Skip to content

Commit

Permalink
Merge 1.4 branch to master (#710)
Browse files Browse the repository at this point in the history
* update irc link (#663)

* update docs folder link (#666)

* Add methods `addErrorWithFormatOnly()` and `addErrorWithoutPostProcessing()` to `Result` object (#665)

* Clarify psalm types in `Result` (#668)

* Update result docs (#676)

* Add `Image` validation rule (#670)

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

* Add missed params to `Image` rule options (#680)

* Add date rules (#678)

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

* Add aspect ratio support to `Image` rule (#681)

* Add aspect ratio support to `Image` rule

* Apply fixes from StyleCI

* Code coverage, mutants

* Add detailed test cases' descriptions in data providers

* Change placeholders

* Work with options

* Work with options 2

* More configuration checks

* Fix logic, add PHPDoc

* Use value object for aspect ratio

* Actualize fix for mutant for absolute margin

* Fix error messages

* Fix new mutants

* Update src/Rule/Image/ImageAspectRatio.php

Co-authored-by: Sergei Predvoditelev <[email protected]>

* Do not use dedicated container in tests, fix last mutant

---------

Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Sergei Predvoditelev <[email protected]>

* Release version 1.3.0

* Prepare for next release

* Update guides in english and Translate guides into Brazilian Portuguese  (#691)

* Add `Result::add()` method for merging other results to the base one (#686)

* Add `Result::add()` method for merging other results to the base one

* Apply fixes from StyleCI

* Update PR template [skip ci]

* Update src/Result.php

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

---------

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

* Add type rules and `Any` rule (#692)

* Add type rules and handlers

* Apply fixes from StyleCI

* Mention in the docs + basic tests

* Apply fixes from StyleCI

* Fix copy paste [skip ci]

* Test error message

* Update changelog [skip ci]

* Update PHPDoc [skip ci]

* More tests and descriptions

* Apply fixes from StyleCI

* Include type in error message

* Add Any rule

* Apply fixes from StyleCI

* Update changelog [skip ci]

* Note [skip ci]

* Add translations [skip ci]

* Fix tests

* Test attributes

* Extract PHP >= 8.1 specific tests

* Apply fixes from StyleCI

* Extract PHP >= 8.1 specific tests 2

* Fix mutant

* Update CHANGELOG.md

Co-authored-by: Sergei Predvoditelev <[email protected]>

* Rename Any to AnyRule (review)

---------

Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Sergei Predvoditelev <[email protected]>

* Rename `Any` rule in docs (#699)

* Rename AnyHandler (remaining occurence) (#701)

* Add methods for getting first error messages to `Result` (#697)

* Add methods for getting first error messages to `Result`

* Bump coverage

* Update src/Result.php

Co-authored-by: Sergei Predvoditelev <[email protected]>

* Update src/Result.php

Co-authored-by: Sergei Predvoditelev <[email protected]>

* Apply fixes from StyleCI

* Remove newline [skip ci]

* Add changelog entry [skip ci]

---------

Co-authored-by: Sergei Predvoditelev <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>

* Translate Each rule docs into Russian (#688)

* Add `Unique` rule (#695)

* Add Unique rule

* Apply fixes from StyleCI

* More tests, messages [WIP]

* Apply fixes from StyleCI

* Test traslated attributes

* Test using as attribute

* Ready for review

* Apply fixes from StyleCI

* Update src/Rule/UniqueHandler.php

Co-authored-by: Dmitriy Derepko <[email protected]>

* Apply fixes from StyleCI

* Slightly different approach

* Apply fixes from StyleCI

* New test case to check strict equality

* Different approach

* Minor adjustments

* Remove comma, rename

* Update changelog [skip ci]

---------

Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Dmitriy Derepko <[email protected]>
Co-authored-by: Sergei Predvoditelev <[email protected]>

* Fix typo in array shape (#705)

* Fix docs, translate brazilian portuguese (#708)

Co-authored-by: Sergei Predvoditelev <[email protected]>

* Release version 1.4.0

* Prepare for next release

* Merge fixes

---------

Co-authored-by: Ihor Sychevskyi <[email protected]>
Co-authored-by: Alexey Rogachev <[email protected]>
Co-authored-by: Alexander Makarov <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Luiz Marin <[email protected]>
Co-authored-by: Danil Arduanov <[email protected]>
Co-authored-by: Dmitriy Derepko <[email protected]>
  • Loading branch information
8 people authored May 23, 2024
1 parent a6c8917 commit da04738
Show file tree
Hide file tree
Showing 62 changed files with 6,213 additions and 86 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
| Is bugfix? | ✔️/❌
| New feature? | ✔️/❌
| Breaks BC? | ✔️/❌
| Fixed issues | <!-- comma-separated list of tickets # fixed by the PR, if any -->
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
- Chg #613: Change type of `$escape` argument in `Error::getValuePath()` from `bool|string|null` to `string|null`
(@arogachev)

## 1.4.0 May 22, 2024

- New #649: Add `getFirstErrorMessagesIndexedByPath()` and `getFirstErrorMessagesIndexedByAttribute()` methods to
`Result` (@arogachev)
- New #655: Add rules for validating value types - `boolean`, `float`, `integer`, `string` (@arogachev)
- New #657: Add `Result::add()` method for merging other results to the base one (@arogachev)
- New #687: Add `UniqueIterable` rule (@arogachev)
- New #693: Add `AnyRule` rule (@arogachev)

## 1.3.0 April 04, 2024

- New #665: Add methods `addErrorWithFormatOnly()` and `addErrorWithoutPostProcessing()` to `Result` object (@vjik)
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<a href="https://github.com/yiisoft" target="_blank">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px" alt="Yii">
</a>
<h1 align="center">Yii Validator</h1>
<br>
Expand Down Expand Up @@ -41,7 +41,7 @@ This package provides data validation capabilities.

## Installation

The package could be installed with composer:
The package could be installed with [Composer](https://getcomposer.org):

```shell
composer require yiisoft/validator
Expand Down Expand Up @@ -102,9 +102,12 @@ $result->getErrorMessages();

## Documentation

- [Guide](docs/guide/en/README.md)
- Guide: [English](docs/guide/en/README.md), [Português - Brasil](docs/guide/pt-BR/README.md)
- [Internals](docs/internals.md)

If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).

## License

The Yii Validator is free software. It is released under the terms of the BSD License.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/validator/issues?state=open",
"source": "https://github.com/yiisoft/validator",
"forum": "https://www.yiiframework.com/forum/",
"wiki": "https://www.yiiframework.com/wiki/",
"irc": "ircs://irc.libera.chat:6697/yii",
"chat": "https://t.me/yii3en",
"source": "https://github.com/yiisoft/validator"
"chat": "https://t.me/yii3en"
},
"funding": [
{
Expand Down Expand Up @@ -42,7 +42,7 @@
"maglnet/composer-require-checker": "^4.3",
"phpbench/phpbench": "^1.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^1.0",
"rector/rector": "1.0.*",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.22",
Expand Down Expand Up @@ -75,7 +75,7 @@
},
"config-plugin": {
"di": "di.php",
"params": "params.php"
"params": "params.php"
}
},
"config": {
Expand Down
10 changes: 3 additions & 7 deletions docs/guide/en/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Yii Validator

A package for validating data.

## Guides

### Validation
## Validation

- [Using validator](using-validator.md)
- [Result](result.md)
- [Conditional validation](conditional-validation.md)
- [Customizing error messages](customizing-error-messages.md)

### Rules
## Rules

- [Built-in rules](built-in-rules.md)
- [Callback](built-in-rules-callback.md)
Expand All @@ -23,7 +19,7 @@ A package for validating data.
- [Configuring rules via PHP attributes](configuring-rules-via-php-attributes.md)
- [Creating custom rules](creating-custom-rules.md)

### Miscellaneous
## Miscellaneous

- [Client-side validation](client-side-validation.md)
- [Extensions](extensions.md)
10 changes: 4 additions & 6 deletions docs/guide/en/built-in-rules-callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A condition can be within:
- Callable class.
- DTO (data transfer object) method.

The downside of using standalone functions and DTO methods is a lack of reusability. So they are mainly useful
The downside of using standalone functions and DTO methods is a lack of reusability. So they are mainly useful
for some specific non-repetitive conditions. Reusability can be achieved with callable classes, but depending on other
factors (the need for additional parameters for example), it might be a good idea to create a full-fledged
[custom rule](creating-custom-rules.md) with a separate handler instead.
Expand Down Expand Up @@ -54,7 +54,8 @@ new Callback(
### Value validation

`Callback` rule can be used to add validation missing in built-in rules for a single attribute's value. Below is the
example verifying that a value is a valid [YAML] string (additionally requires `yaml` PHP extension):
example verifying that a value is a valid [YAML](https://en.wikipedia.org/wiki/YAML) string
(additionally requires `yaml` PHP extension):

```php
use Exception;
Expand Down Expand Up @@ -85,7 +86,7 @@ new Callback(
```

> **Note:** Processing untrusted user input with `yaml_parse()` can be dangerous with certain settings. Please refer to
> [yaml_parse docs] for more details.
> [`yaml_parse()` docs](https://www.php.net/manual/en/function.yaml-parse.php) for more details.
### Usage of validation context for validating multiple attributes depending on each other

Expand Down Expand Up @@ -390,6 +391,3 @@ $rules = [
];
$result = (new Validator())->validate($data, $rules);
```

[YAML]: https://en.wikipedia.org/wiki/YAML
[yaml_parse docs]: https://www.php.net/manual/en/function.yaml-parse.php
11 changes: 4 additions & 7 deletions docs/guide/en/built-in-rules-composite.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `Composite` - grouping multiple validation rules

`Composite` allows to group multiple rules and configure the common [skipping options], such as `skipOnEmpty`,
`skipOnError` and `when`, for the whole set only once instead of repeating them in each rule:
`Composite` allows to group multiple rules and configure the common [skipping options](conditional-validation.md),
such as `skipOnEmpty`, `skipOnError` and `when`, for the whole set only once instead of repeating them in each rule:

```php
use Yiisoft\Validator\Rule\Composite;
Expand Down Expand Up @@ -45,9 +45,9 @@ And use it just like a single regular rule:
use Yiisoft\Validator\Validator;

$result = (new Validator())->validate('John', new UsernameRuleSet());
````
```

It can also be combined with [Nested] rule to reuse rules for multiple attributes:
It can also be combined with [Nested](built-in-rules-nested.md) rule to reuse rules for multiple attributes:

```php
use Yiisoft\Validator\Rule\Composite;
Expand Down Expand Up @@ -82,6 +82,3 @@ final class ChartCoordinateRuleSet extends Composite
}
}
```

[skipping options]: conditional-validation.md
[Nested]: built-in-rules-nested.md
9 changes: 3 additions & 6 deletions docs/guide/en/built-in-rules-each.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `Each` - applying the same rules for each data item in the set

The `Each` rule allows the same rules to be applied to each data item in the set. The following example shows
the configuration for validating [RGB color] components:
the configuration for validating [RGB color](https://en.wikipedia.org/wiki/RGB_color_model) components:

```php
use Yiisoft\Validator\Rule\Each;
Expand Down Expand Up @@ -30,7 +30,7 @@ $rules = [
];
```

Validated data items are not limited to only "simple" values - `Each` can be used both within a `Nested` and contain
Validated data items are not limited to only "simple" values - `Each` can be used both within a `Nested` and contain
`Nested` rule covering one-to-many and many-to-many relations:

```php
Expand Down Expand Up @@ -59,7 +59,4 @@ $rule = new Nested([
]);
```

For more information about using it with `Nested`, see the [Nested] guide.

[RGB color]: https://en.wikipedia.org/wiki/RGB_color_model
[Nested]: built-in-rules-nested.md
For more information about using it with `Nested`, see the [Nested](built-in-rules-nested.md) guide.
2 changes: 1 addition & 1 deletion docs/guide/en/built-in-rules-stop-on-error.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $rules = [
]),
// Skipping of other intermediate rules depends on `skipOnError` option set in these intermediate rules.
'attribute4' => new SimpleRule4(), // Not skipped, because `skipOnError` is `false` by default.
]);
];
```

Use grouping / ordering / `skipOnError` option to achieve the desired effect.
14 changes: 12 additions & 2 deletions docs/guide/en/built-in-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

Here is a list of all available built-in rules, divided by category.

### Type rules

- [BooleanType](../../../src/Rule/Type/BooleanType.php)
- [FloatType](../../../src/Rule/Type/FloatType.php)
- [IntegerType](../../../src/Rule/Type/IntegerType.php)
- [StringType](../../../src/Rule/Type/StringType.php)

### String rules

- [StringValue](../../../src/Rule/StringValue.php)
Expand All @@ -16,8 +23,8 @@ Here is a list of all available built-in rules, divided by category.

### Boolean rules

- [Boolean](../../../src/Rule/Boolean.php)
- [IsTrue](../../../src/Rule/IsTrue.php)
- [Boolean](../../../src/Rule/BooleanValue.php)
- [IsTrue](../../../src/Rule/TrueValue.php)

### Number rules

Expand All @@ -38,6 +45,7 @@ Here is a list of all available built-in rules, divided by category.

- [In](../../../src/Rule/In.php)
- [Subset](../../../src/Rule/Subset.php)
- [UniqueIterable](../../../src/Rule/UniqueIterable.php)

### Count rules

Expand All @@ -62,6 +70,7 @@ Here is a list of all available built-in rules, divided by category.

### Complex rules

- [AnyRule](../../../src/Rule/AnyRule.php)
- [Composite](../../../src/Rule/Composite.php)
- [Each](../../../src/Rule/Each.php)
- [Nested](../../../src/Rule/Nested.php)
Expand All @@ -83,5 +92,6 @@ Some rules also have guides in addition to PHPDoc:

Can't find a rule? Feel free to submit an issue / PR, so it can be included in the package after review. Another option,
if your use case is less generic, is to search for [an extension] or [create a custom rule].

[an extension]: extensions.md
[create a custom rule]: creating-custom-rules.md
2 changes: 1 addition & 1 deletion docs/guide/en/conditional-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ is considered non-empty and validated without skipping (default).
(corresponding attribute must be present) and non-empty values (not `null`, `[]`, or `''`) are validated.
- If a custom callback is set, it is used to determine emptiness.

`false` is usually more suitable for HTML forms and `true` - for APIs.
`false` is usually more suitable for HTML forms and `true` for APIs.

There are some more conditions that have no shortcuts and need to be set explicitly because they are less used:

Expand Down
5 changes: 2 additions & 3 deletions docs/guide/en/configuring-rules-via-php-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Given a single `User` entity / model:
```php
use Yiisoft\Validator\Rule\Integer;
use Yiisoft\Validator\Rule\Length;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;

[
Expand Down Expand Up @@ -103,7 +102,6 @@ use Yiisoft\Validator\Rule\Each;
use Yiisoft\Validator\Rule\Integer;
use Yiisoft\Validator\Rule\Length;
use Yiisoft\Validator\Rule\Nested;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Rule\Url;

Expand Down Expand Up @@ -242,10 +240,11 @@ class Truck extends Car
}
```

In this case the set of rules for `Truck` will be:
In this case the set of rules for `Truck` class will be:

```php
use Yiisoft\Validator\Rule\BooleanValue;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;

[
Expand Down
3 changes: 1 addition & 2 deletions docs/guide/en/creating-custom-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ final class YamlHandler implements RuleHandlerInterface
> **Note:** Using [yaml_parse] additionally requires `yaml` PHP extension.
> **Note:** Processing untrusted user input with `yaml_parse()` can be dangerous with certain settings. Please refer to
> [yaml_parse docs] for more details.
> [`yaml_parse()` docs](https://www.php.net/manual/en/function.yaml-parse.php) for more details.
### Wrapping validation

Expand Down Expand Up @@ -437,7 +437,6 @@ someone else - make it available as an extension.
[array_is_list]: https://www.php.net/manual/en/function.array-is-list.php
[YAML]: https://en.wikipedia.org/wiki/YAML
[yaml_parse]: https://www.php.net/manual/en/function.yaml-parse.php
[yaml_parse docs]: https://www.php.net/manual/en/function.yaml-parse.php
[scenarios from Yii 2]: https://www.yiiframework.com/doc/guide/2.0/en/structure-models#scenarios
[Yii Validator Scenarios]: https://github.com/vjik/yii-validator-scenarios
[Sergei Predvoditelev]: https://github.com/vjik
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/en/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ approach is discouraged and the recommended way with this package is using separ
Sure, this will lead to some code duplication, but it's acceptable and will pay off in the future.
Anyway, we decided to make it available through an extension, but use it with caution.

[Yii Validator Scenarios] (`vjik/yii-validator-scenarios`) package from a core team member [Sergei Predvoditelev] adds
[Yii Validator Scenarios] package from a core team member [Sergei Predvoditelev] adds
special `On` rule which allows to wrap other rules by declaring specific scenarios.

An example of the class using scenarios:
Expand Down Expand Up @@ -54,12 +54,12 @@ use Yiisoft\Validator\ValidationContext;
use Yiisoft\Validator\Validator;

$context = new ValidationContext([On::SCENARIO_PARAMETER => 'signup']);
$result = (new Validator())->validate($userDto, context: $context));
$result = (new Validator())->validate($userDto, context: $context);
```

## Wrapper for Symfony rules

[Yii Validator Symfony Rule] (`vjik/yii-validator-symfony-rule`) package from a core team member [Sergei Predvoditelev]
[Yii Validator Symfony Rule] package from a core team member [Sergei Predvoditelev]
adapts [constraints from Symfony framework] to be used as rules in Yii Validator.

Using it is straightforward, all you have to do is wrap a Symfony constraint (or a list of them) with `SymfonyRule` rule
Expand Down
3 changes: 2 additions & 1 deletion docs/guide/en/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ Also keep in mind that attribute names must be strings, even when used with `Eac
$rule = new Each([new Number(min: 21)]),
```

With input containing non-string keys for top level attributes, for example, `[21, 22, 23, 20]`, InvalidArgumentException` will be thrown.
With input containing non-string keys for top level attributes, for example, `[21, 22, 23, 20]`,
`InvalidArgumentException` will be thrown.

Even array `['1' => 21, '2' => 22, '3' => 23, '4' => 20]` will cause an error, because PHP [will cast keys to the int type].

Expand Down
25 changes: 25 additions & 0 deletions docs/guide/pt-BR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Yii Validator

## Validação

- [Usando o validador](using-validator.md)
- [Result](result.md)
- [Validação condicional](conditional-validation.md)
- [Personalizando mensagens de erro](customizing-error-messages.md)

## Regras

- [Regras integradas](built-in-rules.md)
- [Callback](built-in-rules-callback.md)
- [Composite](built-in-rules-composite.md)
- [Each](built-in-rules-each.md)
- [Nested](built-in-rules-nested.md)
- [Required](built-in-rules-required.md)
- [StopOnError](built-in-rules-stop-on-error.md)
- [Configurando regras via atributos PHP](configuring-rules-via-php-attributes.md)
- [Criando regras personalizadas](creating-custom-rules.md)

## Diversos

- [Validação do lado do cliente](client-side-validation.md)
- [Extensões](extensions.md)
Loading

0 comments on commit da04738

Please sign in to comment.