Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6dfff1c
add size method
walmir-silva Jul 1, 2024
18284e0
feat: Normalize Interfaces
walmir-silva Jul 1, 2024
21fc7c0
Merge branch 'main' into develop
walmir-silva Jul 1, 2024
132e0ee
Refactor and Normalize Collection Interface and Implementation
walmir-silva Jul 1, 2024
1124a8a
Merge branch 'main' into develop
walmir-silva Jul 1, 2024
f40b0c3
feat: Add BinaryHeap implementation and comprehensive tests
walmir-silva Jul 2, 2024
aaeb8d9
docs: Update README files in English and Portuguese
walmir-silva Jul 2, 2024
b1d7662
style: Normalize code formatting and style
walmir-silva Jul 2, 2024
d677ae5
Merge branch 'main' into develop
walmir-silva Jul 2, 2024
ff2922f
feat: Create Container interface and add unit tests
walmir-silva Jul 5, 2024
8316540
feat: Add logging interfaces and corresponding tests
walmir-silva Jul 5, 2024
fd0cb1c
feat: Update logging interfaces Add tests for LoggerAware and LoggerC…
walmir-silva Jul 10, 2024
1b46d44
Merge branch 'main' into develop
walmir-silva Jul 10, 2024
30dd462
feat(logging): improve log rotation and update log handler
walmir-silva Jul 18, 2024
fc2bbe3
Refactor:Indexable interface and LogLevel class
walmir-silva Oct 10, 2024
c00bfdc
Merge branch 'main' into develop
walmir-silva Oct 10, 2024
788e773
feat(contract): Add Processor interfaces and tests
walmir-silva Oct 13, 2024
b40023f
feat: add ProcessorRegistry interface and unit tests
walmir-silva Oct 13, 2024
468dc9a
Merge branch 'main' into develop
walmir-silva Oct 13, 2024
9e223a4
feat(processor): add ProcessorBuilder interface and test suite
walmir-silva Oct 14, 2024
3da44b1
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 14, 2024
611e84f
feat(contract): add PHPDoc for ProcessableAttribute interface and cre…
walmir-silva Oct 15, 2024
185bd7c
Merge branch 'main' into develop
walmir-silva Oct 15, 2024
bf99f58
feat(contract): add Sanitizer, Serializer, and Validator interfaces w…
walmir-silva Oct 15, 2024
3e56162
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 15, 2024
b1a9521
fix(validator): correct return type of Validator interface
walmir-silva Oct 15, 2024
115cad9
Merge branch 'main' into develop
walmir-silva Oct 15, 2024
2fcec44
feat(contract): add CustomizableMessageAttribute interface
walmir-silva Oct 18, 2024
c6758d7
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 18, 2024
1cbe3ca
feat: add BaseProcessorAttribute abstract class
walmir-silva Oct 18, 2024
756ea9f
refactor: adjusty filterValidProcessors in BaseProcessorAttribute
walmir-silva Oct 18, 2024
bf508f4
Merge branch 'main' into develop
walmir-silva Oct 18, 2024
9de21b2
feat(processor): add ProcessorValidator and ValidatableProcessor inte…
walmir-silva Oct 21, 2024
b5c27a7
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 21, 2024
8b7d45b
feat(validator): Add reset method to ValidatableProcessor interface
walmir-silva Oct 24, 2024
50f6c51
feat(validator): Add reset method to ValidatableProcessor interface
walmir-silva Oct 24, 2024
87e89f0
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 24, 2024
0d0fc3a
Merge branch 'main' into develop
walmir-silva Oct 24, 2024
260fd83
test(processor): add unit tests for ProcessingResult interface
walmir-silva Oct 25, 2024
a3a4547
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 25, 2024
9034f37
refactor: add professional comments to BaseProcessorAttribute and upd…
walmir-silva Oct 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ temp/
tmp/
.vscode/launch.json
.vscode/extensions.json
tests/lista_de_arquivos.php
tests/lista_de_arquivos.php
/composer.lock
26 changes: 13 additions & 13 deletions composer.lock

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

52 changes: 52 additions & 0 deletions src/Processor/Attribute/BaseProcessorAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,79 @@

namespace KaririCode\Contract\Processor\Attribute;

