-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the validation engine of composite-based rules
Signed-off-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
41245f6
commit f1b6f0c
Showing
10 changed files
with
170 additions
and
509 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,68 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Respect\Validation\Rules; | ||
|
||
use Respect\Validation\Helpers\DeprecatedValidatableMethods; | ||
use Respect\Validation\Validatable; | ||
|
||
abstract class Composite implements Validatable | ||
{ | ||
use DeprecatedValidatableMethods; | ||
|
||
/** @var array<Validatable> */ | ||
private readonly array $rules; | ||
|
||
private ?string $name = null; | ||
|
||
private ?string $template = null; | ||
|
||
public function __construct(Validatable ...$rules) | ||
{ | ||
$this->rules = $rules; | ||
} | ||
|
||
/** @return array<Validatable> */ | ||
public function getRules(): array | ||
{ | ||
return $this->rules; | ||
} | ||
|
||
public function setName(string $name): static | ||
{ | ||
foreach ($this->getRules() as $rule) { | ||
if ($rule->getName() && $this->name !== $rule->getName()) { | ||
continue; | ||
} | ||
|
||
$rule->setName($name); | ||
} | ||
|
||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setTemplate(string $template): static | ||
{ | ||
$this->template = $template; | ||
|
||
return $this; | ||
} | ||
|
||
public function getTemplate(): ?string | ||
{ | ||
return $this->template; | ||
} | ||
} |
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
Oops, something went wrong.