- WIP on validations
This commit is contained in:
1 parent
c82eae5be4
commit
f292ac63ca
5 files changed
+29
-6
No files matched your search
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute;
|
||||
|
||||
enum CommonRegexFormatEnum : string
|
||||
{
|
||||
case BasicEmail = "/[^@ \t\r\n]+@[^@ \t\r\n]+\.[^@ \t\r\n]+/i";
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class ContextField
|
||||
{
|
||||
public function __construct(
|
||||
public string $description = "",
|
||||
public bool $mandatory = false,
|
||||
public bool|MandatoryGroup $mandatory = false,
|
||||
public ?int $minLength = null,
|
||||
public ?int $maxLength = null,
|
||||
public ?int $minValue = null,
|
||||
@@ -25,7 +25,7 @@ class ContextField
|
||||
|
||||
public function assertValueSpecs(mixed $value, bool $isNew) : void
|
||||
{
|
||||
if ($isNew && ( $this->mandatory && $value === null )) {
|
||||
if ($isNew && ( $this->mandatory === true && $value === null )) {
|
||||
throw new MandatoryFieldException("Mandatory field must be provided a value.");
|
||||
}
|
||||
elseif ($value !== null) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute;
|
||||
|
||||
readonly class MandatoryGroup
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public int $needed = 1,
|
||||
) {}
|
||||
}
|
||||
Reference in new issue
Block a user