Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions bin/create-mixin
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ function addMethodToInterface(

$defaultValue = $reflectionParameter->getDefaultValue();
if (is_object($defaultValue)) {
$parameter->setDefaultValue(null);
$parameter->setNullable(true);
continue;
}

$parameter->setDefaultValue($reflectionParameter->getDefaultValue());
$parameter->setDefaultValue($defaultValue);
$parameter->setNullable(false);
}
}
Expand Down Expand Up @@ -170,10 +172,10 @@ function overwriteFile(string $content, string $basename): void
['Length', 'length', $numberRelatedRules, []],
['Max', 'max', $numberRelatedRules, []],
['Min', 'min', $numberRelatedRules, []],
['Not', 'not', [], ['Not', 'NotEmpty', 'NotBlank', 'NotEmoji', 'NotUndef', 'NullOr', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['NullOr', 'nullOr', [], ['NullOr', 'NotUndef', 'UndefOr', 'Templated', 'Named']],
['Not', 'not', [], ['Not', 'NotEmpty', 'NotEmoji', 'NotUndef', 'NullOr', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['NullOr', 'nullOr', [], ['NullOr', 'Blank', 'NotUndef', 'UndefOr', 'Templated', 'Named']],
['Property', 'property', [], $structureRelatedRules],
['UndefOr', 'undefOr', [], ['NullOr', 'NotUndef', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['UndefOr', 'undefOr', [], ['NullOr', 'Blank', 'NotUndef', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['', null, [], []],
];

Expand Down
4 changes: 2 additions & 2 deletions bin/update-doc-links
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ create_rule_documentation()
sed -nE '/^# /,/^## Changelog/p' "${filename}" | ggrep -E -v '^## Changelog'

# "Changelog" section
sed -nE '/^## Changelog/,/^\*\*\*/p' "${filename}" | ggrep -Fv '***'
sed -nE '/^## Changelog/,/^---/p' "${filename}"

# "See also" section
echo "***"
echo
echo "See also:"
echo
echo "${related_links}"
Expand Down
1 change: 0 additions & 1 deletion docs/02-feature-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ The `Validator` class is the core of Respect\Validation, offering a fluent inter

For convenience, the `Validator` class is aliased as `v`. This means you can write `v::intType()` instead of `\Respect\Validation\Validator::intType()`.


## Validating using booleans

With the `isValid()` method, determine if your input meets a specific validation rule.
Expand Down
2 changes: 1 addition & 1 deletion docs/04-message-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ We use dependency injection container to create Validators with all their depend

You can use different translators to translate validation messages into different languages, by overwriting the default container in `ContainerRegistry`, passing the translator you desire.

Luckily, the `ContainerRegistry` has method that creates a pre-configured container using [php-di/php-di](https://php-di.org/). That means you just need to overwrite that service.
Luckily, the `ContainerRegistry` has method that creates a pre-configured container using [php-di/php-di](https://php-di.org/). That means you just need to overwrite that service.

```php
use Respect\Validation\ContainerRegistry;
Expand Down
4 changes: 2 additions & 2 deletions docs/08-comparable-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ You can make comparison with the following data types:
- Numeric types
- Single character string
- Primitive types in general: normal operation comparison made by PHP
- Time string: [date and time format](http://php.net/datetime.formats)
that can be parsed by PHP
- Time string: [date and time format](http://php.net/datetime.formats)
that can be parsed by PHP

Below you can see some examples:

Expand Down
22 changes: 11 additions & 11 deletions docs/09-list-of-rules-by-category.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@
- [Uploaded](rules/Uploaded.md)
- [Writable](rules/Writable.md)

## ISO codes

- [CountryCode](rules/CountryCode.md)
- [CurrencyCode](rules/CurrencyCode.md)
- [LanguageCode](rules/LanguageCode.md)
- [SubdivisionCode](rules/SubdivisionCode.md)

## Identifications

- [Bsn](rules/Bsn.md)
Expand Down Expand Up @@ -137,6 +130,13 @@
- [Url](rules/Url.md)
- [VideoUrl](rules/VideoUrl.md)

## ISO codes

- [CountryCode](rules/CountryCode.md)
- [CurrencyCode](rules/CurrencyCode.md)
- [LanguageCode](rules/LanguageCode.md)
- [SubdivisionCode](rules/SubdivisionCode.md)

## Localization

- [CountryCode](rules/CountryCode.md)
Expand All @@ -159,9 +159,9 @@

## Miscellaneous

- [Blank](rules/Blank.md)
- [FilterVar](rules/FilterVar.md)
- [Named](rules/Named.md)
- [NotBlank](rules/NotBlank.md)
- [NotEmpty](rules/NotEmpty.md)
- [NotUndef](rules/NotUndef.md)
- [Templated](rules/Templated.md)
Expand Down Expand Up @@ -235,8 +235,8 @@
- [In](rules/In.md)
- [Json](rules/Json.md)
- [Lowercase](rules/Lowercase.md)
- [NoWhitespace](rules/NoWhitespace.md)
- [NotEmoji](rules/NotEmoji.md)
- [NoWhitespace](rules/NoWhitespace.md)
- [Phone](rules/Phone.md)
- [PhpLabel](rules/PhpLabel.md)
- [PostalCode](rules/PostalCode.md)
Expand Down Expand Up @@ -315,6 +315,7 @@
- [Base64](rules/Base64.md)
- [Between](rules/Between.md)
- [BetweenExclusive](rules/BetweenExclusive.md)
- [Blank](rules/Blank.md)
- [BoolType](rules/BoolType.md)
- [BoolVal](rules/BoolVal.md)
- [Bsn](rules/Bsn.md)
Expand Down Expand Up @@ -401,13 +402,12 @@
- [Nif](rules/Nif.md)
- [Nip](rules/Nip.md)
- [No](rules/No.md)
- [NoWhitespace](rules/NoWhitespace.md)
- [NoneOf](rules/NoneOf.md)
- [Not](rules/Not.md)
- [NotBlank](rules/NotBlank.md)
- [NotEmoji](rules/NotEmoji.md)
- [NotEmpty](rules/NotEmpty.md)
- [NotUndef](rules/NotUndef.md)
- [NoWhitespace](rules/NoWhitespace.md)
- [NullOr](rules/NullOr.md)
- [NullType](rules/NullType.md)
- [Number](rules/Number.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Alnum.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ See also:
- [Decimal](Decimal.md)
- [Digit](Digit.md)
- [Lowercase](Lowercase.md)
- [NoWhitespace](NoWhitespace.md)
- [NotEmoji](NotEmoji.md)
- [NoWhitespace](NoWhitespace.md)
- [Regex](Regex.md)
- [StringType](StringType.md)
- [StringVal](StringVal.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ See also:
- [Decimal](Decimal.md)
- [Digit](Digit.md)
- [Lowercase](Lowercase.md)
- [NoWhitespace](NoWhitespace.md)
- [NotEmoji](NotEmoji.md)
- [NoWhitespace](NoWhitespace.md)
- [Regex](Regex.md)
- [Uppercase](Uppercase.md)
- [Vowel](Vowel.md)
2 changes: 2 additions & 0 deletions docs/rules/AlwaysValid.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ v::alwaysValid()->isValid('whatever'); // true
See also:

- [AlwaysInvalid](AlwaysInvalid.md)
- [KeyExists](KeyExists.md)
- [PropertyExists](PropertyExists.md)
11 changes: 6 additions & 5 deletions docs/rules/Attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ v::attributes()->assert(new Person('', 'not a date', 'not an email', 'not a phon

## Caveats

* If the object has no attributes, the validation will always pass.
* When the property is nullable, this rule will wrap the rule on the property into [NullOr](NullOr.md) rule.
* This rule has no templates because it uses the templates of the rules that are applied to the properties.
- If the object has no attributes, the validation will always pass.
- When the property is nullable, this rule will wrap the rule on the property into [NullOr](NullOr.md) rule.
- This rule has no templates because it uses the templates of the rules that are applied to the properties.

## Categorization

Expand All @@ -82,10 +82,11 @@ v::attributes()->assert(new Person('', 'not a date', 'not an email', 'not a phon
## Changelog

| Version | Description |
|--------:|-------------|
| ------: | ----------- |
| 3.0.0 | Created |

***
---

See also:

- [Named](Named.md)
Expand Down
63 changes: 63 additions & 0 deletions docs/rules/Blank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Blank

- `Blank()`

Validates if the given input is a blank value (`null`, zeros, empty strings or empty arrays, recursively).

```php
v::blank()->isValid(null); // true
v::blank()->isValid(''); // true
v::blank()->isValid([]); // true
v::blank()->isValid(' '); // true
v::blank()->isValid(0); // true
v::blank()->isValid('0'); // true
v::blank()->isValid(0); // true
v::blank()->isValid('0.0'); // true
v::blank()->isValid(false); // true
v::blank()->isValid(['']); // true
v::blank()->isValid([' ']); // true
v::blank()->isValid([0]); // true
v::blank()->isValid(['0']); // true
v::blank()->isValid([false]); // true
v::blank()->isValid([[''], [0]]); // true
v::blank()->isValid(new stdClass()); // true
```

It's similar to [NotEmpty](NotEmpty.md), but way stricter.

## Templates

### `Blank::TEMPLATE_STANDARD`

| Mode | Template |
| ---------- | ----------------------------- |
| `default` | {{subject}} must be blank |
| `inverted` | {{subject}} must not be blank |

## Template placeholders

| Placeholder | Description |
| ----------- | ---------------------------------------------------------------- |
| `subject` | The validated input or the custom validator name (if specified). |

## Categorization

- Miscellaneous

## Changelog

| Version | Description |
| ------: | ------------------------------------------- |
| 3.0.0 | Renamed to `Blank` and changed the behavior |
| 1.0.0 | Created as `NotBlank` |

---

See also:

- [NotEmpty](NotEmpty.md)
- [NotUndef](NotUndef.md)
- [NoWhitespace](NoWhitespace.md)
- [NullType](NullType.md)
- [Number](Number.md)
- [UndefOr](UndefOr.md)
11 changes: 6 additions & 5 deletions docs/rules/Call.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ v::call(
### `Call::TEMPLATE_STANDARD`

| Mode | Template |
|------------|------------------------------------------------------------|
| ---------- | ---------------------------------------------------------- |
| `default` | {{input}} must be a suitable argument for {{callable}} |
| `inverted` | {{input}} must not be a suitable argument for {{callable}} |

## Template placeholders

| Placeholder | Description |
|-------------|------------------------------------------------------------------|
| ----------- | ---------------------------------------------------------------- |
| `callable` | |
| `input` | |
| `subject` | The validated input or the custom validator name (if specified). |
| `subject` | The validated input or the custom validator name (if specified). |

## Categorization

Expand All @@ -67,10 +67,11 @@ v::call(
## Changelog

| Version | Description |
|--------:|-------------|
| ------: | ----------- |
| 0.3.9 | Created |

***
---

See also:

- [Callback](Callback.md)
Expand Down
5 changes: 3 additions & 2 deletions docs/rules/Circuit.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ This rule does not have any templates, because it will always return the result
## Changelog

| Version | Description |
|--------:|-------------|
| ------: | ----------- |
| 3.0.0 | Created |

***
---

See also:

- [AllOf](AllOf.md)
Expand Down
13 changes: 7 additions & 6 deletions docs/rules/Key.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ v::key('email', v::email())->assert(['email' => 'not email']);

## Note

* To validate if a key exists, use [KeyExists](KeyExists.md) instead.
* To validate an array against a given rule if the key exists, use [KeyOptional](KeyOptional.md) instead.
- To validate if a key exists, use [KeyExists](KeyExists.md) instead.
- To validate an array against a given rule if the key exists, use [KeyOptional](KeyOptional.md) instead.

## Templates

## Template placeholders

| Placeholder | Description |
|-------------|------------------------------------------------------------------|
| `subject` | The validated input or the custom validator name (if specified). |
| ----------- | ---------------------------------------------------------------- |
| `subject` | The validated input or the custom validator name (if specified). |

## Categorization

Expand All @@ -57,11 +57,12 @@ v::key('email', v::email())->assert(['email' => 'not email']);
## Changelog

| Version | Description |
|--------:|----------------------------------------------------------------------|
| ------: | -------------------------------------------------------------------- |
| 3.0.0 | Split by [KeyExists](KeyExists.md) and [KeyOptional](KeyOptional.md) |
| 0.3.9 | Created |

***
---

See also:

- [ArrayVal](ArrayVal.md)
Expand Down
1 change: 1 addition & 0 deletions docs/rules/KeyExists.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ v::key('foo', v::alwaysValid()->setName('Custom name'))->assert([]);

See also:

- [AlwaysValid](AlwaysValid.md)
- [ArrayType](ArrayType.md)
- [ArrayVal](ArrayVal.md)
- [Each](Each.md)
Expand Down
13 changes: 7 additions & 6 deletions docs/rules/KeyOptional.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ v::arrayType()->keyOptional('phone', v::phone())->assert('This is not an array')

Below are some other rules that are tightly related to `KeyOptional`:

* To validate if a key exists, use [KeyExists](KeyExists.md) instead.
* To validate an array against a given rule requiring the key to exist, use [Key](Key.md) instead.
- To validate if a key exists, use [KeyExists](KeyExists.md) instead.
- To validate an array against a given rule requiring the key to exist, use [Key](Key.md) instead.

## Templates

## Template placeholders

| Placeholder | Description |
|-------------|------------------------------------------------------------------|
| `subject` | The validated input or the custom validator name (if specified). |
| ----------- | ---------------------------------------------------------------- |
| `subject` | The validated input or the custom validator name (if specified). |

## Categorization

Expand All @@ -52,10 +52,11 @@ Below are some other rules that are tightly related to `KeyOptional`:
## Changelog

| Version | Description |
|--------:|----------------------------|
| ------: | -------------------------- |
| 3.0.0 | Created from [Key](Key.md) |

***
---

See also:

- [ArrayType](ArrayType.md)
Expand Down
Loading