-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/v0.2.0' into main
- Loading branch information
Showing
25 changed files
with
942 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* @package Lucid | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Lucid; | ||
|
||
use DecodeLabs\Lucid\Validate\Error; | ||
use Generator; | ||
|
||
/** | ||
* @template TParam | ||
* @template TValue | ||
*/ | ||
interface Constraint | ||
{ | ||
/** | ||
* @phpstan-param Processor<TValue> $processor | ||
*/ | ||
public function __construct(Processor $processor); | ||
|
||
/** | ||
* @return array<string>|null | ||
*/ | ||
public static function getProcessorOutputTypes(): ?array; | ||
|
||
public function getName(): string; | ||
public function getWeight(): int; | ||
|
||
/** | ||
* @phpstan-return Processor<TValue> | ||
*/ | ||
public function getProcessor(): Processor; | ||
|
||
/** | ||
* @phpstan-param TParam $param | ||
* @return $this | ||
*/ | ||
public function setParameter(mixed $param): static; | ||
public function getParameter(): mixed; | ||
|
||
public function prepareValue(mixed $value): mixed; | ||
|
||
/** | ||
* @phpstan-param TValue $value | ||
* @phpstan-return TValue|null | ||
*/ | ||
public function alterValue(mixed $value): mixed; | ||
|
||
/** | ||
* @phpstan-param TValue|null $value | ||
* @phpstan-return Generator<int, Error|null, mixed, bool> | ||
*/ | ||
public function validate(mixed $value): Generator; | ||
} |
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,40 @@ | ||
<?php | ||
|
||
/** | ||
* @package Lucid | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Lucid\Constraint; | ||
|
||
use DecodeLabs\Lucid\Constraint; | ||
use DecodeLabs\Lucid\ConstraintTrait; | ||
|
||
/** | ||
* This constraint is used to wrap the main Processor | ||
* to be passed to Error objects | ||
* | ||
* @template TValue | ||
* @implements Constraint<TValue, TValue> | ||
*/ | ||
class Processor implements Constraint | ||
{ | ||
/** | ||
* @phpstan-use ConstraintTrait<TValue, TValue> | ||
*/ | ||
use ConstraintTrait; | ||
|
||
public const OUTPUT_TYPES = []; | ||
|
||
public function getName(): string | ||
{ | ||
return $this->processor->getName(); | ||
} | ||
|
||
public function getWeight(): int | ||
{ | ||
return 1; | ||
} | ||
} |
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,96 @@ | ||
<?php | ||
|
||
/** | ||
* @package Lucid | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Lucid; | ||
|
||
use Generator; | ||
use ReflectionClass; | ||
|
||
/** | ||
* @template TParam | ||
* @template TValue | ||
*/ | ||
trait ConstraintTrait | ||
{ | ||
/** | ||
* @phpstan-var Processor<TValue> | ||
*/ | ||
protected Processor $processor; | ||
|
||
/** | ||
* @phpstan-param Processor<TValue> $processor | ||
*/ | ||
public function __construct(Processor $processor) | ||
{ | ||
$this->processor = $processor; | ||
} | ||
|
||
public static function getProcessorOutputTypes(): ?array | ||
{ | ||
if ( | ||
defined('static::OUTPUT_TYPES') && | ||
/** @phpstan-ignore-next-line */ | ||
is_array(static::OUTPUT_TYPES) | ||
) { | ||
/** @phpstan-ignore-next-line */ | ||
return static::OUTPUT_TYPES; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return (new ReflectionClass($this)) | ||
->getShortName(); | ||
} | ||
|
||
public function getWeight(): int | ||
{ | ||
return 10; | ||
} | ||
|
||
public function getProcessor(): Processor | ||
{ | ||
return $this->processor; | ||
} | ||
|
||
/** | ||
* @phpstan-param TParam $param | ||
* @return $this | ||
*/ | ||
public function setParameter(mixed $param): static | ||
{ | ||
return $this; | ||
} | ||
|
||
public function getParameter(): mixed | ||
{ | ||
return null; | ||
} | ||
|
||
public function prepareValue(mixed $value): mixed | ||
{ | ||
return $value; | ||
} | ||
|
||
public function alterValue(mixed $value): mixed | ||
{ | ||
return $value; | ||
} | ||
|
||
/** | ||
* @phpstan-param TValue $value | ||
*/ | ||
public function validate(mixed $value): Generator | ||
{ | ||
yield null; | ||
return true; | ||
} | ||
} |
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,94 @@ | ||
<?php | ||
|
||
/** | ||
* @package Lucid | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Lucid; | ||
|
||
use DecodeLabs\Lucid\Validate\Error; | ||
use Generator; | ||
|
||
/** | ||
* @template TOutput | ||
*/ | ||
interface Processor | ||
{ | ||
public function __construct(Sanitizer $sanitizer); | ||
|
||
/** | ||
* @return array<string> | ||
*/ | ||
public function getOutputTypes(): array; | ||
|
||
public function getName(): string; | ||
public function getSanitizer(): Sanitizer; | ||
|
||
/** | ||
* Does this processor require a list of values? | ||
*/ | ||
public function isMultiValue(): bool; | ||
|
||
/** | ||
* Prepare value before coercion | ||
*/ | ||
public function prepareValue(mixed $value): mixed; | ||
|
||
/** | ||
* Apply value processing before validation | ||
* | ||
* @phpstan-param TOutput $value | ||
* @phpstan-return TOutput|null | ||
*/ | ||
public function alterValue(mixed $value): mixed; | ||
|
||
/** | ||
* Coerce input to output type or null | ||
* | ||
* @phpstan-return TOutput|null | ||
*/ | ||
public function coerce(mixed $value): mixed; | ||
|
||
|
||
/** | ||
* Test validity of constraint | ||
* | ||
* @return $this | ||
*/ | ||
public function test( | ||
string $constraint, | ||
mixed $param | ||
): static; | ||
|
||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function getDefaultConstraints(): array; | ||
|
||
|
||
/** | ||
* @phpstan-return array<string, Constraint<mixed, TOutput>> | ||
*/ | ||
public function prepareConstraints(): array; | ||
|
||
|
||
/** | ||
* Test constraints and yield errors in sequence | ||
* | ||
* @phpstan-param TOutput|null $value | ||
* @return Generator<Error|null> | ||
*/ | ||
public function validate(mixed $value): Generator; | ||
|
||
/** | ||
* Test type and yield errors in sequence | ||
* | ||
* @phpstan-param TOutput|null $value | ||
* @return Generator<Error|null> | ||
*/ | ||
public function validateType(mixed $value): Generator; | ||
} |
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,14 @@ | ||
<?php | ||
|
||
/** | ||
* @package Lucid | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Lucid; | ||
|
||
interface Provider | ||
{ | ||
} |
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.