Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 74fdbd7

Browse files
authored
Merge pull request #70 from programmatordev/1.x
1.2.0
2 parents e32b2dc + 1818f7e commit 74fdbd7

16 files changed

+505
-37
lines changed

.ddev/config.yaml

+15-9
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ omit_containers: [db]
1313
use_dns_when_possible: true
1414
composer_version: "2"
1515
web_environment: []
16+
corepack_enable: false
1617
disable_upload_dirs_warning: true
1718

1819
# Key features of DDEV's config.yaml:
1920

2021
# name: <projectname> # Name of the project, automatically provides
2122
# http://projectname.ddev.site and https://projectname.ddev.site
2223

23-
# type: <projecttype> # backdrop, craftcms, django4, drupal6/7/8/9/10, laravel, magento, magento2, php, python, shopware6, silverstripe, typo3, wordpress
24-
# See https://ddev.readthedocs.io/en/latest/users/quickstart/ for more
24+
# type: <projecttype> # backdrop, craftcms, django4, drupal, drupal6, drupal7, laravel, magento, magento2, php, python, shopware6, silverstripe, typo3, wordpress
25+
# See https://ddev.readthedocs.io/en/stable/users/quickstart/ for more
2526
# information on the different project types
27+
# "drupal" covers recent Drupal 8+
2628

2729
# docroot: <relative_path> # Relative path to the directory containing index.php.
2830

29-
# php_version: "8.1" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"
31+
# php_version: "8.2" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"
3032

3133
# You can explicitly specify the webimage but this
3234
# is not recommended, as the images are often closely tied to DDEV's' behavior,
@@ -36,8 +38,9 @@ disable_upload_dirs_warning: true
3638

3739
# database:
3840
# type: <dbtype> # mysql, mariadb, postgres
39-
# version: <version> # database version, like "10.4" or "8.0"
40-
# MariaDB versions can be 5.5-10.8 and 10.11, MySQL versions can be 5.5-8.0
41+
# version: <version> # database version, like "10.11" or "8.0"
42+
# MariaDB versions can be 5.5-10.8, 10.11, and 11.4.
43+
# MySQL versions can be 5.5-8.0.
4144
# PostgreSQL versions can be 9-16.
4245

4346
# router_http_port: <port> # Port to be used for http (defaults to global configuration, usually 80)
@@ -77,7 +80,7 @@ disable_upload_dirs_warning: true
7780
# Alternatively, an explicit Composer version may be specified, for example "2.2.18".
7881
# To reinstall Composer after the image was built, run "ddev debug refresh".
7982

80-
# nodejs_version: "18"
83+
# nodejs_version: "20"
8184
# change from the default system Node.js version to any other version.
8285
# Numeric version numbers can be complete (i.e. 18.15.0) or
8386
# incomplete (18, 17.2, 16). 'lts' and 'latest' can be used as well along with
@@ -86,6 +89,9 @@ disable_upload_dirs_warning: true
8689
# Note that you can continue using 'ddev nvm' or nvm inside the web container
8790
# to change the project's installed node version if you need to.
8891

92+
# corepack_enable: false
93+
# Change to 'true' to 'corepack enable' and gain access to latest versions of yarn/pnpm
94+
8995
# additional_hostnames:
9096
# - somename
9197
# - someothername
@@ -143,8 +149,8 @@ disable_upload_dirs_warning: true
143149
# - "mutagen": enables Mutagen for this project.
144150
# - "nfs": enables NFS for this project.
145151
#
146-
# See https://ddev.readthedocs.io/en/latest/users/install/performance/#nfs
147-
# See https://ddev.readthedocs.io/en/latest/users/install/performance/#mutagen
152+
# See https://ddev.readthedocs.io/en/stable/users/install/performance/#nfs
153+
# See https://ddev.readthedocs.io/en/stable/users/install/performance/#mutagen
148154

149155
# fail_on_hook_fail: False
150156
# Decide whether 'ddev start' should be interrupted by a failing hook
@@ -197,7 +203,7 @@ disable_upload_dirs_warning: true
197203

198204
# disable_settings_management: false
199205
# If true, DDEV will not create CMS-specific settings files like
200-
# Drupal's settings.php/settings.ddev.php or TYPO3's AdditionalConfiguration.php
206+
# Drupal's settings.php/settings.ddev.php or TYPO3's additional.php
201207
# In this case the user must provide all such settings.
202208

203209
# You can inject environment variables into the web container with:

README.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,12 @@ PHP validator with expressive error messages.
1212

1313
## Installation
1414

