Skip to content

Commit

Permalink
Rename AtLeast and OneOf rules (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev authored Aug 1, 2024
1 parent c8e7ad1 commit 44aabb0
Show file tree
Hide file tree
Showing 28 changed files with 155 additions and 152 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 2.0.0 under development

- Chg #694: Rename `AtLeast` rule to `FilledAtLeast` and `OneOf` rule to `FilledOnlyOneOf` (@arogachev)
- Enh #492: Add type to error messages related with incorrect input (@arogachev)
- Enh #735: Make `Json::$message` a bit more clear (@arogachev)
- Bug #736: Fix wrong value for `type` parameter for `Each::$incorrectInputKeyMessage` (@arogachev)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ composer require yiisoft/validator
Validator allows to check data in any format. For example, when data is an object:

```php
use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\Email;
use Yiisoft\Validator\Rule\Length;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Validator;

#[AtLeast(['email', 'phone'])]
#[FilledAtLeast(['email', 'phone'])]
final class Person
{
public function __construct(
Expand Down
4 changes: 3 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ for both A and B.
- `Yiisoft\Validator\AttributeTranslator\ArrayAttributeTranslator` to `Yiisoft\Validator\PropertyTranslator\ArrayPropertyTranslator`,
- `Yiisoft\Validator\AttributeTranslator\NullAttributeTranslator` to `Yiisoft\Validator\PropertyTranslator\NullPropertyTranslator`,
- `Yiisoft\Validator\AttributeTranslator\TranslatorAttributeTranslator` to `Yiisoft\Validator\PropertyTranslator\TranslatorPropertyTranslator`,
- `Yiisoft\Validator\AttributeTranslatorInterface` to `Yiisoft\Validator\PropertyTranslatorInterface`.
- `Yiisoft\Validator\AttributeTranslatorInterface` to `Yiisoft\Validator\PropertyTranslatorInterface`,
- `Yiisoft\Validator\Rule\AtLeast` to `Yiisoft\Validator\Rule\FilledAtLeast`,
- `Yiisoft\Validator\Rule\OneOf` to `Yiisoft\Validator\Rule\FilledOnlyOneOf`.

* Changed interface `Yiisoft\Validator\AttributeTranslatorProviderInterface`:
- renamed to `Yiisoft\Validator\PropertyTranslatorProviderInterface`,
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/en/built-in-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Here is a list of all available built-in rules, divided by category.

### Count rules

- [AtLeast](../../../src/Rule/AtLeast.php)
- [Count](../../../src/Rule/Count.php)
- [OneOf](../../../src/Rule/OneOf.php)
- [FilledAtLeast](../../../src/Rule/FilledAtLeast.php)
- [FilledOnlyOneOf](../../../src/Rule/FilledOnlyOneOf.php)

### File rules

Expand Down
8 changes: 4 additions & 4 deletions docs/guide/en/using-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $result = (new Validator())->validate($value, $rules);
It's possible to validate an array both as a whole and by individual items. For example:

```php
use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\Count;
use Yiisoft\Validator\Rule\Email;
use Yiisoft\Validator\Rule\Length;
Expand All @@ -46,7 +46,7 @@ $rules = [
// The rules that are not related to a specific property

// At least one of the properties ("email" and "phone") must be passed and have non-empty value.
new AtLeast(['email', 'phone']),
new FilledAtLeast(['email', 'phone']),

// The rules related to a specific property.

Expand All @@ -72,14 +72,14 @@ For objects there is an additional option to configure validation with PHP attri
separately in explicit way (passing just the object itself is enough). For example:

```php
use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\Email;
use Yiisoft\Validator\Rule\Length;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Validator;

#[AtLeast(['email', 'phone'])]
#[FilledAtLeast(['email', 'phone'])]
final class Person
{
public function __construct(
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/pt-BR/built-in-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Aqui está uma lista de todas as regras integradas disponíveis, divididas por c

### Regras de contagem

- [AtLeast](../../../src/Rule/AtLeast.php)
- [Count](../../../src/Rule/Count.php)
- [OneOf](../../../src/Rule/OneOf.php)
- [FilledAtLeast](../../../src/Rule/FilledAtLeast.php)
- [FilledOnlyOneOf](../../../src/Rule/FilledOnlyOneOf.php)

### Regras de arquivo

Expand Down
8 changes: 4 additions & 4 deletions docs/guide/pt-BR/using-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $result = (new Validator())->validate($value, $rules);
É possível validar um array como um todo ou por itens individuais. Por exemplo:

```php
use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\Count;
use Yiisoft\Validator\Rule\Email;
use Yiisoft\Validator\Rule\Length;
Expand All @@ -46,7 +46,7 @@ $rules = [
// As regras que não estão relacionadas a um atributo específico

// Pelo menos um dos atributos ("email" e "phone") deve ser passado e ter valor não vazio.
new AtLeast(['email', 'phone']),
new FilledAtLeast(['email', 'phone']),

// As regras relacionadas a um atributo específico.

Expand All @@ -72,14 +72,14 @@ Para objetos existe uma opção adicional para configurar a validação com atri
separadamente de forma explícita (passar apenas o objeto em si é suficiente). Por exemplo:

```php
use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\Email;
use Yiisoft\Validator\Rule\Length;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Validator;

#[AtLeast(['email', 'phone'])]
#[FilledAtLeast(['email', 'phone'])]
final class Person
{
public function __construct(
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/ru/using-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $result = (new Validator())->validate($value, $rules);
Валидировать массив можно как целиком, так и по отдельным элементам. Например:

```php
use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\Count;
use Yiisoft\Validator\Rule\Email;
use Yiisoft\Validator\Rule\Length;
Expand All @@ -46,7 +46,7 @@ $rules = [
// Правила, не относящиеся к конкретному свойству.

// Хотя бы одно из свойств ("email" или "phone"), должен быть передан и иметь непустое значение.
new AtLeast(['email', 'phone']),
new FilledAtLeast(['email', 'phone']),

// Правила, относящиеся к конкретному свойству.

Expand All @@ -71,14 +71,14 @@ $result = (new Validator())->validate($data, $rules);
Для объектов есть дополнительная возможность настроить валидацию по атрибутами, что позволяет не передавать правила отдельно явным образом (достаточно передавать только сам объект). Например:

```php
use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\Email;
use Yiisoft\Validator\Rule\Length;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Validator;

#[AtLeast(['email', 'phone'])]
#[FilledAtLeast(['email', 'phone'])]
final class Person
{
public function __construct(
Expand Down
12 changes: 6 additions & 6 deletions messages/de/yii-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\BooleanValue;
use Yiisoft\Validator\Rule\Compare;
use Yiisoft\Validator\Rule\Count;
Expand All @@ -21,7 +21,7 @@
use Yiisoft\Validator\Rule\Nested;
use Yiisoft\Validator\Rule\NotEqual;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\OneOf;
use Yiisoft\Validator\Rule\FilledOnlyOneOf;
use Yiisoft\Validator\Rule\Regex;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Rule\Subset;
Expand All @@ -31,7 +31,7 @@
return [
// Used in single rule

/** @see AtLeast */
/** @see FilledAtLeast */
'At least {min, number} {min, plural, one{property} other{properties}} from this list must be filled' =>
'Mindestens {min, number} {min, plural, one{Attribut aus dieser Liste muss} other{Attribute aus dieser ' .
'Liste müssen}} ausgefüllt werden',
Expand Down Expand Up @@ -82,7 +82,7 @@
'Property "{path}" is not found.' => 'Eigenschaft "{path}" nicht gefunden.',
/** @see Number */
'{Property} must be a number.' => '{Property} muss eine Nummer sein.',
/** @see OneOf */
/** @see FilledOnlyOneOf */
'Exactly 1 property from this list must be filled: {properties}.' => 'Exakt ein Attribut aus dieser Liste ' .
'muss gefüllt sein: {properties}.',
/** @see Regex */
Expand All @@ -101,9 +101,9 @@
// Used in multiple rules

/**
* @see AtLeast
* @see FilledAtLeast
* @see Nested
* @see OneOf
* @see FilledOnlyOneOf
*/
'{Property} must be an array or an object.' => '{Property} muss ein Array oder Object sein.',
/**
Expand Down
12 changes: 6 additions & 6 deletions messages/pl/yii-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\BooleanValue;
use Yiisoft\Validator\Rule\Compare;
use Yiisoft\Validator\Rule\Count;
Expand All @@ -21,7 +21,7 @@
use Yiisoft\Validator\Rule\Nested;
use Yiisoft\Validator\Rule\NotEqual;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\OneOf;
use Yiisoft\Validator\Rule\FilledOnlyOneOf;
use Yiisoft\Validator\Rule\Regex;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Rule\Subset;
Expand All @@ -31,7 +31,7 @@
return [
// Used in single rule

/** @see AtLeast */
/** @see FilledAtLeast */
'At least {min, number} {min, plural, one{property} other{properties}} from this list must be filled' => 'At least {min, number} {min, plural, one{property} other{properties}} from this list must be filled',
/** @see BooleanValue */
'{Property} must be either "{true}" or "{false}".' => '{Property} wynosić "{true}" albo "{false}".',
Expand Down Expand Up @@ -69,7 +69,7 @@
'Property "{path}" is not found.' => 'Właściwość "{path}" nie została znaleziona.',
/** @see Number */
'{Property} must be a number.' => '{Property} być liczbą.',
/** @see OneOf */
/** @see FilledOnlyOneOf */
'Exactly 1 property from this list must be filled: {properties}.' => 'Exactly 1 property from this list must be filled: {properties}.',
/** @see Regex */
'{Property} is invalid.' => 'Wartość jest nieprawidłowa.',
Expand All @@ -87,9 +87,9 @@
// Used in multiple rules

/**
* @see AtLeast
* @see FilledAtLeast
* @see Nested
* @see OneOf
* @see FilledOnlyOneOf
*/
'{Property} must be an array or an object.' => '{Property} być tablicą lub obiektem.',
/**
Expand Down
12 changes: 6 additions & 6 deletions messages/pt-BR/yii-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\BooleanValue;
use Yiisoft\Validator\Rule\Compare;
use Yiisoft\Validator\Rule\Count;
Expand All @@ -21,7 +21,7 @@
use Yiisoft\Validator\Rule\Nested;
use Yiisoft\Validator\Rule\NotEqual;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\OneOf;
use Yiisoft\Validator\Rule\FilledOnlyOneOf;
use Yiisoft\Validator\Rule\Regex;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Rule\Subset;
Expand All @@ -31,7 +31,7 @@
return [
// Usado em regra única

/** @see AtLeast */
/** @see FilledAtLeast */
'The data must have at least "{min}" filled properties.' => 'Os dados devem conter no mínimo {min, number} {min, plural, one{atributo preenchido} few{atributo preenchido} many{atributos preenchidos} other{atributo preenchido}}.',
/** @see BooleanValue */
'Value must be either "{true}" or "{false}".' => 'O valor deve ser "{true}" ou "{false}".',
Expand Down Expand Up @@ -69,7 +69,7 @@
'Property "{path}" is not found.' => 'Propriedade "{path}" não encontrada.',
/** @see Number */
'Value must be a number.' => 'O valor deve ser um número.',
/** @see OneOf */
/** @see FilledOnlyOneOf */
'The data must have at least 1 filled property.' => 'Os dados devem conter pelo menos 1 atributo preenchido.',
/** @see Regex */
'Value is invalid.' => 'O valor está incorreto.',
Expand All @@ -87,9 +87,9 @@
// Usado em múltiplas regras

/**
* @see AtLeast
* @see FilledAtLeast
* @see Nested
* @see OneOf
* @see FilledOnlyOneOf
*/
'The value must be an array or an object.' => 'O valor deve ser um array ou um objeto.',
/**
Expand Down
12 changes: 6 additions & 6 deletions messages/ru/yii-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Yiisoft\Validator\Rule\AtLeast;
use Yiisoft\Validator\Rule\FilledAtLeast;
use Yiisoft\Validator\Rule\BooleanValue;
use Yiisoft\Validator\Rule\Compare;
use Yiisoft\Validator\Rule\Count;
Expand All @@ -22,7 +22,7 @@
use Yiisoft\Validator\Rule\Nested;
use Yiisoft\Validator\Rule\NotEqual;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\OneOf;
use Yiisoft\Validator\Rule\FilledOnlyOneOf;
use Yiisoft\Validator\Rule\Regex;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Rule\Subset;
Expand All @@ -36,7 +36,7 @@
return [
// Used in single rule

/** @see AtLeast */
/** @see FilledAtLeast */
'At least {min, number} {min, plural, one{property} other{properties}} from this list must be filled for {property}: {properties}' =>
'Как минимум {min, number} {min, plural, one{свойство} few{свойства} many{свойства} other{свойства}} из этого списка {min, plural, one{должен} few{должны} many{должны} other{должны}} быть заполнены для {property}: {properties}.',
/** @see BooleanValue */
Expand Down Expand Up @@ -83,7 +83,7 @@
'Property "{path}" is not found in {property}.' => 'Свойство «{path}» не найдено в {property}.',
/** @see Number */
'{Property} must be a number.' => '{Property} должно быть числом.',
/** @see OneOf */
/** @see FilledOnlyOneOf */
'Exactly 1 property from this list must be filled for {property}: {properties}.' =>
'Ровно 1 свойство из этого списка должно быть заполнено в {property}: {properties}.',
/** @see Regex */
Expand All @@ -102,9 +102,9 @@
// Used in multiple rules

/**
* @see AtLeast
* @see FilledAtLeast
* @see Nested
* @see OneOf
* @see FilledOnlyOneOf
*/
'{Property} must be an array or an object. {type} given.' => '{Property} должно быть массивом или объектом. ' .
'Передан {type}.',
Expand Down
Loading

0 comments on commit 44aabb0

Please sign in to comment.