Skip to content

Commit a6f8720

Browse files
committed
Create a few classes the will be present in the next version
This commit will deprecate some classes in favor of a couple of news ones. If there are no customisations to `assert()`, `check()`, and other methods, the migration should be pretty easy on users.
1 parent 8f6d986 commit a6f8720

11 files changed

+95
-10
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,16 @@ declare(strict_types=1);
6262

6363
namespace Respect\Validation\Rules;
6464

65+
use Respect\Validation\Rules\Core\Simple;
66+
6567
/**
6668
* Explain in one sentence what this rule does.
6769
*
6870
* @author Your Name <youremail@yourdomain.tld>
6971
*/
70-
final class HelloWorld extends AbstractRule
72+
final class HelloWorld extends Simple
7173
{
72-
/**
73-
* {@inheritDoc}
74-
*/
75-
public function validate($input): bool
74+
public function isValid(mixed $input): bool
7675
{
7776
return $input === 'Hello World';
7877
}

docs/06-custom-rules.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ validate method will be executed. Here's how the class should look:
1010
```php
1111
namespace My\Validation\Rules;
1212

13-
use Respect\Validation\Rules\AbstractRule;
13+
use Respect\Validation\Rules\Core\Simple;
1414

15-
final class Something extends AbstractRule
15+
final class Something extends Simple
1616
{
17-
public function validate($input): bool
17+
public function isValid(mixed $input): bool
1818
{
1919
// Do something here with the $input and return a boolean value
2020
}

library/Rules/AbstractComposite.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* @author Alexandre Gomes Gaigalas <[email protected]>
2323
* @author Henrique Moody <[email protected]>
2424
* @author Wojciech Frącz <[email protected]>
25+
*
26+
* @deprecated This class is deprecated, and will be removed in the next major version. Use {@see \Respect\Validation\Rules\Core\Composite} instead.
2527
*/
2628
abstract class AbstractComposite extends AbstractRule
2729
{

library/Rules/AbstractEnvelope.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* having an custom message.
2020
*
2121
* @author Henrique Moody <[email protected]>
22+
*
23+
* @deprecated This class is deprecated, and will be removed in the next major version. Use {@see \Respect\Validation\Rules\Core\Envelop} instead.
2224
*/
2325
abstract class AbstractEnvelope extends AbstractRule
2426
{

library/Rules/AbstractRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* @author Henrique Moody <[email protected]>
1919
* @author Nick Lombard <[email protected]>
2020
* @author Vicente Mendoza <[email protected]>
21+
*
22+
* @deprecated This class is deprecated, and will be removed in the next major version. Use {@see \Respect\Validation\Rules\Core\Simple} instead.
2123
*/
2224
abstract class AbstractRule implements Validatable
2325
{

library/Rules/AbstractWrapper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*
1717
* @author Alasdair North <[email protected]>
1818
* @author Henrique Moody <[email protected]>
19+
*
20+
* @deprecated This class is deprecated, and will be removed in the next major version. Use {@see \Respect\Validation\Rules\Core\Wrapper} instead.
1921
*/
2022
abstract class AbstractWrapper extends AbstractRule
2123
{

library/Rules/Core/Composite.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Respect\Validation\Rules\Core;
11+
12+
use Respect\Validation\Rules\AbstractComposite;
13+
use Respect\Validation\Validatable;
14+
15+
abstract class Composite extends AbstractComposite
16+
{
17+
public function __construct(Validatable $rule1, Validatable $rule2, Validatable ...$rules)
18+
{
19+
parent::__construct($rule1, $rule2, ...$rules);
20+
}
21+
}

library/Rules/Core/Envelope.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Respect\Validation\Rules\Core;
11+
12+
use Respect\Validation\Rules\AbstractEnvelope;
13+
14+
abstract class Envelope extends AbstractEnvelope
15+
{
16+
}

library/Rules/Core/Simple.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Respect\Validation\Rules\Core;
11+
12+
use Respect\Validation\Rules\AbstractRule;
13+
14+
abstract class Simple extends AbstractRule
15+
{
16+
abstract public function isValid(mixed $input): bool;
17+
18+
/**
19+
* @deprecated Calling `validate()` directly from rules is deprecated. Please use {@see Validator::isValid()} instead.
20+
*/
21+
public function validate($input): bool
22+
{
23+
return $this->isValid($input);
24+
}
25+
}

library/Rules/Core/Wrapper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Respect\Validation\Rules\Core;
11+
12+
use Respect\Validation\Rules\AbstractWrapper;
13+
14+
abstract class Wrapper extends AbstractWrapper
15+
{
16+
}

0 commit comments

Comments
 (0)