-
Notifications
You must be signed in to change notification settings - Fork 3
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 #4 from vanilla/feature/invalid
Add support for allowNull and default
- Loading branch information
Showing
9 changed files
with
313 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* @author Todd Burry <[email protected]> | ||
* @copyright 2009-2017 Vanilla Forums Inc. | ||
* @license MIT | ||
*/ | ||
|
||
namespace Garden\Schema; | ||
|
||
|
||
/** | ||
* A singleton that represents an invalid value. | ||
* | ||
* The purpose of this class is to provide an alternative to **null** for invalid values when **null** could be considered | ||
* valid. This class is not meant to be used outside of this library unless you are extended the schema somehow. | ||
*/ | ||
class Invalid { | ||
private static $value; | ||
|
||
/** | ||
* Private constructor to enforce singleton. | ||
*/ | ||
private function __constructor() { | ||
// no-op | ||
} | ||
|
||
/** | ||
* Return the invalid value. | ||
* | ||
* @return Invalid Returns the invalid value. | ||
*/ | ||
public static function value() { | ||
if (self::$value === null) { | ||
self::$value = new Invalid(); | ||
} | ||
return self::$value; | ||
} | ||
|
||
/** | ||
* Tests a value to see if it is invalid. | ||
* | ||
* @param mixed $value The value to test. | ||
* @return bool Returns **true** of the value is invalid or **false** otherwise. | ||
*/ | ||
public static function isInvalid($value) { | ||
return $value === self::value(); | ||
} | ||
|
||
/** | ||
* Tests whether a value could be valid. | ||
* | ||
* Unlike {@link Invalid::inValid()} a value could still be invalid in some way even if this method returns true. | ||
* | ||
* @param mixed $value The value to test. | ||
* @return bool Returns **true** of the value could be invalid or **false** otherwise. | ||
*/ | ||
public static function isValid($value) { | ||
return $value !== self::value(); | ||
} | ||
} |
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
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