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

Commit 770c1d9

Browse files
committed
docs: added blank documentation
1 parent be82cf0 commit 770c1d9

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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)

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 not 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_not-blank.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Validates that a value is not equal to a blank string, blank array, `false` or `null`.
44

5+
Check the [Blank](03-rules_blank.md) rule for the opposite validation.
6+
57
```php
68
NotBlank(
79
?callable $normalizer = null,
@@ -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

0 commit comments

Comments
 (0)