-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* centralize errors * isolate 'more' info * throw exception for missing error message * swap args
- Loading branch information
1 parent
72b94c1
commit 3dba977
Showing
15 changed files
with
268 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace JsonSchema; | ||
|
||
class ConstraintError extends \MabeEnum\Enum | ||
{ | ||
const ADDITIONAL_ITEMS = 'additionalItems'; | ||
const ADDITIONAL_PROPERTIES = 'additionalProp'; | ||
const ALL_OF = 'allOf'; | ||
const ANY_OF = 'anyOf'; | ||
const DEPENDENCIES = 'dependencies'; | ||
const DISALLOW = 'disallow'; | ||
const DIVISIBLE_BY = 'divisibleBy'; | ||
const ENUM = 'enum'; | ||
const EXCLUSIVE_MINIMUM = 'exclusiveMinimum'; | ||
const EXCLUSIVE_MAXIMUM = 'exclusiveMaximum'; | ||
const FORMAT_COLOR = 'colorFormat'; | ||
const FORMAT_DATE = 'dateFormat'; | ||
const FORMAT_DATE_TIME = 'dateTimeFormat'; | ||
const FORMAT_DATE_UTC = 'dateUtcFormat'; | ||
const FORMAT_EMAIL = 'emailFormat'; | ||
const FORMAT_HOSTNAME = 'styleHostName'; | ||
const FORMAT_IP = 'ipFormat'; | ||
const FORMAT_PHONE = 'phoneFormat'; | ||
const FORMAT_REGEX= 'regexFormat'; | ||
const FORMAT_STYLE = 'styleFormat'; | ||
const FORMAT_TIME = 'timeFormat'; | ||
const FORMAT_URL = 'urlFormat'; | ||
const LENGTH_MAX = 'maxLength'; | ||
const LENGTH_MIN = 'minLength'; | ||
const MAXIMUM = 'maximum'; | ||
const MIN_ITEMS = 'minItems'; | ||
const MINIMUM = 'minimum'; | ||
const MISSING_MAXIMUM = 'missingMaximum'; | ||
const MISSING_MINIMUM = 'missingMinimum'; | ||
const MAX_ITEMS = 'maxItems'; | ||
const MULTIPLE_OF = 'multipleOf'; | ||
const NOT = 'not'; | ||
const ONE_OF = 'oneOf'; | ||
const REQUIRED = 'required'; | ||
const REQUIRED_D3 = 'selfRequired'; | ||
const REQUIRES = 'requires'; | ||
const PATTERN = 'pattern'; | ||
const PREGEX_INVALID = 'pregrex'; | ||
const PROPERTIES_MIN = 'minProperties'; | ||
const PROPERTIES_MAX = 'maxProperties'; | ||
const TYPE = 'type'; | ||
const UNIQUE_ITEMS = 'uniqueItems'; | ||
|
||
public function getMessage() | ||
{ | ||
$name = $this->getValue(); | ||
static $messages = array( | ||
self::ADDITIONAL_ITEMS => 'The item %s[%s] is not defined and the definition does not allow additional items', | ||
self::ADDITIONAL_PROPERTIES => 'The property %s is not defined and the definition does not allow additional properties', | ||
self::ALL_OF => 'Failed to match all schemas', | ||
self::ANY_OF => 'Failed to match at least one schema', | ||
self::DEPENDENCIES => '%s depends on %s, which is missing', | ||
self::DISALLOW => 'Disallowed value was matched', | ||
self::DIVISIBLE_BY => 'Is not divisible by %d', | ||
self::ENUM => 'Does not have a value in the enumeration %s', | ||
self::EXCLUSIVE_MINIMUM => 'Must have a minimum value greater than %d', | ||
self::EXCLUSIVE_MAXIMUM => 'Must have a maximum value less than %d', | ||
self::FORMAT_COLOR => 'Invalid color', | ||
self::FORMAT_DATE => 'Invalid date %s, expected format YYYY-MM-DD', | ||
self::FORMAT_DATE_TIME => 'Invalid date-time %s, expected format YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss+hh:mm', | ||
self::FORMAT_DATE_UTC => 'Invalid time %s, expected integer of milliseconds since Epoch', | ||
self::FORMAT_EMAIL => 'Invalid email', | ||
self::FORMAT_HOSTNAME => 'Invalid hostname', | ||
self::FORMAT_IP => 'Invalid IP address', | ||
self::FORMAT_PHONE => 'Invalid phone number', | ||
self::FORMAT_REGEX=> 'Invalid regex format %s', | ||
self::FORMAT_STYLE => 'Invalid style', | ||
self::FORMAT_TIME => 'Invalid time %s, expected format hh:mm:ss', | ||
self::FORMAT_URL => 'Invalid URL format', | ||
self::LENGTH_MAX => 'Must be at most %d characters long', | ||
self::LENGTH_MIN => 'Must be at least %d characters long', | ||
self::MAX_ITEMS => 'There must be a maximum of %d items in the array', | ||
self::MAXIMUM => 'Must have a maximum value less than or equal to %d', | ||
self::MIN_ITEMS => 'There must be a minimum of %d items in the array', | ||
self::MINIMUM => 'Must have a minimum value greater than or equal to %d', | ||
self::MISSING_MAXIMUM => 'Use of exclusiveMaximum requires presence of maximum', | ||
self::MISSING_MINIMUM => 'Use of exclusiveMinimum requires presence of minimum', | ||
self::MULTIPLE_OF => 'Must be a multiple of %d', | ||
self::NOT => 'Matched a schema which it should not', | ||
self::ONE_OF => 'Failed to match exactly one schema', | ||
self::REQUIRED => 'The property %s is required', | ||
self::REQUIRED_D3 => 'Is missing and it is required', | ||
self::REQUIRES => 'The presence of the property %s requires that %s also be present', | ||
self::PATTERN => 'Does not match the regex pattern %s', | ||
self::PREGEX_INVALID => 'The pattern %s is invalid', | ||
self::PROPERTIES_MIN => 'Must contain a minimum of %d properties', | ||
self::PROPERTIES_MAX => 'Must contain no more than %d properties', | ||
self::TYPE => '%s value found, but %s is required', | ||
self::UNIQUE_ITEMS => 'There are no duplicates allowed in the array' | ||
); | ||
|
||
if (!isset($messages[$name])) { | ||
throw new InvalidArgumentException('Missing error message for ' . $name); | ||
} | ||
|
||
return $messages[$name]; | ||
} | ||
} |
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
Oops, something went wrong.