Skip to content

Commit

Permalink
Merge pull request #4 from KaririCode-Framework/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
walmir-silva authored Oct 25, 2024
2 parents 0dc52a0 + b550edf commit 6bcb670
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 628 deletions.
43 changes: 22 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Contract/ValidationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

interface ValidationResult
{
public function addError(string $property, string $errorKey, string $message): void;

public function setValidatedData(string $property, mixed $value): void;

public function hasErrors(): bool;
public function isValid(): bool;

public function getErrors(): array;

Expand Down
10 changes: 0 additions & 10 deletions src/Contract/ValidationResultFactory.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Contract/ValidationResultProcessor.php

This file was deleted.

39 changes: 0 additions & 39 deletions src/Processor/DefaultValidationResultProcessor.php

This file was deleted.

36 changes: 36 additions & 0 deletions src/Result/ValidationResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace KaririCode\Validator\Result;

use KaririCode\ProcessorPipeline\Result\ProcessingResultCollection;
use KaririCode\Validator\Contract\ValidationResult as ValidationResultContract;

final class ValidationResult implements ValidationResultContract
{
public function __construct(
private readonly ProcessingResultCollection $results
) {
}

public function isValid(): bool
{
return !$this->results->hasErrors();
}

public function getErrors(): array
{
return $this->results->getErrors();
}

public function getValidatedData(): array
{
return $this->results->getProcessedData();
}

public function toArray(): array
{
return $this->results->toArray();
}
}
81 changes: 0 additions & 81 deletions src/ValidationResult.php

This file was deleted.

25 changes: 16 additions & 9 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,41 @@

use KaririCode\Contract\Processor\ProcessorRegistry;
use KaririCode\Contract\Validator\Validator as ValidatorContract;
use KaririCode\ProcessorPipeline\Handler\ProcessorAttributeHandler;
use KaririCode\ProcessorPipeline\ProcessorBuilder;
use KaririCode\PropertyInspector\AttributeAnalyzer;
use KaririCode\PropertyInspector\AttributeHandler;
use KaririCode\PropertyInspector\Utility\PropertyInspector;
use KaririCode\Validator\Attribute\Validate;
use KaririCode\Validator\Processor\DefaultValidationResultProcessor;
use KaririCode\Validator\Result\ValidationResult;

class Validator implements ValidatorContract
final class Validator implements ValidatorContract
{
private const IDENTIFIER = 'validator';

private ProcessorBuilder $builder;
private readonly ProcessorBuilder $builder;

public function __construct(
private readonly ProcessorRegistry $registry,
private readonly ProcessorRegistry $registry
) {
$this->builder = new ProcessorBuilder($this->registry);
}

public function validate(mixed $object): ValidationResult
{
$handler = new ProcessorAttributeHandler(
self::IDENTIFIER,
$this->builder
);

$propertyInspector = new PropertyInspector(
new AttributeAnalyzer(Validate::class)
);
$attributeHandler = new AttributeHandler(self::IDENTIFIER, $this->builder);
$resultProcessor = new DefaultValidationResultProcessor();
$handler = $propertyInspector->inspect($object, $attributeHandler);

return $resultProcessor->process($handler);
/** @var PropertyAttributeHandler */
$handler = $propertyInspector->inspect($object, $handler);

return new ValidationResult(
$handler->getProcessingResults()
);
}
}
Loading

0 comments on commit 6bcb670

Please sign in to comment.