Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from yiisoft/split-debug
Split debug
- Loading branch information
Showing
55 changed files
with
335 additions
and
4 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
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
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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Validator\Debug; | ||
|
||
use Traversable; | ||
use Yiisoft\Validator\Result; | ||
use Yiisoft\Yii\Debug\Collector\CollectorTrait; | ||
use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface; | ||
|
||
final class ValidatorCollector implements SummaryCollectorInterface | ||
{ | ||
use CollectorTrait; | ||
|
||
private array $validations = []; | ||
|
||
public function getCollected(): array | ||
{ | ||
return $this->validations; | ||
} | ||
|
||
public function collect(mixed $value, Result $result, callable|iterable|object|string|null $rules = null): void | ||
{ | ||
if (!$this->isActive()) { | ||
return; | ||
} | ||
|
||
if ($rules instanceof Traversable) { | ||
$rules = iterator_to_array($rules); | ||
} | ||
|
||
|
||
$this->validations[] = [ | ||
'value' => $value, | ||
'rules' => $rules, | ||
'result' => $result->isValid(), | ||
'errors' => $result->getErrors(), | ||
]; | ||
} | ||
|
||
public function getSummary(): array | ||
{ | ||
$count = count($this->validations); | ||
$countValid = count(array_filter($this->validations, fn (array $data): bool => (bool)$data['result'])); | ||
$countInvalid = $count - $countValid; | ||
|
||
return [ | ||
'validator' => [ | ||
'total' => $count, | ||
'valid' => $countValid, | ||
'invalid' => $countInvalid, | ||
], | ||
]; | ||
} | ||
|
||
private function reset(): void | ||
{ | ||
$this->validations = []; | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Validator\Debug; | ||
|
||
use Yiisoft\Validator\Result; | ||
use Yiisoft\Validator\RulesProviderInterface; | ||
use Yiisoft\Validator\ValidationContext; | ||
use Yiisoft\Validator\ValidatorInterface; | ||
|
||
final class ValidatorInterfaceProxy implements ValidatorInterface | ||
{ | ||
public function __construct( | ||
private ValidatorInterface $validator, | ||
private ValidatorCollector $collector, | ||
) { | ||
} | ||
|
||
public function validate( | ||
mixed $data, | ||
callable|iterable|object|string|null $rules = null, | ||
?ValidationContext $context = null | ||
): Result { | ||
$result = $this->validator->validate($data, $rules, $context); | ||
|
||
if ($rules === null && $data instanceof RulesProviderInterface) { | ||
$rules = (array) $data->getRules(); | ||
} | ||
|
||
$this->collector->collect( | ||
$data, | ||
$result, | ||
$rules, | ||
); | ||
|
||
return $result; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.