-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from programmatordev/1.x
1.2.0
- Loading branch information
Showing
16 changed files
with
505 additions
and
37 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 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,56 @@ | ||
# Blank | ||
|
||
Validates that a value is equal to an empty string, empty array, `false` or `null`. | ||
|
||
Check the [NotBlank](03-rules_not-blank.md) rule for the opposite validation. | ||
|
||
```php | ||
Blank( | ||
?callable $normalizer = null, | ||
?string $message = null | ||
); | ||
``` | ||
|
||
## Basic Usage | ||
|
||
Bellow are the *only* cases where the rule will succeed by default, | ||
everything else is considered invalid (you may want to check the [`normalizer`](#normalizer) option for a different behaviour): | ||
|
||
```php | ||
Validator::blank()->validate(''); // true | ||
Validator::blank()->validate([]); // true | ||
Validator::blank()->validate(false); // true | ||
Validator::blank()->validate(null); // true | ||
``` | ||
|
||
## Options | ||
|
||
### `normalizer` | ||
|
||
type: `?callable` default: `null` | ||
|
||
Allows to define a `callable` that will be applied to the value before checking if it is valid. | ||
|
||
For example, use `trim`, or pass your own function, to allow a string with whitespaces only: | ||
|
||
```php | ||
Validator::blank(normalizer: 'trim')->validate(' '); // true | ||
Validator::blank(normalizer: fn($value) => trim($value))->validate(' '); // true | ||
``` | ||
|
||
### `message` | ||
|
||
type: `?string` default: `The {{ name }} value should be blank, {{ value }} given.` | ||
|
||
Message that will be shown if the value is not blank. | ||
|
||
The following parameters are available: | ||
|
||
| Parameter | Description | | ||
|---------------|---------------------------| | ||
| `{{ value }}` | The current invalid value | | ||
| `{{ name }}` | Name of the invalid value | | ||
|
||
## Changelog | ||
|
||
- `1.2.0` Created |
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,126 @@ | ||
# CssColor | ||
|
||
Validates that a value is a valid CSS color. | ||
|
||
```php | ||
CssColor( | ||
?array $formats = null, | ||
?string $message = null | ||
); | ||
``` | ||
|
||
## Basic Usage | ||
|
||
```php | ||
// by default, all possible ways to define a CSS color are considered valid | ||
Validator::cssColor()->validate('#0f0f0f'); // true | ||
Validator::cssColor()->validate('black'); // true | ||
Validator::cssColor()->validate('rgb(0, 255, 0)'); // true | ||
// ... | ||
|
||
// restrict allowed formats | ||
Validator::cssColor(formats: ['hex-long'])->validate('#0f0f0f'); // true | ||
Validator::cssColor(formats: ['hex-long'])->validate('rgb(0, 255, 0)'); // false | ||
Validator::cssColor(formats: ['hex-long', 'rgb'])->validate('rgb(0, 255, 0)'); // true | ||
``` | ||
|
||
> [!NOTE] | ||
> An `UnexpectedValueException` will be thrown when a `formats` option is invalid. | ||
## Options | ||
|
||
### `formats` | ||
|
||
type: `?array` default: `null` | ||
|
||
By default, all possible ways to define a CSS color are considered valid. | ||
Use this options to restrict the allowed CSS formats. | ||
|
||
Available options are: | ||
|
||
- [`hex-long`](#hex-long) | ||
- [`hex-long-with-alpha`](#hex-long-with-alpha) | ||
- [`hex-short`](#hex-short) | ||
- [`hex-short-with-alpha`](#hex-short-with-alpha) | ||
- [`basic-named-colors`](#basic-named-colors) | ||
- [`extended-named-colors`](#extended-named-colors) | ||
- [`system-colors`](#system-colors) | ||
- [`keywords`](#keywords) | ||
- [`rgb`](#rgb) | ||
- [`rgba`](#rgba) | ||
- [`hsl`](#hsl) | ||
- [`hsla`](#hsla) | ||
|
||
#### `hex-long` | ||
|
||
Examples: `#0f0f0f`, `#0F0F0F` | ||
|
||
#### `hex-long-with-alpha` | ||
|
||
Examples: `#0f0f0f50`, `#0F0F0F50` | ||
|
||
#### `hex-short` | ||
|
||
Examples: `#0f0`, `#0F0` | ||
|
||
#### `hex-short-with-alpha` | ||
|
||
Examples: `#0f05`, `#0F05` | ||
|
||
#### `basic-named-colors` | ||
|
||
Colors names defined in the [W3C list of basic names colors](https://www.w3.org/wiki/CSS/Properties/color/keywords#Basic_Colors). | ||
|
||
Examples: `black`, `green` | ||
|
||
#### `extended-named-colors` | ||
|
||
Colors names defined in the [W3C list of extended names colors](https://www.w3.org/wiki/CSS/Properties/color/keywords#Extended_colors). | ||
|
||
Examples: `black`, `aqua`, `darkgoldenrod`, `green` | ||
|
||
#### `system-colors` | ||
|
||
Colors names defined in the [CSS WG list of system colors](https://drafts.csswg.org/css-color/#css-system-colors). | ||
|
||
Examples: `AccentColor`, `VisitedText` | ||
|
||
#### `keywords` | ||
|
||
Colors names defined in the [CSS WG list of keywords](https://drafts.csswg.org/css-color/#transparent-color). | ||
|
||
Examples: `transparent`, `currentColor` | ||
|
||
#### `rgb` | ||
|
||
Examples: `rgb(0, 255, 0)`, `rgb(0,255,0)` | ||
|
||
#### `rgba` | ||
|
||
Examples: `rgba(0, 255, 0, 50)`, `rgba(0,255,0,50)` | ||
|
||
#### `hsl` | ||
|
||
Examples: `hsl(0, 50%, 50%)`, `hsl(0,50%,50%)` | ||
|
||
#### `hsla` | ||
|
||
Examples: `hsla(0, 50%, 50%, 0.5)`, `hsla(0,50%,50%,0.5)` | ||
|
||
### `message` | ||
|
||
type: `?string` default: `The {{ name }} value is not a valid CSS color.` | ||
|
||
Message that will be shown if the input value is not a valid CSS color. | ||
|
||
The following parameters are available: | ||
|
||
| Parameter | Description | | ||
|-----------------|---------------------------| | ||
| `{{ value }}` | The current invalid value | | ||
| `{{ name }}` | Name of the invalid value | | ||
| `{{ formats }}` | Selected formats | | ||
|
||
## Changelog | ||
|
||
- `1.2.0` Created |
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,5 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\Validator\Exception; | ||
|
||
class BlankException extends ValidationException {} |
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,5 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\Validator\Exception; | ||
|
||
class CssColorException extends ValidationException {} |
Oops, something went wrong.