-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use PHP attributes to define templates
Creating a specific exception for each rule adds a painful overhead. If you want to make a custom message for your rule, you will need to create an exception and then register that exception namespace to be able to use it—all that is just for customizing the message of your rule. Having different namespaces also implies that you need to fetch the exception of the rule from another directory to change it. As Uncle Bob said, "Classes that change together belong together. Classes that are not reused together should not be grouped." This commit will drastically change this library, moving all the templates from the exceptions to the rules. Consequently, the Factory becomes much simpler, and the library gets a bit smaller, too. Signed-off-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
2b59e3d
commit e4f2c81
Showing
333 changed files
with
1,340 additions
and
4,515 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Respect\Validation\Attributes; | ||
|
||
use Attribute; | ||
use Respect\Validation\Exceptions\ValidationException; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
final class ExceptionClass | ||
{ | ||
/** | ||
* @param class-string<ValidationException> $class | ||
*/ | ||
public function __construct( | ||
public readonly string $class | ||
) { | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Respect\Validation\Attributes; | ||
|
||
use Attribute; | ||
use Respect\Validation\Validatable; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] | ||
final class Template | ||
{ | ||
public function __construct( | ||
public readonly string $default, | ||
public readonly string $negative, | ||
public readonly string $id = Validatable::TEMPLATE_STANDARD, | ||
) { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.