Recommend this page to a friend! |
Download .zip |
Info | View files (73) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2023-06-20 (1 month ago) | Not yet rated by the users | Total: 40 | All time: 10,679 This week: 65 |
Version | License | PHP version | Categories | |||
validator-php 1.0 | MIT/X Consortium ... | 5 | PHP 5, Validation |
Description | Author Smoren Contributor | |
This package can validate an array of values using multiple rules. |
composer require smoren/validator
use Smoren\Validator\Factories\Value;
use Smoren\Validator\Exceptions\ValidationError;
$rule = Value::container()
->array()
->hasAttribute('id', Value::integer()->positive())
->hasAttribute('probability', Value::float()->between(0, 1))
->hasAttribute('vectors', Value::container()->array()->allValuesAre(
Value::container()
->array()
->lengthIs(Value::integer()->equal(2))
->allValuesAre(Value::integer())
));
$validInput = [
'id' => 13,
'probability' => 0.92,
'vectors' => [[1, 2], [3, 4], [5, 6]],
];
try {
$rule->validate($validInput);
} catch (ValidationError $e) {
// Input is valid so this block is unreachable.
}
$invalidInput = [
'id' => '13',
'probability' => 1.92,
'vectors' => [[1, 2.1], [3, 4], [5, 6]],
];
try {
$rule->validate($invalidInput);
} catch (ValidationError $e) {
// Input is invalid so we catch the exception.
print_r($e->getViolatedRestrictions());
/*
[
['attribute_is', [
'attribute' => 'id',
'rule' => 'integer',
'violated_restrictions' => [
['integer', []]
]
]],
['attribute_is', [
'attribute' => 'probability',
'rule' => 'float',
'violated_restrictions' => [
['between', [
'start' => 0,
'end' => 1
]]
]
]],
['attribute_is', [
'attribute' => 'vectors',
'rule' => 'container',
'violated_restrictions' => [
['all_values_are', [
'rule' => 'container',
'violated_restrictions' => [
['all_values_are', [
'rule' => 'integer',
'violated_restrictions' => [
['integer', []]
]
]]
]
]]
]
]]
]
*/
}
composer install
composer test-init
composer test
PHP Validator Tools conforms to the following standards:
PHP Validation Tools is licensed under the MIT License.
Files |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
src (8 directories) | ||||
tests (3 files, 2 directories) | ||||
.scrutinizer.yml | Data | Auxiliary data | ||
codeception.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.xml | Data | Auxiliary data | ||
phpstan.neon | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Checks (6 files) | ||||
Exceptions (5 files) | ||||
Factories (2 files, 1 directory) | ||||
Helpers (2 files) | ||||
Interfaces (13 files) | ||||
Models (1 file) | ||||
Rules (10 files) | ||||
Structs (5 files) |
Files | / | src | / | Checks |
File | Role | Description |
---|---|---|
AllOfCheck.php | Class | Class source |
AnyOfCheck.php | Class | Class source |
Check.php | Class | Class source |
CompositeCheck.php | Class | Class source |
RetrospectiveCheck.php | Class | Class source |
WrappedCheck.php | Class | Class source |
Files | / | src | / | Exceptions |
File | Role | Description |
---|---|---|
CheckError.php | Class | Class source |
CompositeCheckError.php | Class | Class source |
FormInvalidConfigError.php | Class | Class source |
FormValidationError.php | Class | Class source |
ValidationError.php | Class | Class source |
Files | / | src | / | Factories |
File | Role | Description | ||
---|---|---|---|---|
Checks (5 files) | ||||
CheckBuilder.php | Class | Class source | ||
Value.php | Class | Class source |
Files | / | src | / | Factories | / | Checks |
File | Role | Description |
---|---|---|
BooleanCheckFactory.php | Class | Class source |
ContainerCheckFactory.php | Class | Class source |
MixedCheckFactory.php | Class | Class source |
NumericCheckFactory.php | Class | Class source |
StringCheckFactory.php | Class | Class source |
Files | / | src | / | Helpers |
File | Role | Description |
---|---|---|
ContainerAccessHelper.php | Class | Class source |
TypeHelper.php | Class | Class source |
Files | / | src | / | Interfaces |
File | Role | Description |
---|---|---|
BooleanRuleInterface.php | Class | Class source |
CheckInterface.php | Class | Class source |
CheckWrapperInterface.php | Class | Class source |
CompositeRuleInterface.php | Class | Class source |
ContainerRuleInterface.php | Class | Class source |
FloatRuleInterface.php | Class | Class source |
FormInterface.php | Class | Class source |
IntegerRuleInterface.php | Class | Class source |
MixedRuleInterface.php | Class | Class source |
NumericRuleInterface.php | Class | Class source |
StringRuleInterface.php | Class | Class source |
UtilityCheckInterface.php | Class | Class source |
ValidationResultInterface.php | Class | Class source |
Files | / | src | / | Rules |
File | Role | Description |
---|---|---|
AllOfRule.php | Class | Class source |
AnyOfRule.php | Class | Class source |
BaseRule.php | Class | Class source |
BooleanRule.php | Class | Class source |
ContainerRule.php | Class | Class source |
FloatRule.php | Class | Class source |
IntegerRule.php | Class | Class source |
MixedRule.php | Class | Class source |
NumericRule.php | Class | Class source |
StringRule.php | Class | Class source |
Files | / | src | / | Structs |
File | Role | Description |
---|---|---|
CheckName.php | Class | Class source |
CheckWrapper.php | Class | Class source |
Param.php | Class | Class source |
RuleName.php | Class | Class source |
ValidationSuccessResult.php | Class | Class source |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
unit (9 files, 1 directory) | ||||
_support (1 file) | ||||
coding_standard.xml | Data | Auxiliary data | ||
unit.suite.yml | Data | Auxiliary data | ||
_bootstrap.php | Aux. | Auxiliary script |
Files | / | tests | / | unit |
File | Role | Description | ||
---|---|---|---|---|
Fixture (3 files) | ||||
AllOfRuleTest.php | Class | Class source | ||
AnyOfRuleTest.php | Class | Class source | ||
BooleanTest.php | Class | Class source | ||
ContainerTest.php | Class | Class source | ||
FloatTest.php | Class | Class source | ||
IntegerTest.php | Class | Class source | ||
MixedTest.php | Class | Class source | ||
NumericTest.php | Class | Class source | ||
StringTest.php | Class | Class source |
Files | / | tests | / | unit | / | Fixture |
File | Role | Description |
---|---|---|
ArrayAccessListFixture.php | Class | Class source |
ArrayAccessMapFixture.php | Class | Class source |
SomeClassFixture.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.