From 08eb9bd31cee80d6e1ea8aab48dbbea2abc99fda Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Sat, 10 Aug 2024 18:53:38 +0500 Subject: [PATCH 1/5] Fix docs --- README.md | 12 +++++++----- src/Attribute/Validate.php | 4 ++-- src/ValidatedInputInterface.php | 3 +-- src/ValidatingHydrator.php | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a8d1803..0648954 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,12 @@ composer require yiisoft/hydrator-validator ## General usage -Validating hydrator is a [hydrator](https://github.com/yiisoft/hydrator) decorator that allows to validate -raw data before passing it to the decorated hydrator and to validate object after creating or populating it. +Validating hydrator is a decorator for [hydrator](https://github.com/yiisoft/hydrator) that allows to validate object +after creating or populating with the decorated hydrator. -To use it, the object being validated must implement `ValidatedInputInterface`. You can use `ValidatedInputTrait` to -easily create such object. The validation rules for raw values of the object are defined with `Validate` PHP attribute. +To use it, the object being validated must implement `ValidatedInputInterface`. You can use `ValidatedInputTrait` to +easily create such object. The validation rules for raw values of the object that must be validated before hydration are +defined with `Validate` PHP attribute. Example of object: @@ -60,7 +61,8 @@ final class InputDto implements ValidatedInputInterface } ``` -Validation result could be obtained via `getValidationResult()` method. +Validation result could be obtained via `getValidationResult()` method. For further working with result, refer to +corresponding [validator's guide section](https://github.com/yiisoft/validator/blob/master/docs/guide/en/result.md). Validating hydrator usage example: diff --git a/src/Attribute/Validate.php b/src/Attribute/Validate.php index dd24f1e..5c455dc 100644 --- a/src/Attribute/Validate.php +++ b/src/Attribute/Validate.php @@ -9,8 +9,8 @@ use Yiisoft\Validator\RuleInterface; /** - * Added to either property or parameter to indicate that raw values should be validated. Validation rules are passed - * as arguments to the attribute. + * Added to either property or parameter to indicate that raw values should be validated. Validation rules are passed as + * arguments to the attribute. */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER | Attribute::IS_REPEATABLE)] final class Validate implements ParameterAttributeInterface diff --git a/src/ValidatedInputInterface.php b/src/ValidatedInputInterface.php index 0ce0a7f..781b935 100644 --- a/src/ValidatedInputInterface.php +++ b/src/ValidatedInputInterface.php @@ -9,8 +9,7 @@ use Yiisoft\Validator\Result; /** - * `ValidatedInputInterface` is an interface for objects that can be validated. - * It provides a method to get validation result. + * Used for objects that can be validated. It provides a method to get validation result. * * You can use {@see ValidatedInputTrait} to implement this interface. */ diff --git a/src/ValidatingHydrator.php b/src/ValidatingHydrator.php index 3bd1505..7158553 100644 --- a/src/ValidatingHydrator.php +++ b/src/ValidatingHydrator.php @@ -11,7 +11,7 @@ use Yiisoft\Validator\ValidatorInterface; /** - * `ValidatingHydrator` is a decorator for {@see HydratorInterface} that validates data before hydration. + * `ValidatingHydrator` is a decorator for {@see HydratorInterface} that validates data after hydration. */ final class ValidatingHydrator implements HydratorInterface { From ca9dfc10787c82a9ba592448290b378a5519e6c9 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Sun, 11 Aug 2024 13:44:35 +0500 Subject: [PATCH 2/5] Corrections --- README.md | 12 +++++++----- src/ValidatingHydrator.php | 6 +++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0648954..5d2b79d 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,14 @@ composer require yiisoft/hydrator-validator ## General usage -Validating hydrator is a decorator for [hydrator](https://github.com/yiisoft/hydrator) that allows to validate object -after creating or populating with the decorated hydrator. +Validating hydrator is a decorator for [hydrator](https://github.com/yiisoft/hydrator): -To use it, the object being validated must implement `ValidatedInputInterface`. You can use `ValidatedInputTrait` to -easily create such object. The validation rules for raw values of the object that must be validated before hydration are -defined with `Validate` PHP attribute. +- it allows to validate raw data of properties marked with `Validate` PHP attribute before passing it to the decorated +hydrator; +- it allows to validate object after creating or populating it. + +To use it, the object being validated must implement `ValidatedInputInterface`. You can use `ValidatedInputTrait` to +easily create such object. The validation rules for raw values of the object are defined with `Validate` PHP attribute. Example of object: diff --git a/src/ValidatingHydrator.php b/src/ValidatingHydrator.php index 7158553..f5b9228 100644 --- a/src/ValidatingHydrator.php +++ b/src/ValidatingHydrator.php @@ -11,7 +11,11 @@ use Yiisoft\Validator\ValidatorInterface; /** - * `ValidatingHydrator` is a decorator for {@see HydratorInterface} that validates data after hydration. + * `ValidatingHydrator` is a decorator for {@see HydratorInterface}: + * + * - it allows to validate raw data of properties marked with {@see Validate} PHP attribute before passing it to the + * decorated hydrator; + * - it allows to validate object after creating or populating it. */ final class ValidatingHydrator implements HydratorInterface { From e30128846a6f350d2c9d30763a48caa1f43a2355 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Tue, 13 Aug 2024 14:38:49 +0500 Subject: [PATCH 3/5] Fix [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d2b79d..2926c9d 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ corresponding [validator's guide section](https://github.com/yiisoft/validator/b Validating hydrator usage example: ```php -use Yiisoft\Hydrator\HydratorInterface; +use Psr\Http\Message\RequestInterface; use Yiisoft\Hydrator\Validator\ValidatingHydrator; public function actionEdit(RequestInterface $request, ValidatingHydrator $hydrator): ResponseInterface From 43f1ed73a354c95ca855e2624d0ad4ffdc4948f7 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 15 Aug 2024 17:55:42 +0500 Subject: [PATCH 4/5] Review fix [skip ci] --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 2926c9d..e952278 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,7 @@ composer require yiisoft/hydrator-validator Validating hydrator is a decorator for [hydrator](https://github.com/yiisoft/hydrator): -- it allows to validate raw data of properties marked with `Validate` PHP attribute before passing it to the decorated -hydrator; +- it allows to validate raw data of properties marked with `Validate` PHP attribute; - it allows to validate object after creating or populating it. To use it, the object being validated must implement `ValidatedInputInterface`. You can use `ValidatedInputTrait` to From 4b9695b31821729a53a56c6a36685e2c0c840121 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Tue, 20 Aug 2024 12:28:07 +0500 Subject: [PATCH 5/5] Update README.md Co-authored-by: Alexander Makarov --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e952278..93749d9 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,10 @@ composer require yiisoft/hydrator-validator ## General usage -Validating hydrator is a decorator for [hydrator](https://github.com/yiisoft/hydrator): +Validating hydrator is a decorator for [hydrator](https://github.com/yiisoft/hydrator) that allows to validate: -- it allows to validate raw data of properties marked with `Validate` PHP attribute; -- it allows to validate object after creating or populating it. +- raw data of properties marked with `Validate` PHP attribute; +- an object after creating or populating it. To use it, the object being validated must implement `ValidatedInputInterface`. You can use `ValidatedInputTrait` to easily create such object. The validation rules for raw values of the object are defined with `Validate` PHP attribute.