-
Notifications
You must be signed in to change notification settings - Fork 34
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 #89 from utopia-php/feat-handle-null-param
feat: handle null param
- Loading branch information
Showing
7 changed files
with
248 additions
and
140 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,65 @@ | ||
<?php | ||
|
||
namespace Utopia\Validator; | ||
|
||
use Utopia\Validator; | ||
|
||
class Nullable extends Validator | ||
{ | ||
public function __construct(protected Validator $validator) | ||
{ | ||
} | ||
|
||
/** | ||
* Get Description | ||
* | ||
* Returns validator description | ||
* | ||
* @return string | ||
*/ | ||
public function getDescription(): string | ||
{ | ||
return $this->validator->getDescription() . ' or null'; | ||
} | ||
|
||
/** | ||
* Is array | ||
* | ||
* Function will return true if object is array. | ||
* | ||
* @return bool | ||
*/ | ||
public function isArray(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Get Type | ||
* | ||
* Returns validator type. | ||
* | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return $this->validator->getType(); | ||
} | ||
|
||
/** | ||
* Is valid | ||
* | ||
* Validation will pass when $value is text with valid length. | ||
* | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public function isValid(mixed $value): bool | ||
{ | ||
if (\is_null($value)) { | ||
return true; | ||
} | ||
|
||
return $this->validator->isValid($value); | ||
} | ||
} |
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