From a44cc1d2e3c0f147e91a5c052ac7fd879e34e706 Mon Sep 17 00:00:00 2001 From: Eole Date: Thu, 21 Jan 2016 10:29:26 +0100 Subject: Init Server Composer Components --- .../src/JsonSchema/Constraints/EnumConstraint.php | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/EnumConstraint.php (limited to 'server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/EnumConstraint.php') diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/EnumConstraint.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/EnumConstraint.php new file mode 100644 index 0000000..df413e4 --- /dev/null +++ b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/EnumConstraint.php @@ -0,0 +1,46 @@ + + * @author Bruno Prieto Reis + */ +class EnumConstraint extends Constraint +{ + /** + * {@inheritDoc} + */ + public function check($element, $schema = null, $path = null, $i = null) + { + // Only validate enum if the attribute exists + if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) { + return; + } + + foreach ($schema->enum as $enum) { + $type = gettype($element); + if ($type === gettype($enum)) { + if ($type == "object") { + if ($element == $enum) + return; + } else { + if ($element === $enum) + return; + + } + } + } + + $this->addError($path, "Does not have a value in the enumeration " . print_r($schema->enum, true), 'enum', array('enum' => $schema->enum,)); + } +} -- cgit v1.2.3