-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename "Attribute" rule to "Property"
Because now we have the concept of attributes in PHP, the rule with the name "Attribute" makes no sense because it doesn't validate attributes but properties. In the future, it might be possible that Validation will have a rule called "Attribute" to validate PHP attributes. Signed-off-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
8f545c1
commit 9259ea2
Showing
16 changed files
with
112 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Property | ||
|
||
- `Property(string $name)` | ||
- `Property(string $name, Validatable $rule)` | ||
- `Property(string $name, Validatable $rule, bool $mandatory)` | ||
|
||
Validates an object property, even private ones. | ||
|
||
```php | ||
$obj = new stdClass; | ||
$obj->foo = 'bar'; | ||
|
||
v::property('foo')->validate($obj); // true | ||
``` | ||
|
||
You can also validate the property itself: | ||
|
||
```php | ||
v::property('foo', v::equals('bar'))->validate($obj); // true | ||
``` | ||
|
||
Third parameter makes the property presence optional: | ||
|
||
```php | ||
v::property('lorem', v::stringType(), false)->validate($obj); // true | ||
``` | ||
|
||
The name of this validator is automatically set to the property name. | ||
|
||
## Categorization | ||
|
||
- Nesting | ||
- Objects | ||
- Structures | ||
|
||
## Changelog | ||
|
||
Version | Description | ||
--------|------------- | ||
3.0.0 | Renamed from `Attribute` to `Property` | ||
0.3.9 | Created | ||
|
||
*** | ||
See also: | ||
|
||
- [Key](Key.md) | ||
- [KeyNested](KeyNested.md) | ||
- [ObjectType](ObjectType.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,13 @@ | |
namespace Respect\Validation\Exceptions; | ||
|
||
/** | ||
* Exceptions to be thrown by the Attribute Rule. | ||
* Exceptions to be thrown by the Property Rule. | ||
* | ||
* @author Alexandre Gomes Gaigalas <[email protected]> | ||
* @author Emmerson Siqueira <[email protected]> | ||
* @author Henrique Moody <[email protected]> | ||
*/ | ||
final class AttributeException extends NestedValidationException implements NonOmissibleException | ||
final class PropertyException extends NestedValidationException implements NonOmissibleException | ||
{ | ||
public const NOT_PRESENT = 'not_present'; | ||
public const INVALID = 'invalid'; | ||
|
@@ -26,12 +26,12 @@ final class AttributeException extends NestedValidationException implements NonO | |
*/ | ||
protected $defaultTemplates = [ | ||
self::MODE_DEFAULT => [ | ||
self::NOT_PRESENT => 'Attribute {{name}} must be present', | ||
self::INVALID => 'Attribute {{name}} must be valid', | ||
self::NOT_PRESENT => 'Property {{name}} must be present', | ||
self::INVALID => 'Property {{name}} must be valid', | ||
], | ||
self::MODE_NEGATIVE => [ | ||
self::NOT_PRESENT => 'Attribute {{name}} must not be present', | ||
self::INVALID => 'Attribute {{name}} must not validate', | ||
self::NOT_PRESENT => 'Property {{name}} must not be present', | ||
self::INVALID => 'Property {{name}} must not validate', | ||
], | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,17 @@ | |
use function property_exists; | ||
|
||
/** | ||
* Validates an object attribute, event private ones. | ||
* Validates an object property, event private ones. | ||
* | ||
* @author Alexandre Gomes Gaigalas <[email protected]> | ||
* @author Emmerson Siqueira <[email protected]> | ||
* @author Henrique Moody <[email protected]> | ||
*/ | ||
final class Attribute extends AbstractRelated | ||
final class Property extends AbstractRelated | ||
{ | ||
public function __construct(string $reference, ?Validatable $rule = null, bool $mandatory = true) | ||
public function __construct(string $name, ?Validatable $rule = null, bool $mandatory = true) | ||
{ | ||
parent::__construct($reference, $rule, $mandatory); | ||
parent::__construct($name, $rule, $mandatory); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.