From 251675738edc1f6b22b8088645f8d09b4e927889 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Wed, 25 Oct 2023 10:29:07 -0500 Subject: [PATCH] 5.4.0 --- src/DataMapper/Query/Select.php | 6 +- src/Filter/Validation/AbstractValidator.php | 111 ++++++++++-------- .../Validator/File/AbstractFile.php | 40 ++++--- .../Validation/Validator/File/Size/Equal.php | 28 +++-- .../Validation/Validator/File/Size/Max.php | 31 ++--- .../Validation/Validator/File/Size/Min.php | 31 ++--- src/Filter/Validation/ValidatorInterface.php | 42 +++---- src/Html/Helper/AbstractSeries.php | 9 ++ src/Logger/Formatter/AbstractFormatter.php | 29 +++-- src/Logger/Formatter/Json.php | 4 +- src/Logger/Formatter/Line.php | 4 +- src/Support/HelperFactory.php | 50 ++++---- 12 files changed, 211 insertions(+), 174 deletions(-) diff --git a/src/DataMapper/Query/Select.php b/src/DataMapper/Query/Select.php index 2367e54b..b75dfdf8 100644 --- a/src/DataMapper/Query/Select.php +++ b/src/DataMapper/Query/Select.php @@ -97,14 +97,14 @@ public function appendJoin(string $condition, $value = null, int $type = -1): Se } /** - * The columns to select from. If a key is set in an array element, the + * The columns to select from. If a key is set in the array element, the * key will be used as the alias * - * @param string ...$column + * @param array $columns * * @return Select */ - public function columns(): Select + public function columns(array $columns): Select { } diff --git a/src/Filter/Validation/AbstractValidator.php b/src/Filter/Validation/AbstractValidator.php index c25fe6cb..d25ac478 100644 --- a/src/Filter/Validation/AbstractValidator.php +++ b/src/Filter/Validation/AbstractValidator.php @@ -9,9 +9,9 @@ */ namespace Phalcon\Filter\Validation; -use Phalcon\Support\Helper\Arr\Whitelist; use Phalcon\Messages\Message; use Phalcon\Filter\Validation; +use Phalcon\Support\Helper\Arr\Whitelist; /** * This is a base class for validators @@ -46,12 +46,25 @@ public function __construct(array $options = []) { } + /** + * Returns an option in the validator's options + * Returns null if the option hasn't set + * + * @param string $key + * @param mixed|null $defaultValue + * + * @return mixed + */ + public function getOption(string $key, $defaultValue = null) + { + } + /** * Get the template message * + * @param string|null $field + * * @return string - * @throw InvalidArgumentException When the field does not exists - * @param string $field */ public function getTemplate(string $field = null): string { @@ -67,110 +80,116 @@ public function getTemplates(): array } /** - * Clear current templates and set new from an array, + * Checks if an option is defined * - * @return ValidatorInterface - * @param array $templates + * @param string $key + * + * @return bool */ - public function setTemplates(array $templates): ValidatorInterface + public function hasOption(string $key): bool { } /** - * Set a new template message + * Create a default message by factory * - * @return ValidatorInterface - * @param string $template + * @param Validation $validation + * @param array|string $field + * @param array $replacements + * + * @return Message */ - public function setTemplate(string $template): ValidatorInterface + public function messageFactory(\Phalcon\Filter\Validation $validation, $field, array $replacements = []): Message { } /** - * Returns an option in the validator's options - * Returns null if the option hasn't set + * Sets an option in the validator * * @param string $key - * @param mixed $defaultValue - * @return mixed + * @param mixed $value + * + * @return void */ - public function getOption(string $key, $defaultValue = null) + public function setOption(string $key, $value): void { } /** - * Checks if an option is defined + * Set a new template message * - * @param string $key - * @return bool + * @return ValidatorInterface + * @param string $template */ - public function hasOption(string $key): bool + public function setTemplate(string $template): ValidatorInterface { } /** - * Sets an option in the validator + * Clear current templates and set new from an array, * - * @param string $key - * @param mixed $value - * @return void + * @return ValidatorInterface + * @param array $templates */ - public function setOption(string $key, $value): void + public function setTemplates(array $templates): ValidatorInterface { } /** * Executes the validation * - * @param \Phalcon\Filter\Validation $validation - * @param mixed $field + * @param Validation $validation + * @param mixed $field + * * @return bool */ abstract public function validate(\Phalcon\Filter\Validation $validation, $field): bool; /** - * Prepares a validation code. + * Checks if field can be empty. * - * @param string $field - * @return int + * @param mixed $field + * @param mixed $value + * + * @return bool */ - protected function prepareCode(string $field): int + protected function allowEmpty($field, $value): bool { } /** - * Prepares a label for the field. + * Checks if a value is an array and returns the element based on the + * passed field name * - * @param \Phalcon\Filter\Validation $validation + * @param mixed $value * @param string $field + * * @return mixed */ - protected function prepareLabel(\Phalcon\Filter\Validation $validation, string $field) + protected function checkArray($value, string $field) { } /** - * Checks if field can be empty. + * Prepares a validation code. * - * @param mixed $field - * @param mixed $value * - * @return bool + * @param string $field + * + * @return int */ - protected function allowEmpty($field, $value): bool + protected function prepareCode(string $field): int { } /** - * Create a default message by factory + * Prepares a label for the field. * - * @return Message + * @param Validation $validation + * @param string $field * - * @throw Exception - * @param \Phalcon\Filter\Validation $validation - * @param mixed $field - * @param array $replacements + * @return mixed */ - public function messageFactory(\Phalcon\Filter\Validation $validation, $field, array $replacements = []): Message + protected function prepareLabel(\Phalcon\Filter\Validation $validation, string $field) { } } diff --git a/src/Filter/Validation/Validator/File/AbstractFile.php b/src/Filter/Validation/Validator/File/AbstractFile.php index 8abc1070..2f48164e 100644 --- a/src/Filter/Validation/Validator/File/AbstractFile.php +++ b/src/Filter/Validation/Validator/File/AbstractFile.php @@ -9,9 +9,9 @@ */ namespace Phalcon\Filter\Validation\Validator\File; -use Phalcon\Messages\Message; use Phalcon\Filter\Validation; use Phalcon\Filter\Validation\AbstractValidator; +use Phalcon\Messages\Message; /** * Checks if a value has a correct file @@ -79,10 +79,12 @@ abstract class AbstractFile extends AbstractValidator * Check upload * * @param Validation $validation - * @param mixed $field + * @param string $field + * * @return bool + * @throws Validation\Exception */ - public function checkUpload(\Phalcon\Filter\Validation $validation, $field): bool + public function checkUpload(\Phalcon\Filter\Validation $validation, string $field): bool { } @@ -90,10 +92,12 @@ public function checkUpload(\Phalcon\Filter\Validation $validation, $field): boo * Check if upload is empty * * @param Validation $validation - * @param mixed $field - * @return boolean + * @param string $field + * + * @return bool + * @throws Validation\Exception */ - public function checkUploadIsEmpty(\Phalcon\Filter\Validation $validation, $field): bool + public function checkUploadIsEmpty(\Phalcon\Filter\Validation $validation, string $field): bool { } @@ -101,10 +105,12 @@ public function checkUploadIsEmpty(\Phalcon\Filter\Validation $validation, $fiel * Check if upload is valid * * @param Validation $validation - * @param mixed $field - * @return boolean + * @param string $field + * + * @return bool + * @throws Validation\Exception */ - public function checkUploadIsValid(\Phalcon\Filter\Validation $validation, $field): bool + public function checkUploadIsValid(\Phalcon\Filter\Validation $validation, string $field): bool { } @@ -112,10 +118,12 @@ public function checkUploadIsValid(\Phalcon\Filter\Validation $validation, $fiel * Check if uploaded file is larger than PHP allowed size * * @param Validation $validation - * @param mixed $field - * @return boolean + * @param string $field + * + * @return bool + * @throws Validation\Exception */ - public function checkUploadMaxSize(\Phalcon\Filter\Validation $validation, $field): bool + public function checkUploadMaxSize(\Phalcon\Filter\Validation $validation, string $field): bool { } @@ -123,6 +131,7 @@ public function checkUploadMaxSize(\Phalcon\Filter\Validation $validation, $fiel * Convert a string like "2.5MB" in bytes * * @param string $size + * * @return float */ public function getFileSizeInBytes(string $size): float @@ -160,8 +169,10 @@ public function getMessageValid(): string * Check on empty * * @param Validation $validation - * @param string $field + * @param string $field + * * @return bool + * @throws Validation\Exception */ public function isAllowEmpty(\Phalcon\Filter\Validation $validation, string $field): bool { @@ -202,9 +213,10 @@ public function setMessageValid(string $message): void /** * Checks if a file has been uploaded; Internal check that can be - * overriden in a subclass if you do not want to check uploaded files + * overridden in a subclass if you do not want to check uploaded files * * @param string $name + * * @return bool */ protected function checkIsUploadedFile(string $name): bool diff --git a/src/Filter/Validation/Validator/File/Size/Equal.php b/src/Filter/Validation/Validator/File/Size/Equal.php index 36b87a87..24dac8fb 100644 --- a/src/Filter/Validation/Validator/File/Size/Equal.php +++ b/src/Filter/Validation/Validator/File/Size/Equal.php @@ -9,7 +9,6 @@ */ namespace Phalcon\Filter\Validation\Validator\File\Size; -use Phalcon\Messages\Message; use Phalcon\Filter\Validation; use Phalcon\Filter\Validation\Validator\File\AbstractFile; @@ -59,29 +58,34 @@ */ class Equal extends AbstractFile { + /** + * @var string|null + */ protected $template = 'File :field does not have the exact :size file size'; /** - * Constructor + * Executes the validation * - * @param array $options = [ - * 'message' => '', - * 'template' => '', - * 'size' => '2.5MB' - * ] + * @param Validation $validation + * @param mixed $field + * + * @return bool + * @throws Validation\Exception */ - public function __construct(array $options = []) + public function validate(\Phalcon\Filter\Validation $validation, $field): bool { } /** - * Executes the validation + * Executes the conditional + * + * @param float $source + * @param float $target + * @param bool $included * - * @param \Phalcon\Filter\Validation $validation - * @param mixed $field * @return bool */ - public function validate(\Phalcon\Filter\Validation $validation, $field): bool + protected function getConditional(float $source, float $target, bool $included = false) { } } diff --git a/src/Filter/Validation/Validator/File/Size/Max.php b/src/Filter/Validation/Validator/File/Size/Max.php index 659c4869..51f0a280 100644 --- a/src/Filter/Validation/Validator/File/Size/Max.php +++ b/src/Filter/Validation/Validator/File/Size/Max.php @@ -9,10 +9,6 @@ */ namespace Phalcon\Filter\Validation\Validator\File\Size; -use Phalcon\Messages\Message; -use Phalcon\Filter\Validation; -use Phalcon\Filter\Validation\Validator\File\AbstractFile; - /** * Checks if a value has a correct file * @@ -57,32 +53,23 @@ * ); * ``` */ -class Max extends AbstractFile +class Max extends \Phalcon\Filter\Validation\Validator\File\Size\Equal { - protected $template = 'File :field exceeds the size of :size'; - /** - * Constructor - * - * @param array $options = [ - * 'message' => '', - * 'template' => '', - * 'size' => '2.5MB', - * 'included' => false - * ] + * @var string|null */ - public function __construct(array $options = []) - { - } + protected $template = 'File :field exceeds the size of :size'; /** - * Executes the validation + * Executes the conditional + * + * @param float $source + * @param float $target + * @param bool $included * - * @param \Phalcon\Filter\Validation $validation - * @param mixed $field * @return bool */ - public function validate(\Phalcon\Filter\Validation $validation, $field): bool + protected function getConditional(float $source, float $target, bool $included = false) { } } diff --git a/src/Filter/Validation/Validator/File/Size/Min.php b/src/Filter/Validation/Validator/File/Size/Min.php index 147e9e8e..b11de786 100644 --- a/src/Filter/Validation/Validator/File/Size/Min.php +++ b/src/Filter/Validation/Validator/File/Size/Min.php @@ -9,10 +9,6 @@ */ namespace Phalcon\Filter\Validation\Validator\File\Size; -use Phalcon\Messages\Message; -use Phalcon\Filter\Validation; -use Phalcon\Filter\Validation\Validator\File\AbstractFile; - /** * Checks if a value has a correct file * @@ -57,32 +53,23 @@ * ); * ``` */ -class Min extends AbstractFile +class Min extends \Phalcon\Filter\Validation\Validator\File\Size\Equal { - protected $template = 'File :field can not have the minimum size of :size'; - /** - * Constructor - * - * @param array $options = [ - * 'message' => '', - * 'template' => '', - * 'size' => '2.5MB', - * 'included' => false - * ] + * @var string|null */ - public function __construct(array $options = []) - { - } + protected $template = 'File :field can not have the minimum size of :size'; /** - * Executes the validation + * Executes the conditional + * + * @param float $source + * @param float $target + * @param bool $included * - * @param \Phalcon\Filter\Validation $validation - * @param mixed $field * @return bool */ - public function validate(\Phalcon\Filter\Validation $validation, $field): bool + protected function getConditional(float $source, float $target, bool $included = false) { } } diff --git a/src/Filter/Validation/ValidatorInterface.php b/src/Filter/Validation/ValidatorInterface.php index ace0fba7..0b84f4b3 100644 --- a/src/Filter/Validation/ValidatorInterface.php +++ b/src/Filter/Validation/ValidatorInterface.php @@ -26,23 +26,6 @@ interface ValidatorInterface */ public function getOption(string $key, $defaultValue = null); - /** - * Checks if an option is defined - * - * @return boolean - * @param string $key - */ - public function hasOption(string $key): bool; - - /** - * Executes the validation - * - * @return boolean - * @param \Phalcon\Filter\Validation $validation - * @param mixed $field - */ - public function validate(\Phalcon\Filter\Validation $validation, $field): bool; - /** * Get the template message * @@ -60,12 +43,12 @@ public function getTemplate(string $field): string; public function getTemplates(): array; /** - * Clear current template and set new from an array, + * Checks if an option is defined * - * @return ValidatorInterface - * @param array $templates + * @return boolean + * @param string $key */ - public function setTemplates(array $templates): ValidatorInterface; + public function hasOption(string $key): bool; /** * Set a new template message @@ -74,4 +57,21 @@ public function setTemplates(array $templates): ValidatorInterface; * @param string $template */ public function setTemplate(string $template): ValidatorInterface; + + /** + * Clear current template and set new from an array, + * + * @return ValidatorInterface + * @param array $templates + */ + public function setTemplates(array $templates): ValidatorInterface; + + /** + * Executes the validation + * + * @return boolean + * @param \Phalcon\Filter\Validation $validation + * @param mixed $field + */ + public function validate(\Phalcon\Filter\Validation $validation, $field): bool; } diff --git a/src/Html/Helper/AbstractSeries.php b/src/Html/Helper/AbstractSeries.php index 3e89c07b..45ed0bda 100644 --- a/src/Html/Helper/AbstractSeries.php +++ b/src/Html/Helper/AbstractSeries.php @@ -44,6 +44,15 @@ public function __toString() { } + /** + * Resets the internal store. + * + * @return AbstractSeries + */ + public function reset(): AbstractSeries + { + } + /** * Returns the tag name. * diff --git a/src/Logger/Formatter/AbstractFormatter.php b/src/Logger/Formatter/AbstractFormatter.php index b2201695..f0f98ace 100644 --- a/src/Logger/Formatter/AbstractFormatter.php +++ b/src/Logger/Formatter/AbstractFormatter.php @@ -26,14 +26,30 @@ abstract class AbstractFormatter extends AbstractStr implements \Phalcon\Logger\ protected $dateFormat = 'c'; /** - * Return the default date format - * + * @var string + */ + protected $interpolatorLeft = '%'; + + /** + * @var string + */ + protected $interpolatorRight = '%'; + + /** * @return string */ public function getDateFormat(): string { } + /** + * @param string $format + * @return void + */ + public function setDateFormat(string $format): void + { + } + /** * Returns the date formatted for the logger. * @@ -46,13 +62,12 @@ protected function getFormattedDate(\Phalcon\Logger\Item $item): string } /** - * Set the default date format + * @param Item $item + * @param string $message * - * @param string $format - * - * @return void + * @return string */ - public function setDateFormat(string $format): void + protected function getInterpolatedMessage(\Phalcon\Logger\Item $item, string $message): string { } } diff --git a/src/Logger/Formatter/Json.php b/src/Logger/Formatter/Json.php index 7c44bc01..812917dc 100644 --- a/src/Logger/Formatter/Json.php +++ b/src/Logger/Formatter/Json.php @@ -21,8 +21,10 @@ class Json extends \Phalcon\Logger\Formatter\AbstractFormatter * Json constructor. * * @param string $dateFormat + * @param string $interpolatorLeft + * @param string $interpolatorRight */ - public function __construct(string $dateFormat = 'c') + public function __construct(string $dateFormat = 'c', string $interpolatorLeft = '%', string $interpolatorRight = '%') { } diff --git a/src/Logger/Formatter/Line.php b/src/Logger/Formatter/Line.php index 4dc53b39..42453305 100644 --- a/src/Logger/Formatter/Line.php +++ b/src/Logger/Formatter/Line.php @@ -29,8 +29,10 @@ class Line extends \Phalcon\Logger\Formatter\AbstractFormatter * * @param string $format * @param string $dateFormat + * @param string $interpolatorLeft + * @param string $interpolatorRight */ - public function __construct(string $format = '[%date%][%level%] %message%', string $dateFormat = 'c') + public function __construct(string $format = '[%date%][%level%] %message%', string $dateFormat = 'c', string $interpolatorLeft = '%', string $interpolatorRight = '%') { } diff --git a/src/Support/HelperFactory.php b/src/Support/HelperFactory.php index a2d7d8c9..aa80f3f3 100644 --- a/src/Support/HelperFactory.php +++ b/src/Support/HelperFactory.php @@ -14,62 +14,62 @@ /** * ServiceLocator implementation for helpers * - * @method array blacklist(array $collection, array $blackList) - * @method array chunk(array $collection, int $size, bool $preserveKeys = false) - * @method mixed first(array $collection, callable $method = null) - * @method mixed firstKey(array $collection, callable $method = null) - * @method array flatten(array $collection, bool $deep = false) - * @method mixed get(array $collection, $index, $defaultValue = null, string $cast = null) - * @method array group(array $collection, $method) - * @method bool has(array $collection, $index) - * @method bool isUnique(array $collection) - * @method mixed last(array $collection, callable $method = null) - * @method mixed lastKey(array $collection, callable $method = null) - * @method array order(array $collection, $attribute, string $order = 'asc') - * @method array pluck(array $collection, string $element) - * @method array set(array $collection, $value, $index = null) - * @method array sliceLeft(array $collection, int $elements = 1) - * @method array sliceRight(array $collection, int $elements = 1) - * @method array split(array $collection) - * @method object toObject(array $collection) - * @method bool validateAll(array $collection, callable $method) - * @method bool validateAny(array $collection, callable $method) - * @method array whitelist(array $collection, array $whiteList) * @method string basename(string $uri, string $suffix = null) - * @method string decode(string $data, bool $associative = false, int $depth = 512, int $options = 0) - * @method string encode($data, int $options = 0, int $depth = 512) - * @method bool between(int $value, int $start, int $end) + * @method array blacklist(array $collection, array $blackList) * @method string camelize(string $text, string $delimiters = null, bool $lowerFirst = false) + * @method array chunk(array $collection, int $size, bool $preserveKeys = false) * @method string concat(string $delimiter, string $first, string $second, string ...$arguments) * @method int countVowels(string $text) * @method string decapitalize(string $text, bool $upperRest = false, string $encoding = 'UTF-8') + * @method string decode(string $data, bool $associative = false, int $depth = 512, int $options = 0) * @method string decrement(string $text, string $separator = '_') * @method string dirFromFile(string $file) * @method string dirSeparator(string $directory) + * @method string encode($data, int $options = 0, int $depth = 512) * @method bool endsWith(string $haystack, string $needle, bool $ignoreCase = true) + * @method mixed first(array $collection, callable $method = null) * @method string firstBetween(string $text, string $start, string $end) + * @method mixed firstKey(array $collection, callable $method = null) * @method string friendly(string $text, string $separator = '-', bool $lowercase = true, $replace = null) + * @method array flatten(array $collection, bool $deep = false) + * @method mixed get(array $collection, $index, $defaultValue = null, string $cast = null) + * @method array group(array $collection, $method) + * @method bool has(array $collection, $index) * @method string humanize(string $text) * @method bool includes(string $haystack, string $needle) * @method string increment(string $text, string $separator = '_') * @method bool isAnagram(string $first, string $second) + * @method bool isBetween(int $value, int $start, int $end) * @method bool isLower(string $text, string $encoding = 'UTF-8') * @method bool isPalindrome(string $text) + * @method bool isUnique(array $collection) * @method bool isUpper(string $text, string $encoding = 'UTF-8') * @method string kebabCase(string $text, string $delimiters = null) + * @method mixed last(array $collection, callable $method = null) + * @method mixed lastKey(array $collection, callable $method = null) * @method int len(string $text, string $encoding = 'UTF-8') * @method string lower(string $text, string $encoding = 'UTF-8') + * @method array order(array $collection, $attribute, string $order = 'asc') * @method string pascalCase(string $text, string $delimiters = null) + * @method array pluck(array $collection, string $element) * @method string prefix($text, string $prefix) * @method string random(int $type = 0, int $length = 8) * @method string reduceSlashes(string $text) - * @method bool startsWith(string $haystack, string $needle, bool $ignoreCase = true) + * @method array set(array $collection, $value, $index = null) + * @method array sliceLeft(array $collection, int $elements = 1) + * @method array sliceRight(array $collection, int $elements = 1) * @method string snakeCase(string $text, string $delimiters = null) + * @method array split(array $collection) + * @method bool startsWith(string $haystack, string $needle, bool $ignoreCase = true) * @method string suffix($text, string $suffix) + * @method object toObject(array $collection) + * @method bool validateAll(array $collection, callable $method) + * @method bool validateAny(array $collection, callable $method) * @method string ucwords(string $text, string $encoding = 'UTF-8') * @method string uncamelize(string $text, string $delimiters = '_') * @method string underscore(string $text) * @method string upper(string $text, string $encoding = 'UTF-8') + * @method array whitelist(array $collection, array $whiteList) */ class HelperFactory extends AbstractFactory {