Skip to content

Commit

Permalink
Minor docs' improvements (#27)
Browse files Browse the repository at this point in the history
* Fix docs

* Corrections

* Fix [skip ci]

* Review fix [skip ci]

* Update README.md

Co-authored-by: Alexander Makarov <[email protected]>

---------

Co-authored-by: Alexander Makarov <[email protected]>
  • Loading branch information
arogachev and samdark authored Aug 20, 2024
1 parent dcd162b commit 6d60629
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ 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:

- 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.
Expand All @@ -60,12 +62,13 @@ 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:

```php
use Yiisoft\Hydrator\HydratorInterface;
use Psr\Http\Message\RequestInterface;
use Yiisoft\Hydrator\Validator\ValidatingHydrator;

public function actionEdit(RequestInterface $request, ValidatingHydrator $hydrator): ResponseInterface
Expand Down
4 changes: 2 additions & 2 deletions src/Attribute/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/ValidatedInputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/ValidatingHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
use Yiisoft\Validator\ValidatorInterface;

/**
* `ValidatingHydrator` is a decorator for {@see HydratorInterface} that validates data before 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
{
Expand Down

0 comments on commit 6d60629

Please sign in to comment.