2 |
3 | # Aplus Framework Validation Library
4 |
5 | - [Home](https://aplus-framework.com/packages/validation)
6 | - [User Guide](https://docs.aplus-framework.com/guides/libraries/validation/index.html)
7 | - [API Documentation](https://docs.aplus-framework.com/packages/validation.html)
8 |
9 | [](https://github.com/aplus-framework/validation/actions/workflows/tests.yml)
10 | [](https://coveralls.io/github/aplus-framework/validation?branch=master)
11 | [](https://packagist.org/packages/aplus/validation)
12 | [](https://aplus-framework.com/sponsor)
13 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Natan Felles
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.phpstorm.meta.php:
--------------------------------------------------------------------------------
1 |
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 | namespace PHPSTORM_META;
11 |
12 | registerArgumentsSet(
13 | 'rules',
14 | 'alpha',
15 | 'alphaNumber',
16 | 'array',
17 | 'base64',
18 | 'between',
19 | 'blank',
20 | 'bool',
21 | 'datetime',
22 | 'dim',
23 | 'email',
24 | 'empty',
25 | 'equals',
26 | 'ext',
27 | 'float',
28 | 'greater',
29 | 'greaterOrEqual',
30 | 'hex',
31 | 'hexColor',
32 | 'image',
33 | 'in',
34 | 'int',
35 | 'ip',
36 | 'isset',
37 | 'json',
38 | 'latin',
39 | 'length',
40 | 'less',
41 | 'lessOrEqual',
42 | 'maxDim',
43 | 'maxLength',
44 | 'maxSize',
45 | 'md5',
46 | 'mimes',
47 | 'minDim',
48 | 'minLength',
49 | 'notBetween',
50 | 'notEquals',
51 | 'notIn',
52 | 'notRegex',
53 | 'null',
54 | 'number',
55 | 'object',
56 | 'optional',
57 | 'regex',
58 | 'required',
59 | 'specialChar',
60 | 'string',
61 | 'timezone',
62 | 'uploaded',
63 | 'url',
64 | 'uuid',
65 | );
66 | expectedArguments(
67 | \Framework\Validation\Validation::getMessage(),
68 | 1,
69 | argumentsSet('rules')
70 | );
71 | expectedArguments(
72 | \Framework\Validation\Validation::isRuleAvailable(),
73 | 0,
74 | argumentsSet('rules')
75 | );
76 | expectedArguments(
77 | \Framework\Validation\Validation::setMessage(),
78 | 1,
79 | argumentsSet('rules')
80 | );
81 | expectedArguments(
82 | \Framework\Validation\Validation::setRule(),
83 | 1,
84 | argumentsSet('rules')
85 | );
86 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aplus/validation",
3 | "description": "Aplus Framework Validation Library",
4 | "license": "MIT",
5 | "type": "library",
6 | "keywords": [
7 | "validation",
8 | "validator",
9 | "files-validation"
10 | ],
11 | "authors": [
12 | {
13 | "name": "Natan Felles",
14 | "email": "natanfelles@gmail.com",
15 | "homepage": "https://natanfelles.github.io"
16 | }
17 | ],
18 | "homepage": "https://aplus-framework.com/packages/validation",
19 | "support": {
20 | "email": "support@aplus-framework.com",
21 | "issues": "https://github.com/aplus-framework/validation/issues",
22 | "forum": "https://aplus-framework.com/forum",
23 | "source": "https://github.com/aplus-framework/validation",
24 | "docs": "https://docs.aplus-framework.com/guides/libraries/validation/"
25 | },
26 | "funding": [
27 | {
28 | "type": "Aplus Sponsor",
29 | "url": "https://aplus-framework.com/sponsor"
30 | }
31 | ],
32 | "require": {
33 | "php": ">=8.3",
34 | "ext-fileinfo": "*",
35 | "ext-intl": "*",
36 | "ext-json": "*",
37 | "aplus/debug": "^4.3",
38 | "aplus/helpers": "^4.0",
39 | "aplus/language": "^4.0"
40 | },
41 | "require-dev": {
42 | "ext-xdebug": "*",
43 | "aplus/coding-standard": "^2.8",
44 | "ergebnis/composer-normalize": "^2.25",
45 | "jetbrains/phpstorm-attributes": "^1.0",
46 | "phpmd/phpmd": "^2.13",
47 | "phpstan/phpstan": "^1.9",
48 | "phpunit/phpunit": "^10.5"
49 | },
50 | "minimum-stability": "dev",
51 | "prefer-stable": true,
52 | "autoload": {
53 | "psr-4": {
54 | "Framework\\Validation\\": "src/"
55 | }
56 | },
57 | "autoload-dev": {
58 | "psr-4": {
59 | "Tests\\Validation\\": "tests/"
60 | }
61 | },
62 | "config": {
63 | "allow-plugins": {
64 | "ergebnis/composer-normalize": true
65 | },
66 | "optimize-autoloader": true,
67 | "preferred-install": "dist",
68 | "sort-packages": true
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/BaseRules.php:
--------------------------------------------------------------------------------
1 |
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 | namespace Framework\Validation;
11 |
12 | use Error;
13 | use Stringable;
14 |
15 | /**
16 | * Class BaseRules.
17 | *
18 | * @property-read arrayA Validation instance has not been set in this collector.
'; 69 | } 70 | \ob_start(); ?> 71 | = $this->renderValidations() ?> 72 | validatorsRules = $this->getValidatorsRules(); ?> 73 |Validation did not run.
'; 85 | } 86 | $count = \count($this->getData()); 87 | \ob_start(); ?> 88 |Validation ran = $count ?> time= $count === 1 ? '' : 's' ?>. 89 |
90 |
| # | 94 |Type | 95 |Errors Count | 96 |Error Field | 97 |Error Message | 98 |Time | 99 |
|---|---|---|---|---|---|
| = $index + 1 ?> | 114 |= $item['type'] ?> | 115 |= $count ?> | 116 |= \htmlentities($errors[0]['field'] ?? '') ?> | 117 |= \htmlentities($errors[0]['error'] ?? '') ?> | 118 |= Debugger::roundSecondsToMilliseconds($item['end'] - $item['start']) ?> | 119 |
| = \htmlentities($errors[$i]['field']) ?> | 123 |= \htmlentities($errors[$i]['error']) ?> | 124 |
No rules have been set.
'; 136 | } 137 | \ob_start(); ?> 138 |The following rules have been set:
139 || # | 143 |Field | 144 |Label | 145 |Rule | 146 |Possible Error Message | 147 |
|---|---|---|---|---|
| = $index + 1 ?> | 154 |= \htmlentities($set['field']) ?> | 155 |= \htmlentities((string) $set['label']) ?> | 156 |= $this->sRule($set['rules'][0]['rule'], $this->validatorsRules) ?> | 157 |= \htmlentities($set['rules'][0]['message']) ?> | 158 |
| = $this->sRule($set['rules'][$i]['rule'], $this->validatorsRules) ?> | 162 |= \htmlentities($set['rules'][$i]['message']) ?> | 163 |
There are = \count($this->validatorsRules) ?> rules available:
176 || Rule | 180 |Params | 181 |Message Pattern | 182 |Validator | 183 |
|---|---|---|---|
| = \htmlentities($rule) ?> | 189 |
190 |
191 |
192 |
193 | |
194 |
195 | 199 | |
200 | = \htmlentities($data['validator']) ?> | 201 |