/**
* Classe BaseProcessorAttribute.
*
* Classe abstrata que implementa atributos de processamento, fornecendo funcionalidades
* para registrar processadores e mensagens customizadas associadas a cada um. Esta classe
* é projetada para servir como base para a criação de atributos de processamento que
* suportam personalização de mensagens.
*
* @category Processor
*
* @license MIT
*/
abstract class BaseProcessorAttribute implements ProcessableAttribute, CustomizableMessageAttribute
{
/**
* @var array Lista de processadores associados ao atributo.
* Somente processadores válidos são armazenados nesta lista.
*/
private readonly array $processors;

/**
* @var array Lista de mensagens customizadas para os processadores.
* As mensagens são associadas ao nome do processador e são opcionais.
*/
private readonly array $messages;

/**
* Construtor da classe BaseProcessorAttribute.
*
* Inicializa a lista de processadores e, opcionalmente, as mensagens customizadas.
* Os processadores inválidos (nulos ou false) são automaticamente filtrados.
*
* @param array $processors Lista de processadores a serem associados ao atributo
* @param array|null $messages (Opcional) Lista de mensagens customizadas associadas aos processadores
*/
public function __construct(array $processors, ?array $messages = null)
{
$this->processors = self::filterValidProcessors($processors);
$this->messages = $messages ?? [];
}

/**
* Retorna a lista de processadores associados ao atributo.
*
* @return array A lista de processadores válidos
*/
public function getProcessors(): array
{
return $this->processors;
}

/**
* Obtém uma mensagem customizada para um processador específico, caso esteja definida.
*
* @param string $processorName O nome do processador para o qual a mensagem é requisitada
*
* @return string|null A mensagem customizada associada ao processador, ou null se não existir
*/
public function getMessage(string $processorName): ?string
{
return $this->messages[$processorName] ?? null;
}

/**
* Filtra e retorna somente os processadores válidos.
*
* Este método estático remove processadores nulos ou definidos como false,
* garantindo que apenas processadores utilizáveis sejam armazenados.
*
* @param array $processors Lista de processadores a serem filtrados
*
* @return array A lista de processadores válidos
*/
private static function filterValidProcessors(array $processors): array
{
return array_filter($processors, static fn ($v) => null !== $v && false !== $v);
Expand Down
75 changes: 75 additions & 0 deletions src/Processor/ProcessingResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Processor;

/**
* Interface ProcessingResult.
*
* Defines the contract for handling processing results, including errors and processed data management.
*
* @category Processor
*
* @author Walmir Silva <walmir.silva@kariricode.org>
* @license MIT
*
* @see https://kariricode.org/
*/
interface ProcessingResult
{
/**
* Adds an error associated with a specific property.
*
* @param string $property The property where the error occurred
* @param string $errorKey A unique identifier for the type of error
* @param string $message A human-readable error message
*/
public function addError(string $property, string $errorKey, string $message): void;

/**
* Stores processed data for a specific property.
*
* @param string $property The property associated with the processed data
* @param mixed $value The processed value to be stored
*/
public function setProcessedData(string $property, mixed $value): void;

/**
* Checks if there are any errors in the processing result.
*
* @return bool True if there are errors, false otherwise
*/
public function hasErrors(): bool;

/**
* Retrieves all errors that occurred during processing.
*
* @return array<string, array<int, array{errorKey: string, message: string}>>
* A map of property names to their associated errors
*/
public function getErrors(): array;

/**
* Retrieves all processed data.
*
* @return array<string, mixed> A map of property names to their processed values
*/
public function getProcessedData(): array;

/**
* Converts the processing result into an array representation.
*
* @return array{
* isValid: bool,
* errors: array<string, array<int, array{errorKey: string, message: string}>>,
* processedData: array<string, mixed>
* }
*/
public function toArray(): array;

/**
* Clears all stored errors and processed data.
*/
public function clear(): void;
}
6 changes: 4 additions & 2 deletions src/Processor/ProcessorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*
* @category ProcessorPipeline
*
* @author Walmir Silva <walmir.silva@kariricode.org>
* @license MIT
* @author Walmir Silva <walmir.silva@kariricode.org>
*
* @see https://kariricode.org/
*/
Expand All @@ -31,8 +31,10 @@ interface ProcessorRegistry
* @param string $context The context under which the processor is registered
* @param string $name The unique name of the processor within the context
* @param Processor $processor The processor instance to be registered
*
* @return self Returns the current instance to enable a fluent interface
*/
public function register(string $context, string $name, Processor $processor): void;
public function register(string $context, string $name, Processor $processor): self;

/**
* Retrieves a processor by its context and name.
Expand Down
10 changes: 10 additions & 0 deletions src/Processor/ValidatableProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
*/
interface ValidatableProcessor extends Processor
{
/**
* Resets the processor's state to its initial values.
*
* This method should be called before reusing the processor instance to ensure
* that any previous validation state is cleared and the processor is ready for
* new validation. This is particularly important when processors are reused
* across multiple validation cycles.
*/
public function reset(): void;

/**
* Checks if the processor is in a valid state.
*
Expand Down
Loading
Loading