15-
You can install the library via [Composer](https://getcomposer.org/):
15+
Install the library via [Composer](https://getcomposer.org/):
1616

1717
```bash
1818
composer require programmatordev/yet-another-php-validator
1919
```
2020

21-
To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
22-
23-
```php
24-
require_once 'vendor/autoload.php';
25-
```
26-
2721
## Basic Usage
2822

2923
Simple usage looks like:

docs/01-get-started.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@
1010

1111
## Installation
1212

13-
You can install the library via [Composer](https://getcomposer.org/):
13+
Install the library via [Composer](https://getcomposer.org/):
1414

1515
```bash
1616
composer require programmatordev/yet-another-php-validator
1717
```
1818

19-
To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
20-
21-
```php
22-
require_once 'vendor/autoload.php';
23-
```
24-
2519
## Basic Usage
2620

2721
Simple usage looks like:

docs/03-rules.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
## Basic Rules
1212

13+
- [Blank](03-rules_blank.md)
1314
- [Count](03-rules_count.md)
1415
- [NotBlank](03-rules_not-blank.md)
1516
- [Type](03-rules_type.md)
1617

1718
## String Rules
1819

20+
- [CssColor](03-rules_css-color.md)
1921
- [Email](03-rules_email.md)
2022
- [Length](03-rules_length.md)
2123
- [PasswordStrength](03-rules_password-strength.md)

docs/03-rules_blank.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Blank
2+
3+
Validates that a value is equal to an empty string, empty array, `false` or `null`.
4+
5+
Check the [NotBlank](03-rules_not-blank.md) rule for the opposite validation.
6+
7+
```php
8+
Blank(
9+
?callable $normalizer = null,
10+
?string $message = null
11+
);
12+
```
13+
14+
## Basic Usage
15+
16+
Bellow are the *only* cases where the rule will succeed by default,
17+
everything else is considered invalid (you may want to check the [`normalizer`](#normalizer) option for a different behaviour):
18+
19+
```php
20+
Validator::blank()->validate(''); // true
21+
Validator::blank()->validate([]); // true
22+
Validator::blank()->validate(false); // true
23+
Validator::blank()->validate(null); // true
24+
```
25+
26+
## Options
27+
28+
### `normalizer`
29+
30+
type: `?callable` default: `null`
31+
32+
Allows to define a `callable` that will be applied to the value before checking if it is valid.
33+
34+
For example, use `trim`, or pass your own function, to allow a string with whitespaces only:
35+
36+
```php
37+
Validator::blank(normalizer: 'trim')->validate(' '); // true
38+
Validator::blank(normalizer: fn($value) => trim($value))->validate(' '); // true
39+
```
40+
41+
### `message`
42+
43+
type: `?string` default: `The {{ name }} value should be blank, {{ value }} given.`
44+
45+
Message that will be shown if the value is not blank.
46+
47+
The following parameters are available:
48+
49+
| Parameter | Description |
50+
|---------------|---------------------------|
51+
| `{{ value }}` | The current invalid value |
52+
| `{{ name }}` | Name of the invalid value |
53+
54+
## Changelog
55+
56+
- `1.2.0` Created

docs/03-rules_css-color.md

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# CssColor
2+
3+
Validates that a value is a valid CSS color.
4+
5+
```php
6+
CssColor(
7+
?array $formats = null,
8+
?string $message = null
9+
);
10+
```
11+
12+
## Basic Usage
13+
14+
```php
15+
// by default, all possible ways to define a CSS color are considered valid
16+
Validator::cssColor()->validate('#0f0f0f'); // true
17+
Validator::cssColor()->validate('black'); // true
18+
Validator::cssColor()->validate('rgb(0, 255, 0)'); // true
19+
// ...
20+
21+
// restrict allowed formats
22+
Validator::cssColor(formats: ['hex-long'])->validate('#0f0f0f'); // true
23+
Validator::cssColor(formats: ['hex-long'])->validate('rgb(0, 255, 0)'); // false
24+
Validator::cssColor(formats: ['hex-long', 'rgb'])->validate('rgb(0, 255, 0)'); // true
25+
```
26+
27+
> [!NOTE]
28+
> An `UnexpectedValueException` will be thrown when a `formats` option is invalid.
29+
30+
## Options
31+
32+
### `formats`
33+
34+
type: `?array` default: `null`
35+
36+
By default, all possible ways to define a CSS color are considered valid.
37+
Use this options to restrict the allowed CSS formats.
38+
39+
Available options are:
40+
41+
- [`hex-long`](#hex-long)
42+
- [`hex-long-with-alpha`](#hex-long-with-alpha)
43+
- [`hex-short`](#hex-short)
44+
- [`hex-short-with-alpha`](#hex-short-with-alpha)
45+
- [`basic-named-colors`](#basic-named-colors)
46+
- [`extended-named-colors`](#extended-named-colors)
47+
- [`system-colors`](#system-colors)
48+
- [`keywords`](#keywords)
49+
- [`rgb`](#rgb)
50+
- [`rgba`](#rgba)
51+
- [`hsl`](#hsl)
52+
- [`hsla`](#hsla)
53+
54+
#### `hex-long`
55+
56+
Examples: `#0f0f0f`, `#0F0F0F`
57+
58+
#### `hex-long-with-alpha`
59+
60+
Examples: `#0f0f0f50`, `#0F0F0F50`
61+
62+
#### `hex-short`
63+
64+
Examples: `#0f0`, `#0F0`
65+
66+
#### `hex-short-with-alpha`
67+
68+
Examples: `#0f05`, `#0F05`
69+
70+
#### `basic-named-colors`
71+
72+
Colors names defined in the [W3C list of basic names colors](https://www.w3.org/wiki/CSS/Properties/color/keywords#Basic_Colors).
73+
74+
Examples: `black`, `green`
75+
76+
#### `extended-named-colors`
77+
78+
Colors names defined in the [W3C list of extended names colors](https://www.w3.org/wiki/CSS/Properties/color/keywords#Extended_colors).
79+
80+
Examples: `black`, `aqua`, `darkgoldenrod`, `green`
81+
82+
#### `system-colors`
83+
84+
Colors names defined in the [CSS WG list of system colors](https://drafts.csswg.org/css-color/#css-system-colors).
85+
86+
Examples: `AccentColor`, `VisitedText`
87+
88+
#### `keywords`
89+
90+
Colors names defined in the [CSS WG list of keywords](https://drafts.csswg.org/css-color/#transparent-color).
91+
92+
Examples: `transparent`, `currentColor`
93+
94+
#### `rgb`
95+
96+
Examples: `rgb(0, 255, 0)`, `rgb(0,255,0)`
97+
98+
#### `rgba`
99+
100+
Examples: `rgba(0, 255, 0, 50)`, `rgba(0,255,0,50)`
101+
102+
#### `hsl`
103+
104+
Examples: `hsl(0, 50%, 50%)`, `hsl(0,50%,50%)`
105+
106+
#### `hsla`
107+
108+
Examples: `hsla(0, 50%, 50%, 0.5)`, `hsla(0,50%,50%,0.5)`
109+
110+
### `message`
111+
112+
type: `?string` default: `The {{ name }} value is not a valid CSS color.`
113+
114+
Message that will be shown if the input value is not a valid CSS color.
115+
116+
The following parameters are available:
117+
118+
| Parameter | Description |
119+
|-----------------|---------------------------|
120+
| `{{ value }}` | The current invalid value |
121+
| `{{ name }}` | Name of the invalid value |
122+
| `{{ formats }}` | Selected formats |
123+
124+
## Changelog
125+
126+
- `1.2.0` Created

docs/03-rules_not-blank.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# NotBlank
22

3-
Validates that a value is not equal to a blank string, blank array, `false` or `null`.
3+
Validates that a value is not equal to an empty string, empty array, `false` or `null`.
4+
5+
Check the [Blank](03-rules_blank.md) rule for the opposite validation.
46

57
```php
68
NotBlank(
@@ -25,17 +27,14 @@ Validator::notBlank()->validate(null); // false
2527

2628
### `normalizer`
2729

28-
type: `callable` default: `null`
30+
type: `?callable` default: `null`
2931

3032
Allows to define a `callable` that will be applied to the value before checking if it is valid.
3133

3234
For example, use `trim`, or pass your own function, to not allow a string with whitespaces only:
3335

3436
```php
35-
// Existing PHP callables
3637
Validator::notBlank(normalizer: 'trim')->validate(' '); // false
37-
38-
// Function
3938
Validator::notBlank(normalizer: fn($value) => trim($value))->validate(' '); // false
4039
```
4140

src/ChainedValidatorInterface.php

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
interface ChainedValidatorInterface
99
{
10+
public function blank(
11+
?callable $normalizer = null,
12+
?string $message = null
13+
): ChainedValidatorInterface&Validator;
14+
1015
public function choice(
1116
array $constraints,
1217
bool $multiple = false,
@@ -39,6 +44,11 @@ public function country(
3944
?string $message = null
4045
): ChainedValidatorInterface&Validator;
4146

47+
public function cssColor(
48+
?array $formats = null,
49+
?string $message = null
50+
): ChainedValidatorInterface&Validator;
51+
4252
public function dateTime(
4353
string $format = 'Y-m-d H:i:s',
4454
?string $message = null

src/Exception/BlankException.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\Validator\Exception;
4+
5+
class BlankException extends ValidationException {}

src/Exception/CssColorException.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\Validator\Exception;
4+
5+
class CssColorException extends ValidationException {}

0 commit comments

Comments
 (0)