Skip to content

Commit 5f3cd86

Browse files
committed
General code improvements
1 parent 44c996f commit 5f3cd86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+361
-311
lines changed

README.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
Rakit Validation - PHP Standalone Validation Library
1+
WP Validation - PHP Standalone Validation Library
22
======================================================
33

44
[![Build Status](https://img.shields.io/travis/rakit/validation.svg?style=flat-square)](https://travis-ci.org/rakit/validation)
55
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://doge.mit-license.org)
66

77

8-
PHP Standalone library for validating data. Inspired by `Illuminate\Validation` Laravel.
8+
PHP Standalone library for validating data inspired by Laravel Validation
9+
10+
This is a fork of the original library written by [Rakit](https://github.com/rakit) with some more improvements and changes.
911

1012
## Features
1113

@@ -42,7 +44,7 @@ Using `make`:
4244

4345
require('vendor/autoload.php');
4446

45-
use Rakit\Validation\Validator;
47+
use DG\Validation\Validator;
4648

4749
$validator = new Validator;
4850

@@ -82,7 +84,7 @@ or just `validate` it:
8284

8385
require('vendor/autoload.php');
8486

85-
use Rakit\Validation\Validator;
87+
use DG\Validation\Validator;
8688

8789
$validator = new Validator;
8890

@@ -301,7 +303,7 @@ $message = $validation->errors()->first('nomor'); // "Nomor hanya memperbolehkan
301303
302304
## Working with Error Message
303305

304-
Errors messages are collected in `Rakit\Validation\ErrorBag` object that you can get it using `errors()` method.
306+
Errors messages are collected in `DG\Validation\ErrorBag` object that you can get it using `errors()` method.
305307

306308
```php
307309
$validation = $validator->validate($inputs, $rules);
@@ -924,15 +926,15 @@ $validation = $validator->validate($_POST, [
924926
]);
925927
```
926928

927-
> Note: `Rakit\Validation\Rules\Callback` instance is binded into your Closure.
929+
> Note: `DG\Validation\Rules\Callback` instance is binded into your Closure.
928930
So you can access rule properties and methods using `$this`.
929931

930932
</details>
931933

932934

933935
## Register/Override Rule
934936

935-
Another way to use custom validation rule is to create a class extending `Rakit\Validation\Rule`.
937+
Another way to use custom validation rule is to create a class extending `DG\Validation\Rule`.
936938
Then register it using `setValidator` or `addValidator`.
937939

938940
For example, you want to create `unique` validator that check field availability from database.
@@ -942,7 +944,7 @@ First, lets create `UniqueRule` class:
942944
```php
943945
<?php
944946

945-
use Rakit\Validation\Rule;
947+
use DG\Validation\Rule;
946948

947949
class UniqueRule extends Rule
948950
{
@@ -987,7 +989,7 @@ class UniqueRule extends Rule
987989
Then you need to register `UniqueRule` instance into validator like this:
988990

989991
```php
990-
use Rakit\Validation\Validator;
992+
use DG\Validation\Validator;
991993

992994
$validator = new Validator;
993995

@@ -1002,7 +1004,7 @@ $validation = $validator->validate($_POST, [
10021004
]);
10031005
```
10041006

1005-
In `UniqueRule` above, property `$message` is used for default invalid message. And property `$fillable_params` is used for `fillParameters` method (defined in `Rakit\Validation\Rule` class). By default `fillParameters` will fill parameters listed in `$fillable_params`. For example `unique:users,email,[email protected]` in example above, will set:
1007+
In `UniqueRule` above, property `$message` is used for default invalid message. And property `$fillable_params` is used for `fillParameters` method (defined in `DG\Validation\Rule` class). By default `fillParameters` will fill parameters listed in `$fillable_params`. For example `unique:users,email,[email protected]` in example above, will set:
10061008

10071009
```php
10081010
$params['table'] = 'users';
@@ -1029,7 +1031,7 @@ So you can improve `UniqueRule` class above by adding some methods that returnin
10291031
```php
10301032
<?php
10311033

1032-
use Rakit\Validation\Rule;
1034+
use DG\Validation\Rule;
10331035

10341036
class UniqueRule extends Rule
10351037
{
@@ -1078,7 +1080,7 @@ To make your custom rule implicit, you can make `$implicit` property value to be
10781080
```php
10791081
<?php
10801082

1081-
use Rakit\Validation\Rule;
1083+
use DG\Validation\Rule;
10821084

10831085
class YourCustomRule extends Rule
10841086
{
@@ -1092,15 +1094,15 @@ class YourCustomRule extends Rule
10921094

10931095
In some case, you may want your custom rule to be able to modify it's attribute value like our `default/defaults` rule. So in current and next rules checks, your modified value will be used.
10941096

1095-
To do this, you should implements `Rakit\Validation\Rules\Interfaces\ModifyValue` and create method `modifyValue($value)` to your custom rule class.
1097+
To do this, you should implements `DG\Validation\Rules\Interfaces\ModifyValue` and create method `modifyValue($value)` to your custom rule class.
10961098

10971099
For example:
10981100

10991101
```php
11001102
<?php
11011103

1102-
use Rakit\Validation\Rule;
1103-
use Rakit\Validation\Rules\Interfaces\ModifyValue;
1104+
use DG\Validation\Rule;
1105+
use DG\Validation\Rules\Interfaces\ModifyValue;
11041106

11051107
class YourCustomRule extends Rule implements ModifyValue
11061108
{
@@ -1121,24 +1123,24 @@ class YourCustomRule extends Rule implements ModifyValue
11211123

11221124
You may want to do some preparation before validation running. For example our `uploaded_file` rule will resolves attribute value that come from `$_FILES` (undesirable) array structure to be well-organized array structure, so we can validate multiple file upload just like validating other data.
11231125

1124-
To do this, you should implements `Rakit\Validation\Rules\Interfaces\BeforeValidate` and create method `beforeValidate()` to your custom rule class.
1126+
To do this, you should implements `DG\Validation\Rules\Interfaces\BeforeValidate` and create method `beforeValidate()` to your custom rule class.
11251127

11261128
For example:
11271129

11281130
```php
11291131
<?php
11301132

1131-
use Rakit\Validation\Rule;
1132-
use Rakit\Validation\Rules\Interfaces\BeforeValidate;
1133+
use DG\Validation\Rule;
1134+
use DG\Validation\Rules\Interfaces\BeforeValidate;
11331135

11341136
class YourCustomRule extends Rule implements BeforeValidate
11351137
{
11361138
...
11371139

11381140
public function beforeValidate()
11391141
{
1140-
$attribute = $this->getAttribute(); // Rakit\Validation\Attribute instance
1141-
$validation = $this->validation; // Rakit\Validation\Validation instance
1142+
$attribute = $this->getAttribute(); // DG\Validation\Attribute instance
1143+
$validation = $this->validation; // DG\Validation\Validation instance
11421144

11431145
// Do something with $attribute and $validation
11441146
// For example change attribute value

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
2-
"name": "rakit/validation",
2+
"name": "gdarko/wp-validation",
33
"description": "PHP Laravel like standalone validation library",
44
"license": "MIT",
55
"authors": [
66
{
7-
"email": "emsifa@gmail.com",
8-
"name": "Muhammad Syifa"
7+
"email": "dg@darkog.com",
8+
"name": "Darko Gjorgjijoski"
99
}
1010
],
1111
"autoload": {
1212
"psr-4": {
13-
"Rakit\\Validation\\": "src"
13+
"DG\\Validation\\": "src"
1414
}
1515
},
1616
"autoload-dev": {
1717
"psr-4": {
18-
"Rakit\\Validation\\Tests\\": ["tests", "tests/Fixtures"]
18+
"DG\\Validation\\Tests\\": ["tests", "tests/Fixtures"]
1919
}
2020
},
2121
"require": {

src/Attribute.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rakit\Validation;
3+
namespace DG\Validation;
44

55
class Attribute
66
{
@@ -14,13 +14,13 @@ class Attribute
1414
/** @var string|null */
1515
protected $alias;
1616

17-
/** @var Rakit\Validation\Validation */
17+
/** @var DG\Validation\Validation */
1818
protected $validation;
1919

2020
/** @var bool */
2121
protected $required = false;
2222

23-
/** @var Rakit\Validation\Validation|null */
23+
/** @var DG\Validation\Validation|null */
2424
protected $primaryAttribute = null;
2525

2626
/** @var array */
@@ -32,7 +32,7 @@ class Attribute
3232
/**
3333
* Constructor
3434
*
35-
* @param Rakit\Validation\Validation $validation
35+
* @param DG\Validation\Validation $validation
3636
* @param string $key
3737
* @param string|null $alias
3838
* @param array $rules
@@ -55,7 +55,7 @@ public function __construct(
5555
/**
5656
* Set the primary attribute
5757
*
58-
* @param Rakit\Validation\Attribute $primaryAttribute
58+
* @param DG\Validation\Attribute $primaryAttribute
5959
* @return void
6060
*/
6161
public function setPrimaryAttribute(Attribute $primaryAttribute)
@@ -77,7 +77,7 @@ public function setKeyIndexes(array $keyIndexes)
7777
/**
7878
* Get primary attributes
7979
*
80-
* @return Rakit\Validation\Attribute|null
80+
* @return DG\Validation\Attribute|null
8181
*/
8282
public function getPrimaryAttribute()
8383
{
@@ -101,7 +101,7 @@ public function setOtherAttributes(array $otherAttributes)
101101
/**
102102
* Add other attributes
103103
*
104-
* @param Rakit\Validation\Attribute $otherAttribute
104+
* @param DG\Validation\Attribute $otherAttribute
105105
* @return void
106106
*/
107107
public function addOtherAttribute(Attribute $otherAttribute)
@@ -122,7 +122,7 @@ public function getOtherAttributes(): array
122122
/**
123123
* Add rule
124124
*
125-
* @param Rakit\Validation\Rule $rule
125+
* @param DG\Validation\Rule $rule
126126
* @return void
127127
*/
128128
public function addRule(Rule $rule)

src/ErrorBag.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rakit\Validation;
3+
namespace DG\Validation;
44

55
class ErrorBag
66
{
@@ -22,9 +22,10 @@ public function __construct(array $messages = [])
2222
/**
2323
* Add message for given key and rule
2424
*
25-
* @param string $key
26-
* @param string $rule
27-
* @param string $message
25+
* @param string $key
26+
* @param string $rule
27+
* @param string $message
28+
*
2829
* @return void
2930
*/
3031
public function add(string $key, string $rule, string $message)
@@ -49,7 +50,8 @@ public function count(): int
4950
/**
5051
* Check given key is existed
5152
*
52-
* @param string $key
53+
* @param string $key
54+
*
5355
* @return bool
5456
*/
5557
public function has(string $key): bool
@@ -72,7 +74,8 @@ public function has(string $key): bool
7274
/**
7375
* Get the first value of array
7476
*
75-
* @param string $key
77+
* @param string $key
78+
*
7679
* @return mixed
7780
*/
7881
public function first(string $key)
@@ -100,8 +103,9 @@ public function first(string $key)
100103
/**
101104
* Get messages from given key, can be use custom format
102105
*
103-
* @param string $key
104-
* @param string $format
106+
* @param string $key
107+
* @param string $format
108+
*
105109
* @return array
106110
*/
107111
public function get(string $key, string $format = ':message'): array
@@ -131,7 +135,8 @@ public function get(string $key, string $format = ':message'): array
131135
/**
132136
* Get all messages
133137
*
134-
* @param string $format
138+
* @param string $format
139+
*
135140
* @return array
136141
*/
137142
public function all(string $format = ':message'): array
@@ -149,8 +154,9 @@ public function all(string $format = ':message'): array
149154
/**
150155
* Get the first message from existing keys
151156
*
152-
* @param string $format
153-
* @param boolean $dotNotation
157+
* @param string $format
158+
* @param bool $dotNotation
159+
*
154160
* @return array
155161
*/
156162
public function firstOfAll(string $format = ':message', bool $dotNotation = false): array
@@ -180,7 +186,8 @@ public function toArray(): array
180186
/**
181187
* Parse $key to get the array of $key and $ruleName
182188
*
183-
* @param string $key
189+
* @param string $key
190+
*
184191
* @return array
185192
*/
186193
protected function parseKey(string $key): array
@@ -205,8 +212,9 @@ protected function isWildcardKey(string $key): bool
205212
/**
206213
* Filter messages with wildcard key
207214
*
208-
* @param string $key
209-
* @param mixed $ruleName
215+
* @param string $key
216+
* @param mixed $ruleName
217+
*
210218
* @return array
211219
*/
212220
protected function filterMessagesForWildcardKey(string $key, $ruleName = null): array
@@ -236,8 +244,9 @@ protected function filterMessagesForWildcardKey(string $key, $ruleName = null):
236244
/**
237245
* Get formatted message
238246
*
239-
* @param string $message
240-
* @param string $format
247+
* @param string $message
248+
* @param string $format
249+
*
241250
* @return string
242251
*/
243252
protected function formatMessage(string $message, string $format): string

src/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rakit\Validation;
3+
namespace DG\Validation;
44

55
class Helper
66
{

src/MimeTypeGuesser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rakit\Validation;
3+
namespace DG\Validation;
44

55
class MimeTypeGuesser
66
{

src/MissingRequiredParameterException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rakit\Validation;
3+
namespace DG\Validation;
44

55
class MissingRequiredParameterException extends \Exception
66
{

0 commit comments

Comments
 (0)