diff --git a/lib/JsonSchemaDraft01.php b/lib/JsonSchemaDraft01.php deleted file mode 100644 index b45d6de..0000000 --- a/lib/JsonSchemaDraft01.php +++ /dev/null @@ -1,1091 +0,0 @@ - - * @author Gregory Beaver - * @version 1.5 - * @see http://github.com/garycourt/JSV - */ -namespace JsonSchema; - -/* - * Copyright 2010 Gary Court. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of Gary Court or the JSON Schema specification. - */ - -/*jslint white: true, sub: true, onevar: true, undef: true, eqeqeq: true, newcap: true, immed: true, indent: 4 */ -/*global require */ - -class JsonSchemaDraft01 -{ - var $ENVIRONMENT, - $TYPE_VALIDATORS, - $SCHEMA, - $HYPERSCHEMA, - $LINKS; - - function __construct($register = true) - { - $this->initializeTypeValidators(); - $this->initializeEnvironment(); - $this->initializeSchema(); - $this->initializeHyperSchema(); - $this->initializeLinks(); - - //We need to reinitialize these 3 schemas as they all reference each other - if ($register) { - $this->registerSchemas(); - } - } - - function registerSchemas() - { - $this->SCHEMA = $this->ENVIRONMENT->createSchema($this->SCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/schema#"); - $this->HYPERSCHEMA = $this->ENVIRONMENT->createSchema($this->HYPERSCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/hyper-schema#"); - $this->LINKS = $this->ENVIRONMENT->createSchema($this->LINKS->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/links#"); - - JSV::registerEnvironment("json-schema-draft-00", $this->ENVIRONMENT); - JSV::registerEnvironment("json-schema-draft-01", JSV::createEnvironment("json-schema-draft-00")); - - if (!JSV::getDefaultEnvironmentID()) { - JSV::setDefaultEnvironmentID("json-schema-draft-01"); - } - } - - function initializeTypeValidators() - { - $this->TYPE_VALIDATORS = array( - "string" => function ($instance, $report) { - return is_string($instance->getValue()); - }, - - "number" => function ($instance, $report) { - return is_numeric($instance->getValue()); - }, - - "integer" => function ($instance, $report) { - return is_int($instance->getValue()); - }, - - "boolean" => function ($instance, $report) { - return is_bool($instance->getValue()); - }, - - "object" => function ($instance, $report) { - return is_json_object($instance->getValue()); - }, - - "array" => function ($instance, $report) { - return is_json_array($instance->getValue()); - }, - - "null" => function ($instance, $report) { - return $instance->getValue() === null; - }, - - "any" => function ($instance, $report) { - return true; - } - ); - } - - function initializeEnvironment() - { - $this->ENVIRONMENT = new Environment(); - $this->ENVIRONMENT->setOption("defaultFragmentDelimiter", "."); - $this->ENVIRONMENT->setOption("defaultSchemaURI", "http://json-schema.org/schema#"); //updated later - } - - protected function getSchemaArray() - { - return array( - '$schema' => "http://json-schema.org/hyper-schema#", - "id" => "http://json-schema.org/schema#", - "type" => "object", - - "properties" => array( - "type" => array( - "type" => array("string", "array"), - "items" => array( - "type" => array("string", array('$ref' => "#")) - ), - "optional" => true, - "uniqueItems" => true, - "default" => "any", - - "parser" => function (JSONInstance $instance, $self) { - if (is_string($instance->getValue())) { - return $instance->getValue(); - } else if (is_json_object($instance->getValue())) { - return $instance->getEnvironment()->createSchema( - $instance, - $self->getEnvironment()->findSchema($self->resolveURI("#")) - ); - } else if (is_array($instance->getValue())) { // don't need is_json_array because of previous elseif - $parser = $self->getValueOfProperty("parser"); - return array_map(function ($prop) use ($parser, $self) { - return $parser($prop, $self); - }, $instance->getProperties()); - } - //else - return "any"; - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - $requiredTypes = $schema->getAttribute("type"); - settype($requiredTypes, 'array'); - - //for instances that are required to be a certain type - if ($instance->getValue() !== null && $requiredTypes && count($requiredTypes)) { - $typeValidators = $self->getValueOfProperty("typeValidators"); - if (!$typeValidators) { - $typeValidators = array(); - } - - //ensure that type matches for at least one of the required types - for ($x = 0, $xl = count($requiredTypes); $x < $xl; ++$x) { - $type = $requiredTypes[$x]; - if ($type instanceof JSONSchema) { - $subreport = clone $report; - if (!count($type->validate($instance, $subreport, $parent, $parentSchema, $name)->errors)) { - return true; //instance matches this schema - } - } else { - if (is_string($type) && isset($typeValidators[$type]) && is_callable($typeValidators[$type])) { - if ($typeValidators[$type]($instance, $report)) { - return true; //type is valid - } - } else { - return true; //unknown types are assumed valid - } - } - } - - //if we get to this point, type is invalid - $report->addError($instance, $schema, "type", "Instance is not a required type", $requiredTypes); - return false; - } - //else, anything is allowed if no type is specified - return true; - }, - - "typeValidators" => $this->TYPE_VALIDATORS - ), // type - - "properties" => array( - "type" => "object", - "additionalProperties" => array('$ref' => "#"), - "optional" => true, - "default" => array(), - - "parser" => function ($instance, $self, $arg = null) { - $env = $instance->getEnvironment(); - $selfEnv = $self->getEnvironment(); - if (is_json_object($instance->getValue())) { - if ($arg) { - return $env->createSchema($instance->getProperty($arg), $selfEnv->findSchema($self->resolveURI("#"))); - } else { - $sch = $selfEnv->findSchema($self->resolveURI("#")); - return array_map(function ($instance) use ($sch, $env) { - return $env->createSchema($instance, $sch); - }, $instance->getProperties()); - } - } - //else - return array(); - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - //this attribute is for object type instances only - if (is_json_object($instance->getValue())) { - //for each property defined in the schema - $propertySchemas = $schema->getAttribute("properties"); - foreach ($propertySchemas as $key => $val) { - if ($val) { - //ensure that instance property is valid - $val->validate($instance->getProperty($key), $report, $instance, $schema, $key); - } - } - } - } - ), - - "items" => array( - "type" => array(array('$ref' => "#"), "array"), - "items" => array('$ref' => "#"), - "optional" => true, - "default" => array(), - - "parser" => function ($instance, $self) { - if (is_json_object($instance->getValue())) { - return $instance->getEnvironment()->createSchema($instance, $self->getEnvironment()->findSchema($self->resolveURI("#"))); - } else if (is_array($instance->getValue())) { // don't need is_json_array here because of previous if - $sch = $self->getEnvironment()->findSchema($self->resolveURI("#")); - return array_map(function ($instance) use ($sch){ - return $instance->getEnvironment()->createSchema($instance, $sch); - }, $instance->getProperties()); - } - //else - return $instance->getEnvironment()->createEmptySchema(); - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - - if (is_json_array($instance->getValue())) { - $properties = $instance->getProperties(); - $items = $schema->getAttribute("items"); - $additionalProperties = $schema->getAttribute("additionalProperties"); - - if (is_array($items)) { // no need for is_json_array here, items is either 1 thing or an array of things - for ($x = 0, $xl = count($properties); $x < $xl; ++$x) { - if ($items[$x]) { - $itemSchema = $items[$x]; - } else { - $itemSchema = $additionalProperties; - } - if ($itemSchema !== false) { - $itemSchema->validate($properties[$x], $report, $instance, $schema, $x); - } else { - $report->addError($instance, $schema, "additionalProperties", "Additional items are not allowed", $itemSchema); - } - } - } else { - if ($items) { - $itemSchema = $items; - } else { - $itemSchema = $additionalProperties; - } - for ($x = 0, $xl = count($properties); $x < $xl; ++$x) { - $itemSchema->validate($properties[$x], $report, $instance, $schema, $x); - } - } - } - } - ), - - "optional" => array( - "type" => "boolean", - "optional" => true, - "default" => false, - - "parser" => function ($instance, $self) { - return (bool) $instance->getValue(); - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if ($instance->getValue() === null && !$schema->getAttribute("optional")) { - $report->addError($instance, $schema, "optional", "Property is required", false); - } - }, - - "validationRequired" => true - ), - - "additionalProperties" => array( - "type" => array(array('$ref' => "#"), "boolean"), - "optional" => true, - "default" => array(), - - "parser" => function ($instance, $self) { - if (is_json_object($instance->getValue())) { - return $instance->getEnvironment()->createSchema($instance, $self->getEnvironment()->findSchema($self->resolveURI("#"))); - } else if (is_bool($instance->getValue()) && $instance->getValue() === false) { - return false; - } - //else - return $instance->getEnvironment()->createEmptySchema(); - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - //we only need to check against object types as arrays do their own checking on this property - if (is_json_object($instance->getValue())) { - $additionalProperties = $schema->getAttribute("additionalProperties"); - $props = $schema->getAttribute("properties"); - if ($props) { - $propertySchemas = $props; - } else { - $propertySchemas = array(); - } - $properties = $instance->getProperties(); - foreach ($properties as $key => $val) { - if ($val && !isset($propertySchemas[$key])) { - if ($additionalProperties instanceof JSONSchema) { - $additionalProperties->validate($val, $report, $instance, $schema, $key); - } else if ($additionalProperties === false) { - $report->addError($instance, $schema, "additionalProperties", - "Additional properties are not allowed", $additionalProperties); - } - } - } - } - } - ), - - "requires" => array( - "type" => array("string", array('$ref' => "#")), - "optional" => true, - - "parser" => function ($instance, $self) { - if (is_string($instance->getValue())) { - return $instance->getValue(); - } else if (is_json_object($instance->getValue())) { - return $instance->getEnvironment()->createSchema($instance, $self->getEnvironment()->findSchema($self->resolveURI("#"))); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if ($instance->getValue() !== null && $parent && $parent->getValue() !== null) { - $requires = $schema->getAttribute("requires"); - if (is_string($requires)) { - if ($parent->getProperty($requires)->getValue() === null) { - $report->addError($instance, $schema, "requires", 'Property requires sibling property "' . $requires . '"', - $requires); - } - } else if ($requires instanceof JSONSchema) { - $requires->validate($parent, $report); //WATCH: A "requires" schema does not support the "requires" attribute - } - } - } - ), - - "minimum" => array( - "type" => "number", - "optional" => true, - - "parser" => function ($instance, $self) { - if (is_numeric($instance->getValue())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_numeric($instance->getValue())) { - $minimum = $schema->getAttribute("minimum"); - $minimumCanEqual = $schema->getAttribute("minimumCanEqual"); - if (is_numeric($minimum) && ($instance->getValue() < $minimum || - ($minimumCanEqual === false && $instance->getValue() === $minimum))) { - $report->addError($instance, $schema, "minimum", "Number is less then the required minimum value", $minimum); - } - } - } - ), - - "maximum" => array( - "type" => "number", - "optional" => true, - - "parser" => function ($instance, $self) { - if (is_numeric($instance->getValue())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_numeric($instance->getValue())) { - $maximum = $schema->getAttribute("maximum"); - $maximumCanEqual = $schema->getAttribute("maximumCanEqual"); - if (is_numeric($maximum) && ($instance->getValue() > $maximum || - ($maximumCanEqual === false && $instance->getValue() === $maximum))) { - $report->addError($instance, $schema, "maximum", "Number is greater then the required maximum value", $maximum); - } - } - } - ), - - "minimumCanEqual" => array( - "type" => "boolean", - "optional" => true, - "requires" => "minimum", - "default" => true, - - "parser" => function ($instance, $self) { - if (is_bool($instance->getValue())) { - return $instance->getValue(); - } - //else - return true; - } - ), - - "maximumCanEqual" => array( - "type" => "boolean", - "optional" => true, - "requires" => "maximum", - "default" => true, - - "parser" => function ($instance, $self) { - if (is_bool($instance->getValue())) { - return $instance->getValue(); - } - //else - return true; - } - ), - - "minItems" => array( - "type" => "integer", - "optional" => true, - "minimum" => 0, - "default" => 0, - - "parser" => function ($instance, $self) { - if (is_numeric($instance->getValue())) { - return $instance->getValue(); - } - //else - return 0; - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_json_array($instance->getValue())) { - $minItems = $schema->getAttribute("minItems"); - if (is_numeric($minItems) && count($instance->getProperties()) < $minItems) { - $report->addError($instance, $schema, "minItems", "The number of items is less then the required minimum", $minItems); - } - } - } - ), - - "maxItems" => array( - "type" => "integer", - "optional" => true, - "minimum" => 0, - - "parser" => function ($instance, $self) { - if (is_numeric($instance->getValue())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_json_array($instance->getValue())) { - $maxItems = $schema->getAttribute("maxItems"); - if (is_numeric($maxItems) && count($instance->getProperties()) > $maxItems) { - $report->addError($instance, $schema, "maxItems", "The number of items is greater then the required maximum", $maxItems); - } - } - } - ), - - "pattern" => array( - "type" => "string", - "optional" => true, - "format" => "regex", - - "parser" => function ($instance, $self) { - if (is_string($instance->getValue())) { - if (false === @preg_match($instance->getValue(), '')) { - return new Exception('Bad regex ' . $instance->getValue()); - } - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - $pattern = $schema->getAttribute("pattern"); - if ($pattern instanceof Exception) { - $report->addError($instance, $schema, "pattern", "Invalid pattern", $pattern); - } elseif (is_string($instance->getValue()) && $pattern && !preg_match('/' . $pattern . '/', $instance->getValue())) { - $report->addError($instance, $schema, "pattern", "String does not match pattern", $pattern); - } - } - ), - - "minLength" => array( - "type" => "integer", - "optional" => true, - "minimum" => 0, - "default" => 0, - - "parser" => function ($instance, $self) { - if (is_numeric($instance->getValue())) { - return $instance->getValue(); - } - //else - return 0; - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_string($instance->getValue())) { - $minLength = $schema->getAttribute("minLength"); - if (is_numeric($minLength) && strlen($instance->getValue()) < $minLength) { - $report->addError($instance, $schema, "minLength", "String is less then the required minimum length", $minLength); - } - } - } - ), - - "maxLength" => array( - "type" => "integer", - "optional" => true, - - "parser" => function ($instance, $self) { - if (is_numeric($instance->getType())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_string($instance->getValue())) { - $maxLength = $schema->getAttribute("maxLength"); - if (is_numeric($maxLength) && strlen($instance->getValue()) > $maxLength) { - $report->addError($instance, $schema, "maxLength", "String is greater then the required maximum length", $maxLength); - } - } - } - ), - - "enum" => array( - "type" => "array", - "optional" => true, - "minItems" => 1, - "uniqueItems" => true, - - "parser" => function ($instance, $self) { - if (is_json_array($instance->getValue())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (null !== $instance->getValue()) { - $enums = $schema->getAttribute("enum"); - if ($enums) { - for ($x = 0, $xl = count($enums); $x < $xl; ++$x) { - if ($instance->equals($enums[$x])) { - return true; - } - } - $report->addError($instance, $schema, "enum", "Instance is not one of the possible values", $enums); - } - } - } - ), - - "title" => array( - "type" => "string", - "optional" => true - ), - - "description" => array( - "type" => "string", - "optional" => true - ), - - "format" => array( - "type" => "string", - "optional" => true, - - "parser" => function ($instance, $self) { - if (is_string($instance->getValue())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_string($instance->getValue())) { - $format = $schema->getAttribute("format"); - $formatValidators = $self->getValueOfProperty("formatValidators"); - if (is_string($format) && - is_callable($formatValidators[$format]) && !$formatValidators[$format]($instance, $report)) { - $report->addError($instance, $schema, "format", "String is not in the required format", $format); - } - } - }, - - "formatValidators" => array() - ), - - "contentEncoding" => array( - "type" => "string", - "optional" => true - ), - - "default" => array( - "type" => "any", - "optional" => true - ), - - "maxDecimal" => array( - "type" => "integer", - "optional" => true, - "minimum" => 0, - - "parser" => function ($instance, $self) { - if (is_numeric($instance->getValue())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_int($instance->getValue())) { - $maxDecimal = $schema->getAttribute("maxDecimal"); - if (is_numeric($maxDecimal)) { - $decimals = explode('.', ($instance->getValue() + 0) . ''); - if (count($decimals) > 1) { - $decimals = strlen($decimals[1]); - if ($decimals > $maxDecimal) { - $report->addError($instance, $schema, "maxDecimal", - "The number of decimal places is greater then the allowed maximum", $maxDecimal); - } - } - } - } - } - ), - - "disallow" => array( - "type" => array("string", "array"), - "items" => array("type" => "string"), - "optional" => true, - "uniqueItems" => true, - - "parser" => function ($instance, $self) { - if (is_string($instance->getValue()) || is_json_array($instance->getType())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - $disallowedTypes = $schema->getAttribute("disallow"); - settype($disallowedTypes, 'array'); - - //for instances that are required to be a certain type - if (null !== $instance->getValue() && $disallowedTypes && count($disallowedTypes)) { - if ($self->getValueOfProperty("typeValidators")) { - $typeValidators = $self->getValueOfProperty("typeValidators"); - } else { - $typeValidators = array(); - } - - //ensure that type matches for at least one of the required types - for ($x = 0, $xl = count($disallowedTypes); $x < $xl; ++$x) { - $key = $disallowedTypes[$x]; - if (is_callable($typeValidators[$key])) { - if ($typeValidators[$key]($instance, $report)) { - $report->addError($instance, $schema, "disallow", "Instance is a disallowed type", $disallowedTypes); - return false; - } - } - /* - else { - $report->addError($instance, $schema, "disallow", "Instance may be a disallowed type", $disallowedTypes); - return false; - } - */ - } - - //if we get to this point, type is valid - return true; - } - //else, everything is allowed if no disallowed types are specified - return true; - }, - - "typeValidators" => TYPE_VALIDATORS - ), - - "extends" => array( - "type" => array(array('$ref' => "#"), "array"), - "items" => array('$ref' => "#"), - "optional" => true, - "default" => array(), - - "parser" => function ($instance, $self) { - if (is_json_object($instance->getValue())) { - return $instance->getEnvironment()->createSchema($instance, $self->getEnvironment()->findSchema($self->resolveURI("#"))); - } else if (is_array($instance->getValue())) { // is_json_array not needed because of previous if - $sch = $self->getEnvironment()->findSchema($self->resolveURI("#")); - return array_map(function ($instance) use ($sch, $instance) { - return $instance->getEnvironment()->createSchema(instance, $sch); - }, $instance->getProperties()); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - $extensions = $schema->getAttribute("extends"); - if ($extensions) { - if ($extensions instanceof JSONSchema) { - $extensions->validate($instance, $report, $parent, $parentSchema, $name); - } else if (is_json_array($extensions)) { - for ($x = 0, $xl = count($extensions); $x < $xl; ++$x) { - $extensions[$x]->validate($instance, $report, $parent, $parentSchema, $name); - } - } - } - } - ) - ), - - "optional" => true, - "default" => array(), - "fragmentResolution" => "dot-delimited", - - "parser" => function ($instance, $self) { - if (is_json_object($instance->getValue())) { - return $instance->getEnvironment()->createSchema($instance, $self); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - $propNames = $schema->getPropertyNames(); - $attributeSchemas = $self->getAttribute("properties"); - - foreach ($attributeSchemas as $x => $val) { - if ($val->getValueOfProperty("validationRequired")) { - $propNames = JSV::pushUnique($propNames, $x); - } - } - - for ($x = 0, $xl = count($propNames); $x < $xl; ++$x) { - if (!isset($attributeSchemas[$propNames[$x]])) { - continue; - } - $validator = $attributeSchemas[$propNames[$x]]->getValueOfProperty("validator"); - if (is_callable($validator)) { - $validator($instance, $schema, $attributeSchemas[$propNames[$x]], $report, $parent, $parentSchema, $name); - } - } - }, - - "initializer" => function ($instance) { - - do { - //if there is a link to the full representation, replace instance - $link = $instance->getSchema()->getLink("full", $instance); - $sch = $instance->getEnvironment()->getSchemas(); - if ($link && $instance->getUri() !== $link && isset($sch[$link])) { - $instance = $sch[$link]; - return $instance; //retrieved schemas are guaranteed to be initialized - } - - //if there is a link to a different schema, update instance - $link = $instance->getSchema()->getLink("describedby", $instance); - if ($link && $instance->getSchema()->getUri() !== $link && isset($sch[$link])) { - $instance->setSchema($sch[$link]); - continue; //start over - } - - //extend schema - $extension = $instance->getAttribute("extends"); - if ($extension instanceof JSONSchema) { - $extended = JSV::inherits($extension, $instance, true); - - $instance = $instance->getEnvironment()->createSchema($extended, $instance->getSchema(), $instance->getUri()); - } - - break; //get out of the loop - } while (true); - - //if instance has a URI link to itself, update it's own URI - $link = $instance->getSchema()->getLink("self", $instance); - if ($link) { - $instance->setUri($link); - } - - return $instance; - } - ); - } - - function initializeSchema($uri = "http://json-schema.org/schema#") - { - $this->SCHEMA = $this->ENVIRONMENT->createSchema($this->getSchemaArray(), true, $uri); - } - - protected function getHyperSchemaArray() - { - return array( - '$schema' => "http://json-schema.org/hyper-schema#", - "id" => "http://json-schema.org/hyper-schema#", - - "properties" => array( - "links" => array( - "type" => "array", - "items" => array('$ref' => "links#"), - "optional" => true, - - "parser" => function ($instance, $self, $arg = null) { - $linkSchemaURI = $self->getValueOfProperty("items"); - $linkSchemaURI = $linkSchemaURI['$ref']; - $linkSchema = $self->getEnvironment()->findSchema($linkSchemaURI); - $linkParser = $linkSchema ? $linkSchema->getValueOfProperty("parser") : null; - settype($arg, 'array'); - $arg = array_values($arg); - - if (is_callable($linkParser)) { - $links = array_map(function ($link) use ($linkParser) { - return $linkParser($link, $linkSchema); - }, $instance->getProperties()); - } else { - $links = $instance->getValue(); - settype($links, 'array'); - $links = array_values($links); - } - - if (isset($arg[0])) { - $links = array_values(array_filter($links, function ($link) use ($arg) { - return $link["rel"] === $arg[0]; - })); - } - - if (isset($arg[1])) { - $links = array_map(function ($link) use ($arg) { - $value = null; - $instance = $arg[1]; - $href = $link["href"]; - $href = preg_replace_callback('/\{(.+)\}/', function ($matches) use ($instance) { - $p1 = $matches[1]; - if ($p1 === "-this") { - $value = $instance->getValue(); - } else { - $value = $instance->getValueOfProperty($p1); - } - return $value !== null ? $value . '' : ""; - }, $href); - return $href ? JSV::formatURI($instance->resolveURI($href)) : $href; - }, $links); - } - - return $links; - } - ), - - "fragmentResolution" => array( - "type" => "string", - "optional" => true, - "default" => "dot-delimited" - ), - - "root" => array( - "type" => "boolean", - "optional" => true, - "default" => false - ), - - "readonly" => array( - "type" => "boolean", - "optional" => true, - "default" => false - ), - - "pathStart" => array( - "type" => "string", - "optional" => true, - "format" => "uri", - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (null !== $instance->getValue()) { - $pathStart = $schema->getAttribute("pathStart"); - if (is_string($pathStart)) { - //TODO: Find out what pathStart is relative to - if ($instance->getURI()->indexOf($pathStart) !== 0) { - $report->addError($instance, $schema, "pathStart", "Instance's URI does not start with " . $pathStart, $pathStart); - } - } - } - } - ), - - "mediaType" => array( - "type" => "string", - "optional" => true, - "format" => "media-type" - ), - - "alternate" => array( - "type" => "array", - "items" => array('$ref' => "#"), - "optional" => true - ) - ), - - "links" => array( - array( - "href" => '{$ref}', - "rel" => "full" - ), - - array( - "href" => '{$schema}', - "rel" => "describedby" - ), - - array( - "href" => "{id}", - "rel" => "self" - ) - )//, - - //not needed as JSV->inherits does the job for us - //"extends" => array('$ref' => "http://json-schema.org/schema#"} - ); - } - - function initializeHyperSchema($uri1 = '', $uri2 = "http://json-schema.org/hyper-schema#") - { - $this->HYPERSCHEMA = $this->ENVIRONMENT->createSchema(JSV::inherits($this->SCHEMA, - $this->ENVIRONMENT->createSchema($this->getHyperSchemaArray(), - $this->SCHEMA, $uri1), true), true, - $uri2); - - $this->ENVIRONMENT->setOption("defaultSchemaURI", $uri2); - } - - function getLinksArray() - { - return array( - '$schema' => "http://json-schema.org/hyper-schema#", - "id" => "http://json-schema.org/links#", - "type" => "object", - - "properties" => array( - "href" => array( - "type" => "string" - ), - - "rel" => array( - "type" => "string" - ), - - "method" => array( - "type" => "string", - "default" => "GET", - "optional" => true - ), - - "enctype" => array( - "type" => "string", - "requires" => "method", - "optional" => true - ), - - "properties" => array( - "type" => "object", - "additionalProperties" => array('$ref' => "hyper-schema#"), - "optional" => true, - - "parser" => function ($instance, $self, $arg = null) { - $env = $instance->getEnvironment(); - $selfEnv = $self->getEnvironment(); - $additionalPropertiesSchemaURI = $self->getValueOfProperty("additionalProperties"); - $additionalPropertiesSchemaURI = $additionalPropertiesSchemaURI['$ref']; - if (is_json_object($instance->getValue())) { - if ($arg) { - return $env->createSchema($instance->getProperty($arg), - $selfEnv->findSchema($self->resolveURI($additionalPropertiesSchemaURI))); - } else { - $sch = $selfEnv->findSchema($self->resolveURI($additionalPropertiesSchemaURI)); - return array_map(function ($instance) use ($env, $sch) { - return $env->createSchema($instance, $sch); - }, $instance->getProperties()); - } - } - } - ) - ), - - "parser" => function ($instance, $self) { - $selfProperties = $self->getProperty("properties"); - if (is_json_object($instance)) { - $props = $instance->getProperties(); - array_walk($props, function (&$property, $key) use ($selfProperties) { - $propertySchema = $selfProperties->getProperty($key); - $parser = $propertySchema ? $propertySchema->getValueOfProperty("parser") : null; - if (is_callable($parser)) { - $property = $parser($property, $propertySchema); - } - //else - $property = $property->getValue(); - }); - return $props; - } - return $instance->getValue(); - } - ); - } - function initializeLinks($uri = "http://json-schema.org/links#") - { - $this->LINKS = $this->ENVIRONMENT->createSchema($this->getLinksArray(), HYPERSCHEMA, $uri); - } - - /** - * if the search path key is the same as newkey, we will instead replace the schema item - * if $before is set to the string "replace" we will remove the old key and replace it with the new one - */ - function insert($schema, $path, $newkey, $newvalue, $before = true, $origpath = '') - { - if (!$origpath) { - $origpath = $path; - } - if (strpos($path, '/')) { - // still have to traverse deeper in the tree - $path = explode('/', $path); - $marker = array_shift($path); - $path = implode('/', $path); - $newschema = array(); - $found = false; - foreach ($schema as $key => $value) { - if ($key == $marker) { - $found = true; - $newschema[$key] = $this->insert($value, $path, $newkey, $newvalue, $before, $origpath); - continue; - } - $newschema[$key] = $value; - } - if (!$found) { - throw new Exception('Error: path key ' . $marker . ' was not found in ' . $path . ' component of ' . $origpath); - } - return $newschema; - } - // this is where we will insert - $newschema = array(); - foreach ($schema as $key => $value) { - if ($key != $path) { - $newschema[$key] = $value; - continue; - } - $found = true; - if ($key == $newkey || $before === 'replace') { - $newschema[$newkey] = $newvalue; - continue; - } - if ($before) { - $newschema[$newkey] = $newvalue; - $newschema[$key] = $value; - } else { - $newschema[$key] = $value; - $newschema[$newkey] = $newvalue; - } - } - if (!$found) { - throw new Exception('Error: path key ' . $path . ' was not found in ' . $path . ' component of ' . $origpath); - } - return $newschema; - } -} \ No newline at end of file diff --git a/lib/JsonSchemaDraft01For03.php b/lib/JsonSchemaDraft01For03.php deleted file mode 100644 index 56fedc5..0000000 --- a/lib/JsonSchemaDraft01For03.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @author Gregory Beaver - * @version 1.5 - * @see http://github.com/garycourt/JSV - */ -namespace JsonSchema; - -/* - * Copyright 2010 Gary Court. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of Gary Court or the JSON Schema specification. - */ - -/*jslint white: true, sub: true, onevar: true, undef: true, eqeqeq: true, newcap: true, immed: true, indent: 4 */ -/*global require */ - -class JsonSchemaDraft01For03 extends JsonSchemaDraft01 -{ - function initializeSchema($uri = "http://json-schema.org/draft-00/schema#") - { - return parent::initializeSchema($uri); - } - - function initializeHyperSchema($uri1 = "http://json-schema.org/draft-00/hyper-schema#", $uri2 = "http://json-schema.org/draft-00/hyper-schema#") - { - return parent::initializeHyperSchema($uri1, $uri2); - } - - function initializeLinks($uri = "http://json-schema.org/draft-00/links#") - { - return parent::initializeLinks($uri); - } - - function registerSchemas() - { - //We need to reinitialize these 3 schemas as they all reference each other - $this->SCHEMA = $this->ENVIRONMENT->createSchema($this->SCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/draft-00/schema#"); - $this->HYPERSCHEMA = $this->ENVIRONMENT->createSchema($this->HYPERSCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/draft-00/hyper-schema#"); - $this->LINKS = $this->ENVIRONMENT->createSchema($this->LINKS->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/draft-00/links#"); - - // - // draft-01 - // - $SCHEMA_01_JSON = parent::getSchemaArray(); - $SCHEMA_01_JSON['$schema'] = "http://json-schema.org/draft-01/hyper-schema#"; - $SCHEMA_01_JSON['id'] = "http://json-schema.org/draft-01/schema#"; - - $HYPERSCHEMA_01_JSON = parent::getHyperSchemaArray(); - $HYPERSCHEMA_01_JSON['$schema'] = "http://json-schema.org/draft-01/hyper-schema#"; - $HYPERSCHEMA_01_JSON['id'] = "http://json-schema.org/draft-01/hyper-schema#"; - - $LINKS_01_JSON = parent::getLinksArray(); - $LINKS_01_JSON['$schema'] = "http://json-schema.org/draft-00/hyper-schema#"; - $LINKS_01_JSON['id'] = "http://json-schema.org/draft-00/links#"; - - $this->ENVIRONMENT->setOption("defaultSchemaURI", "http://json-schema.org/draft-01/schema#"); //update later - - $this->SCHEMA = $this->ENVIRONMENT->createSchema($SCHEMA_01_JSON, true, "http://json-schema.org/draft-01/schema#"); - $this->HYPERSCHEMA = $this->ENVIRONMENT->createSchema(JSV::inherits($this->SCHEMA, - $this->ENVIRONMENT->createSchema($HYPERSCHEMA_01_JSON, - true, - "http://json-schema.org/draft-01/hyper-schema#"), - true), true, "http://json-schema.org/draft-01/hyper-schema#"); - - $this->ENVIRONMENT->setOption("defaultSchemaURI", "http://json-schema.org/draft-01/hyper-schema#"); - - $this->LINKS = $this->ENVIRONMENT->createSchema($LINKS_01_JSON, $this->HYPERSCHEMA, "http://json-schema.org/draft-01/links#"); - - //We need to reinitialize these 3 schemas as they all reference each other - $this->SCHEMA = $this->ENVIRONMENT->createSchema($this->SCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/draft-01/schema#"); - $this->HYPERSCHEMA = $this->ENVIRONMENT->createSchema($this->HYPERSCHEMA->getValue(), $this->HYPERSCHEMA, - "http://json-schema.org/draft-01/hyper-schema#"); - $this->LINKS = $this->ENVIRONMENT->createSchema($this->LINKS->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/draft-01/links#"); - } - - function getSchemaArray() - { - $schema = parent::getSchemaArray(); - $schema['$schema'] = "http://json-schema.org/draft-00/hyper-schema#"; - $schema['id'] = "http://json-schema.org/draft-00/schema#"; - return $schema; - } - - function getHyperSchemaArray() - { - $schema = parent::getHyperSchemaArray(); - $schema['$schema'] = "http://json-schema.org/draft-00/hyper-schema#"; - $schema['id'] = "http://json-schema.org/draft-00/hyper-schema#"; - } - - function getLinksArray() - { - $schema = parent::getLinksArray(); - $schema['$schema'] = "http://json-schema.org/draft-00/hyper-schema#"; - $schema['id'] = "http://json-schema.org/draft-00/links#"; - return $schema; - } -} \ No newline at end of file diff --git a/lib/JsonSchemaDraft02.php b/lib/JsonSchemaDraft02.php deleted file mode 100644 index 406dd27..0000000 --- a/lib/JsonSchemaDraft02.php +++ /dev/null @@ -1,137 +0,0 @@ - - * @author Gregory Beaver - * @version 1.5 - * @see http://github.com/garycourt/JSV - */ -namespace JsonSchema; - -/* - * Copyright 2010 Gary Court. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of Gary Court or the JSON Schema specification. - */ - -/*jslint white: true, sub: true, onevar: true, undef: true, eqeqeq: true, newcap: true, immed: true, indent: 4 */ -/*global require */ - -class JsonSchemaDraft02 extends JsonSchemaDraft01 -{ - function registerSchemas() - { - $this->SCHEMA = $this->ENVIRONMENT->createSchema($this->SCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/schema#"); - $this->HYPERSCHEMA = $this->ENVIRONMENT->createSchema($this->HYPERSCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/hyper-schema#"); - $this->LINKS = $this->ENVIRONMENT->createSchema($this->LINKS->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/links#"); - - JSV::registerEnvironment("json-schema-draft-02", $this->ENVIRONMENT); - - if (!JSV::getDefaultEnvironmentID() || JSV::getDefaultEnvironmentID() === "json-schema-draft-01") { - JSV::setDefaultEnvironmentID("json-schema-draft-02"); - } - } - - function initializeEnvironment() - { - $this->ENVIRONMENT = new Environment(); - $this->ENVIRONMENT->setOption("defaultFragmentDelimiter", "/"); - $this->ENVIRONMENT->setOption("defaultSchemaURI", "http://json-schema.org/schema#"); //updated later - } - - function getSchemaArray() - { - $schema = parent::getSchemaArray(); - $schema = $this->insert($schema, 'properties/pattern', 'uniqueItems', array( - "type" => "boolean", - "optional" => true, - "default" => false, - - "parser" => function ($instance, $self) { - return (bool) $instance->getValue(); - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_json_array($instance->getValue()) && $schema->getAttribute("uniqueItems")) { - $value = $instance->getProperties(); - for ($x = 0, $xl = count($value) - 1; $x < $xl; ++$x) { - for ($y = $x + 1, $yl = count($value); $y < $yl; ++$y) { - if ($value[$x]->equals($value[$y])) { - $report->addError($instance, $schema, "uniqueItems", "Array can only contain unique items", - array('x' => $x, 'y' => $y)); - } - } - } - } - } - )); - $schema = $this->insert($schema, 'properties/maxDecimal', 'divisibleBy', array( - "type" => "number", // was integer - "minimum" => 0, - - "minimumCanEqual" => false, // new constraint - "optional" => true, - - "parser" => function ($instance, $self) { - if (is_numeric($instance->getValue())) { - return $instance->getValue(); - } - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_numeric($instance->getValue())) { - $divisor = $schema->getAttribute("divisibleBy"); - if ($divisor === 0) { - $report->addError($instance, $schema, "divisibleBy", "Nothing is divisible by 0", $divisor); - } elseif (floor($instance->getValue() / $divisor) != $instance->getValue() / $divisor) { - $report->addError($instance, $schema, "divisibleBy", "Number is not divisible by " . $divisor, $divisor); - } - } - } - ), 'replace'); - $schema['fragmentResolution'] = 'slash-delimited'; - return $schema; - } - - function getHyperSchemaArray() - { - $schema = parent::getHyperSchemaArray(); - $schema['properties']['fragmentResolution']['default'] = 'slash-delimited'; // was dot-delimited - } - - function getLinksArray() - { - $schema = parent::getLinksArray(); - $schema = $this->insert($schema, 'properties/method', 'targetSchema', array( - '$ref' => "hyper-schema#", - - //need this here because parsers are run before links are resolved - "parser" => $this->HYPERSCHEMA->getAttribute("parser") - )); - return $schema; - } -} \ No newline at end of file diff --git a/lib/JsonSchemaDraft02For03.php b/lib/JsonSchemaDraft02For03.php deleted file mode 100644 index a976264..0000000 --- a/lib/JsonSchemaDraft02For03.php +++ /dev/null @@ -1,95 +0,0 @@ - - * @author Gregory Beaver - * @version 1.5 - * @see http://github.com/garycourt/JSV - */ -namespace JsonSchema; - -/* - * Copyright 2010 Gary Court. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of Gary Court or the JSON Schema specification. - */ - -/*jslint white: true, sub: true, onevar: true, undef: true, eqeqeq: true, newcap: true, immed: true, indent: 4 */ -/*global require */ - -class JsonSchemaDraft02For03 extends JsonSchemaDraft02 -{ - function initializeSchema($uri = "http://json-schema.org/draft-02/schema#") - { - return parent::initializeSchema($uri); - } - - function initializeHyperSchema($uri1 = "http://json-schema.org/draft-02/hyper-schema#", $uri2 = "http://json-schema.org/draft-02/hyper-schema#") - { - return parent::initializeHyperSchema($uri1, $uri2); - } - - function initializeLinks($uri = "http://json-schema.org/draft-02/links#") - { - return parent::initializeLinks($uri); - } - - function registerSchemas() - { - //We need to reinitialize these 3 schemas as they all reference each other - $this->SCHEMA = $this->ENVIRONMENT->createSchema($this->SCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/draft-02/schema#"); - $this->HYPERSCHEMA = $this->ENVIRONMENT->createSchema($this->HYPERSCHEMA->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/draft-02/hyper-schema#"); - $this->LINKS = $this->ENVIRONMENT->createSchema($this->LINKS->getValue(), $this->HYPERSCHEMA, "http://json-schema.org/draft-02/links#"); - } - - - function getSchemaArray() - { - $schema = parent::getSchemaArray(); - $schema['$schema'] = "http://json-schema.org/draft-02/hyper-schema#"; - $schema['id'] = "http://json-schema.org/draft-02/schema#"; - $this->insert($schema, 'properties/divisibleBy', 'maxDecimal', array( - 'deprecated' => true - )); - return $schema; - } - - function getHyperSchemaArray() - { - $schema = parent::getHyperSchemaArray(); - $schema['$schema'] = "http://json-schema.org/draft-02/hyper-schema#"; - $schema['id'] = "http://json-schema.org/draft-02/hyper-schema#"; - } - - function getLinksArray() - { - $schema = parent::getLinksArray(); - $schema['$schema'] = "http://json-schema.org/draft-02/hyper-schema#"; - $schema['id'] = "http://json-schema.org/draft-02/links#"; - return $schema; - } -} \ No newline at end of file diff --git a/lib/JsonSchemaDraft03.php b/lib/JsonSchemaDraft03.php deleted file mode 100644 index 9b927cd..0000000 --- a/lib/JsonSchemaDraft03.php +++ /dev/null @@ -1,511 +0,0 @@ - - * @author Gregory Beaver - * @version 1.5 - * @see http://github.com/garycourt/JSV - */ -namespace JsonSchema; - -/* - * Copyright 2010 Gary Court. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of Gary Court or the JSON Schema specification. - */ - -/*jslint white: true, sub: true, onevar: true, undef: true, eqeqeq: true, newcap: true, immed: true, indent: 4 */ -/*global require */ - -class JsonSchemaDraft03 extends JsonSchemaDraft02 -{ - var - $draft1, - $draft2; - - function __construct($register = true) - { - $this->draft1 = new JsonSchemaDraft01For03(); - $this->draft2 = new JsonSchemaDraft02For03(); - - return parent::__construct($register); - } - - function initializeEnvironment() - { - $this->ENVIRONMENT = new Environment(); - $this->ENVIRONMENT->setOption("validateReferences", true); - $this->ENVIRONMENT->setOption("defaultSchemaURI", "http://json-schema.org/draft-03/schema#"); //update later - - //prevent reference errors - $this->ENVIRONMENT->createSchema(array(), true, "http://json-schema.org/draft-03/schema#"); - $this->ENVIRONMENT->createSchema(array(), true, "http://json-schema.org/draft-03/hyper-schema#"); - $this->ENVIRONMENT->createSchema(array(), true, "http://json-schema.org/draft-03/links#"); - } - - function initializeSchema($uri = "http://json-schema.org/draft-03/schema#") - { - return parent::initializeSchema($uri); - } - - function initializeHyperSchema($uri1 = "http://json-schema.org/draft-03/hyper-schema#", $uri2 = "http://json-schema.org/draft-03/hyper-schema#") - { - return parent::initializeHyperSchema($uri1, $uri2); - } - - function initializeLinks($uri = "http://json-schema.org/draft-03/links#") - { - return parent::initializeLinks($uri); - } - - function registerSchemas() - { - //We need to reinitialize these schemas as they reference each other - $this->HYPERSCHEMA = $this->ENVIRONMENT->createSchema($this->HYPERSCHEMA->getValue(), $this->HYPERSCHEMA, - "http://json-schema.org/draft-03/hyper-schema#"); - - $this->ENVIRONMENT->setOption("latestJSONSchemaSchemaURI", "http://json-schema.org/draft-03/schema#"); - $this->ENVIRONMENT->setOption("latestJSONSchemaHyperSchemaURI", "http://json-schema.org/draft-03/hyper-schema#"); - $this->ENVIRONMENT->setOption("latestJSONSchemaLinksURI", "http://json-schema.org/draft-03/links#"); - - // - //Latest JSON Schema - // - - //Hack, but WAY faster then instantiating a new schema - $this->ENVIRONMENT->replaceSchema("http://json-schema.org/schema#", $this->SCHEMA); - $this->ENVIRONMENT->replaceSchema("http://json-schema.org/hyper-schema#", $this->HYPERSCHEMA); - $this->ENVIRONMENT->replaceSchema("http://json-schema.org/links#", $this->LINKS); - - // - //register environment - // - - JSV::registerEnvironment("json-schema-draft-03", $this->ENVIRONMENT); - if (!JSV::getDefaultEnvironmentID() || JSV::getDefaultEnvironmentID() === "json-schema-draft-01" - || JSV::getDefaultEnvironmentID() === "json-schema-draft-02") { - JSV::setDefaultEnvironmentID("json-schema-draft-03"); - } - } - - function getSchemaArray() - { - $SCHEMA_02_JSON = $this->draft2->getSchemaArray(); - $disallowparser = $SCHEMA_02_JSON["properties"]["type"]["parser"]; - $propertiesparser = $SCHEMA_02_JSON["properties"]["properties"]["parser"]; - $additionalparser = $SCHEMA_02_JSON["properties"]["additionalProperties"]["parser"]; - return JSV::inherits($SCHEMA_02_JSON, array( - '$schema' => "http://json-schema.org/draft-03/schema#", - "id" => "http://json-schema.org/draft-03/schema#", - - "properties" => array( - "patternProperties" => array( - "type" => "object", - "additionalProperties" => array('$ref' => "#"), - "default" => array(), - - "parser" => $propertiesparser, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_json_object($instance->getValue())) { - $matchedProperties = JSV::getMatchedPatternProperties($instance, $schema, $report, $self); - foreach ($matchedProperties as $key => $val) { - $x = count($val); - while ($x--) { - $val[$x]->validate($instance->getProperty($key), $report, $instance, $schema, $key); - } - } - } - } - ), - - "additionalProperties" => array( - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_json_object($instance->getValue())) { - $additionalProperties = $schema->getAttribute("additionalProperties"); - $propertySchemas = $schema->getAttribute("properties"); - if (!$propertySchemas) { - $propertySchemas = array(); - } - $properties = $instance->getProperties(); - $matchedProperties = JSV::getMatchedPatternProperties($instance, $schema); - foreach ($properties as $key => $val) { - if ($val && !isset($propertySchemas[$key]) && !isset($matchedProperties[$key])) { - if ($additionalProperties instanceof JSONSchema) { - $additionalProperties->validate($val, $report, $instance, $schema, $key); - } else if ($additionalProperties === false) { - $report->addError($instance, $schema, "additionalProperties", - "Additional properties are not allowed", $additionalProperties); - } - } - } - } - } - ), - - "items" => array( - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_json_array($instance->getValue())) { - $properties = $instance->getProperties(); - $items = $schema->getAttribute("items"); - $additionalItems = $schema->getAttribute("additionalItems"); - - if (is_array($items)) { - for ($x = 0, $xl = count($properties); $x < $xl; ++$x) { - if (isset($items[$x])) { - $itemSchema = $items[$x]; - } else { - $itemSchema = $additionalItems; - } - if (is_callabel($itemSchema) && is_object($itemSchema)) { - $itemSchema->validate($properties[$x], $report, $instance, $schema, $x); - } else { - $report->addError($instance, $schema, "additionalItems", "Additional items are not allowed", $itemSchema); - } - } - } else { - if ($items) { - $itemSchema = $items; - } else { - $itemSchema = $additionalItems; - } - for ($x = 0, $xl = $properties->length(); $x < $xl; ++$x) { - $itemSchema->validate($properties[$x], $report, $instance, $schema, $x); - } - } - } - } - ), - - "additionalItems" => array( - "type" => array(array('$ref' => "#"), "boolean"), - "default" => array(), - - "parser" => $additionalparser, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - //only validate if the "items" attribute is undefined - if (is_json_array($instance->getValue()) && null === $schema->getProperty("items")) { - $additionalItems = $schema->getAttribute("additionalItems"); - $properties = $instance->getProperties(); - - if ($additionalItems !== false) { - for ($x = 0, $xl = count($properties); $x < $xl; ++$x) { - $additionalItems->validate($properties[$x], $report, $instance, $schema, $x); - } - } else if (count($properties)) { - $report->addError($instance, $schema, "additionalItems", "Additional items are not allowed", $additionalItems); - } - } - } - ), - - "optional" => array( - "validationRequired" => false, - "deprecated" => true - ), - - "required" => array( - "type" => "boolean", - "default" => false, - - "parser" => function ($instance, $self) { - return (bool) $instance->getValue(); - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (null === $instance->getValue() && $schema->getAttribute("required")) { - $report->addError($instance, $schema, "required", "Property is required", true); - } - } - ), - - "requires" => array( - "deprecated" => true - ), - - "dependencies" => array( - "type" => "object", - "additionalProperties" => array( - "type" => array("string", "array", array('$ref' => "#")), - "items" => array( - "type" => "string" - ) - ), - "default" => array(), - - "parser" => function ($instance, $self, $arg = null) { - $parseProperty = function(JSONInstance $property) { - if (is_string($property->getValue()) || is_json_array($property->getValue())) { - return $property->getValue(); - } else if (is_json_object($property->getValue())) { - return $property->getEnvironment()->createSchema($property, $self->getEnvironment() - ->findSchema($self->resolveURI("#"))); - } - }; - - if (is_json_object($instance->getValue())) { - if ($arg) { - return $parseProperty($instance->getProperty($arg)); - } else { - return array_map($parseProperty, $instance->getProperties()); - } - } - //else - return array(); - }, - - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_json_object($instance->getValue())) { - $dependencies = $schema->getAttribute("dependencies"); - foreach ($dependencies as $key => $dependency) { - if ($instance->getProperty($key) !== null) { - if (is_string($dependency)) { - if ($instance->getProperty($dependency) === null) { - $report->addError($instance, $schema, "dependencies", 'Property "' . $key . - '" requires sibling property "' . $dependency . '"', $dependencies); - } - } else if (is_json_array($dependency)) { - for ($x = 0, $xl = count($dependency); $x < $xl; ++$x) { - if ($instance->getProperty($dependency[$x]) === null) { - $report->addError($instance, $schema, "dependencies", 'Property "' . - $key . '" requires sibling property "' . $dependency[$x] . '"', $dependencies); - } - } - } else if ($dependency instanceof JSONSchema) { - $dependency->validate($instance, $report); - } - } - } - } - } - ), - - "minimumCanEqual" => array( - "deprecated" => true - ), - - "maximumCanEqual" => array( - "deprecated" => true - ), - - "exclusiveMinimum" => array( - "type" => "boolean", - "default" => false, - - "parser" => function ($instance, $self) { - return (bool) $instance->getValue(); - } - ), - - "exclusiveMaximum" => array( - "type" => "boolean", - "default" => false, - - "parser" => function ($instance, $self) { - return (bool) $instance->getValue(); - } - ), - - "minimum" => array( - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_numeric($instance->getValue())) { - $minimum = $schema->getAttribute("minimum"); - $exclusiveMinimum = $schema->getAttribute("exclusiveMinimum"); - if (!$exclusiveMinimum) { - $exclusiveMinimum = (!$instance->getEnvironment()->getOption("strict") && !$schema->getAttribute("minimumCanEqual")); - } - if (is_numeric($minimum) && ($instance->getValue() < $minimum || - ($exclusiveMinimum === true && $instance->getValue() === $minimum))) { - $report->addError($instance, $schema, "minimum", "Number is less than the required minimum value", $minimum); - } - } - } - ), - - "maximum" => array( - "validator" => function ($instance, $schema, $self, $report, $parent, $parentSchema, $name) { - if (is_numeric($instance->getValue())) { - $maximum = $schema->getAttribute("maximum"); - $exclusiveMaximum = $schema->getAttribute("exclusiveMaximum"); - if (!$exclusiveMaximum) { - $exclusiveMaximum = (!$instance->getEnvironment()->getOption("strict") && !$schema->getAttribute("maximumCanEqual")); - } - if (is_numeric($maximum) && ($instance->getValue() > $maximum || - ($exclusiveMaximum === true && $instance->getValue() === $maximum))) { - $report->addError($instance, $schema, "maximum", "Number is greater than the required maximum value", $maximum); - } - } - } - ), - - "contentEncoding" => array( - "deprecated" => true - ), - - "divisibleBy" => array( - "exclusiveMinimum" => true - ), - - "disallow" => array( - "items" => array( - "type" => array("string", array('$ref' => "#")) - ), - - "parser" => $disallowparser - ), - - "id" => array( - "type" => "string", - "format" => "uri" - ), - - '$ref' => array( - "type" => "string", - "format" => "uri" - ), - - '$schema' => array( - "type" => "string", - "format" => "uri" - ) - ), - - "dependencies" => array( - "exclusiveMinimum" => "minimum", - "exclusiveMaximum" => "maximum" - ), - - "initializer" => function ($instance) { - $schemaLink = $instance->getValueOfProperty('$schema'); - $refLink = $instance->getValueOfProperty('$ref'); - $idLink = $instance->getValueOfProperty('id'); - $sch = $instance->getEnvironment()->getSchemas(); - $opts = $instance->getEnvironment()->getOptions(); - - //if there is a link to a different schema, update instance - if ($schemaLink) { - $link = $instance->resolveURI($schemaLink); - if ($link && $instance->getSchema()->getUri() !== $link) { - if ($sch[$link]) { - $instance->setSchema($sch[link]); - $initializer = $instance->getSchema()->getValueOfProperty("initializer"); - if (is_callabel($initializer)) { - return $initializer($instance); //this function will finish initialization - } else { - return $instance; //no further initialization - } - } else if ($opts["validateReferences"]) { - throw new InitializationException($instance, $instance->getSchema(), '$schema', "Unknown schema reference", $link); - } - } - } - - //if there is a link to the full representation, replace instance - if ($refLink) { - $link = $instance->resolveURI($refLink); - if ($link && $instance->getUri() !== $link) { - if ($sch[$link]) { - $instance = $sch[link]; - return $instance; //retrieved schemas are guaranteed to be initialized - } else if ($opts["validateReferences"]) { - throw new InitializationException($instance, $instance->getSchema(), '$ref', "Unknown schema reference", $link); - } - } - } - - //extend schema - $extension = $instance->getAttribute("extends"); - if ($extension instanceof JSONSchema) { - $extended = JSV::inherits($extension, $instance, true); - $instance = $instance->getEnvironment()->createSchema($extended, $instance->getSchema(), $instance->getUri()); - } - - //if instance has a URI link to itself, update it's own URI - if ($idLink) { - $link = $instance->resolveURI($idLink); - if (is_string($link)) { - $instance->setUri(JSV::formatURI($link)); - } - } - - return $instance; - } - )); - } - - function getHyperSchemaArray() - { - return JSV::inherits($this->draft2->getHyperSchemaArray(), array( - '$schema' => "http://json-schema.org/draft-03/hyper-schema#", - "id" => "http://json-schema.org/draft-03/hyper-schema#", - - "properties" => array( - "links" => array( - "selfReferenceVariable" => "@" - ), - - "root" => array( - "deprecated" => true - ), - - "contentEncoding" => array( - "deprecated" => false //moved from core to hyper - ), - - "alternate" => array( - "deprecated" => true - ) - ) - )); - } - - function getLinksArray() - { - return JSV::inherits($this->draft2->getLinksArray(), array( - '$schema' => "http://json-schema.org/draft-03/hyper-schema#", - "id" => "http://json-schema.org/draft-03/links#", - - "properties" => array( - "href" => array( - "required" => true, - "format" => "link-description-object-template" - ), - - "rel" => array( - "required" => true - ), - - "properties" => array( - "deprecated" => true - ), - - "schema" => array('$ref' => "http://json-schema.org/draft-03/hyper-schema#") - ) - )); - } -} \ No newline at end of file diff --git a/lib/Jsv.php b/lib/Jsv.php deleted file mode 100644 index 7548f43..0000000 --- a/lib/Jsv.php +++ /dev/null @@ -1,1360 +0,0 @@ - $v) { - if (is_string($k)) { - return true; - } - return false; - } - return true; // empty array is same as empty object, really -} -function is_json_array($i) -{ - if (!is_array($i)) { - return false; - } - foreach ($i as $k => $v) { - if (is_string($k)) { - return false; - } - return true; - } - return true; -} -//class Exception extends \Exception {} -/** - * Defines an error, found by a schema, with an instance. - * This class can only be instantiated by {@link Report#addError}. - */ -class ValidationException extends Exception -{ - - /** - * The URI of the instance that has the error. - * - * @name ValidationError.prototype.uri - * @type String - */ - - public $uri; - - /** - * The URI of the schema that generated the error. - * - * @name ValidationError.prototype.schemaUri - * @type String - */ - - public $schemaUri; - /** - * The name of the schema attribute that generated the error. - * - * @name ValidationError.prototype.attribute - * @type String - */ - - public $attribute; - /** - * The value of the schema attribute that generated the error. - * - * @name ValidationError.prototype.details - * @type Any - */ - public $details; - - /** - * An user-friendly (English) message about what failed to validate. - * - * @name ValidationError.prototype.message - * @type String - */ -} - -/** - * Reports are returned from validation methods to describe the result of a validation. - * @see JSONSchema#validate - * @see Environment#validate - */ -class Report -{ - /** - * An array of {@link ValidationError} objects that define all the errors generated by the schema against the instance. - * - * @name Report.prototype.errors - * @type Array - * @see Report#addError - */ - protected $errors = array(); - - /** - * A hash table of every instance and what schemas were validated against it. - *

- * The key of each item in the table is the URI of the instance that was validated. - * The value of this key is an array of strings of URIs of the schema that validated it. - *

- * - * @name Report.prototype.validated - * @type Object - * @see Report#registerValidation - * @see Report#isValidatedBy - */ - protected $validated = array(); - - /** - * If the report is generated by {@link Environment#validate}, this field is the generated instance. - * - * @name Report.prototype.instance - * @type JSONInstance - * @see Environment#validate - */ - protected $instance; - - /** - * If the report is generated by {@link Environment#validate}, this field is the generated schema. - * - * @name Report.prototype.schema - * @type JSONSchema - * @see Environment#validate - */ - protected $schema; - - /** - * If the report is generated by {@link Environment#validate}, this field is the schema's schema. - * This value is the same as calling schema.getSchema(). - * - * @name Report.prototype.schemaSchema - * @type JSONSchema - * @see Environment#validate - * @see JSONSchema#getSchema - */ - protected $schemaSchema; - - private $_checkVars = array('instance' => 1, 'schema' => 1, 'schemaSchema' => 1, 'validated' => 1, 'errors' => 1); - - function __clone() - { - $this->errors = array(); - } - - function __get($var) - { - if (!isset($this->_checkVars[$var]) || $var !== 'errors') { - throw new Exception('Invalid Report variable requested: ' . $var); - } - return $this->$var; - } - - function __set($var, $val) - { - if (!isset($this->_checkVars[$var])) { - throw new Exception('Invalid Report variable requested: ' . $var); - } - $this->$var = $val; - } - - /** - * Adds a {@link ValidationException} object to the errors field. - * - * @param {JSONInstance|String} instance The instance (or instance URI) that is invalid - * @param {JSONSchema|String} schema The schema (or schema URI) that was validating the instance - * @param {String} attr The attribute that failed to validated - * @param {String} message A user-friendly message on why the schema attribute failed to validate the instance - * @param {Any} details The value of the schema attribute - */ - - function addError($instance, $schema, $attr, $message, $details = '') - { - $err = new ValidationException($message); - $err->uri = $instance instanceof JSONInstance ? $instance->getURI() : $instance; - $err->schemaUri = $schema instanceof JSONInstance ? $schema->getURI() : $schema; - $err->attribute = $attr; - $err->details = $details; - array_push($this->errors, $err); - } - - /** - * Registers that the provided instance URI has been validated by the provided schema URI. - * This is recorded in the validated field. - * - * @param {String} uri The URI of the instance that was validated - * @param {String} schemaUri The URI of the schema that validated the instance - */ - - function registerValidation($uri, $schemaUri) { - if (!isset($this->validated[$uri])) { - $this->validated[$uri] = array($schemaUri); - } else { - $this->validated[$uri][] = $schemaUri; - } - } - - /** - * Returns if an instance with the provided URI has been validated by the schema with the provided URI. - * - * @param {String} uri The URI of the instance - * @param {String} schemaUri The URI of a schema - * @returns {Boolean} If the instance has been validated by the schema. - */ - - function isValidatedBy($uri, $schemaUri) - { - return isset($this->validated[$uri]) && in_array($schemaUri, $this->validated[$uri]); - } -} - -/** - * A wrapper class for binding an Environment, URI and helper methods to an instance. - * This class is most commonly instantiated with {@link Environment#createInstance}. - * - * @name JSONInstance - */ -class JSONInstance -{ - protected $_fd; - protected $_uri; - protected $_value; - protected $_env; - - function getFd() - { - return $this->_fd; - } - - function getUri() - { - return $this->_uri; - } - - function setUri($uri) - { - $this->_uri = $uri; - } - - function getValue() - { - return $this->_value; - } - - function getEnvironment() - { - return $this->_env; - } - - /** - * @param {Environment} env The environment this instance belongs to - * @param {JSONInstance|Any} json The value of the instance - * @param {String} [uri] The URI of the instance. If undefined, the URI will be a randomly generated UUID. - * @param {String} [fd] The fragment delimiter for properties. If undefined, uses the environment default. - */ - - function __construct(Environment $env, $json, $uri, $fd = null) { - if ($json instanceof JSONInstance) { - if (!$fd) { - $fd = $json->getFd(); - } - if (!$uri) { - $uri = $json->getUri(); - } - $json = $json->getValue(); - } - - if (!$uri) { - $uri = "urn:uuid:" . JSV::randomUUID() . "#"; - } elseif (strpos($uri, ":") === -1) { - $urimanager = new URI(); - $uri = JSV::formatURI($urimanager->resolve("urn:uuid:" . JSV::randomUUID() . "#", $uri)); - } - - $this->_env = $env; - $this->_value = $json; - $this->_uri = $uri; - $this->_fd = $fd ? $fd : $this->_env->getOption("defaultFragmentDelimiter"); - } - - /** - * Returns a resolved URI of a provided relative URI against the URI of the instance. - * - * @param {String} uri The relative URI to resolve - * @returns {String} The resolved URI - */ - - function resolveURI($uri) - { - $urimanager = new URI(); - return JSV::formatURI($urimanager->resolve($this->_uri, $uri)); - } - - /** - * Returns an array of the names of all the properties. - * - * @returns {Array} An array of strings which are the names of all the properties - */ - - function getPropertyNames() - { - if ($this->_value === null) { - return array(); - } - return array_keys($this->_value); - } - - /** - * Returns a {@link JSONInstance} of the value of the provided property name. - * - * @param {String} key The name of the property to fetch - * @returns {JSONInstance} The instance of the property value - */ - - function getProperty($key) - { - $value = isset($this->_value) && is_array($this->_value) && isset($this->_value[$key]) ? $this->_value[$key] : null; - if ($value instanceof JSONInstance) { - return $value; - } - //else - return new JSONInstance($this->_env, $value, $this->_uri . $this->_fd . urlencode($key), $this->_fd); - } - - /** - * Returns all the property instances of the target instance. - *

- * If the target instance is an Object, then the method will return a hash table of {@link JSONInstance}s of all the properties. - * If the target instance is an Array, then the method will return an array of {@link JSONInstance}s of all the items. - *

- * - * @returns {Object|Array|undefined} The list of instances for all the properties - */ - - function getProperties() - { - $val = $this->_value; - if ($val === null) { - return array(); - } - $self = $this; - settype($val, 'array'); - array_walk($val, function (&$value, $key) use ($self) { - if ($value instanceof JSONInstance) { - return; - } - $value = new JSONInstance($self->getEnvironment(), $value, $self->getUri() . $self->getFd() . urlencode($key), $self->getFd()); - }); - return $val; - } - - /** - * Returns the JSON value of the provided property name. - * This method is a faster version of calling instance.getProperty(key).getValue(). - * - * @param {String} key The name of the property - * @returns {Any} The JavaScript value of the instance - * @see JSONInstance#getProperty - * @see JSONInstance#getValue - */ - - function getValueOfProperty($key) - { - if ($this->_value) { - if (!isset($this->_value[$key])) { - return null; - } - if ($this->_value[$key] instanceof JSONInstance) { - return $this->_value[$key]->getValue(); - } - return $this->_value[$key]; - } - } - - /** - * Return if the provided value is the same as the value of the instance. - * - * @param {JSONInstance|Any} instance The value to compare - * @returns {Boolean} If both the instance and the value match - */ - - function equals($instance) { - if ($instance instanceof JSONInstance) { - return $this->_value === $instance->getValue(); - } - //else - return $this->_value === $instance; - } -} - - /** - * This class binds a {@link JSONInstance} with a {@link JSONSchema} to provided context aware methods. - */ -class JSONSchema extends JSONInstance -{ - protected $_schema; - protected $_fd; - protected $_attributes = array(); - /** - * @param {Environment} env The environment this schema belongs to - * @param {JSONInstance|Any} json The value of the schema - * @param {String} [uri] The URI of the schema. If undefined, the URI will be a randomly generated UUID. - * @param {JSONSchema|Boolean} [schema] The schema to bind to the instance. If undefined, the environment's default schema will be used. If true, the instance's schema will be itself. - * @extends JSONInstance - */ - - function __construct(Environment $env, $json, $uri = null, $schema = null) { - parent::__construct($env, $json, $uri); - - if ($schema === true) { - $this->_schema = $this; - } elseif ($json instanceof JSONSchema && !($schema instanceof JSONSchema)) { - $this->_schema = $json->getSchema(); //TODO: Make sure cross environments don't mess everything up - } else { - if ($schema instanceof JSONSchema) { - $this->_schema = $schema; - } else { - $default = $this->_env->getDefaultSchema(); - if ($default) { - $this->_schema = $default; - } else { - $this->_schema = $this->createEmptySchema($this->_env); - } - } - } - - //determine fragment delimiter from schema - $fr = $this->_schema->getValueOfProperty("fragmentResolution"); - if ($fr === "dot-delimited") { - $this->_fd = "."; - } else if ($fr === "slash-delimited") { - $this->_fd = "/"; - } - } - - /** - * Creates an empty schema. - * - * @param {Environment} env The environment of the schema - * @returns {JSONSchema} The empty schema, who's schema is itself. - */ - - static function createEmptySchema(Environment $env) - { - static $race = 0; - if ($race) return $this; - $race = 1; // avoid race condition: endless loop - $schema = new self($env, array(), null); - $race = 0; - $schema->setSchema($schema); - return $schema; - } - - function setSchema(JSONSchema $schema) - { - $this->_schema = $schema; - $fr = $this->_schema->getValueOfProperty("fragmentResolution"); - if ($fr === "dot-delimited") { - $this->_fd = "."; - } else if ($fr === "slash-delimited") { - $this->_fd = "/"; - } - } - - /** - * Returns the schema of the schema. - * - * @returns {JSONSchema} The schema of the schema - */ - - function getSchema() - { - return $this->_schema; - } - - /** - * Returns the value of the provided attribute name. - *

- * This method is different from {@link JSONInstance#getProperty} as the named property - * is converted using a parser defined by the schema's schema before being returned. This - * makes the return value of this method attribute dependent. - *

- * - * @param {String} key The name of the attribute - * @param {Any} [arg] Some attribute parsers accept special arguments for returning resolved values. This is attribute dependent. - * @returns {JSONSchema|Any} The value of the attribute - */ - - function getAttribute($key, $arg = null) - { - if (!$arg && array_key_exists($key, $this->_attributes)) { - return $this->_attributes[$key]; - } - - $schemaProperty = $this->_schema->getProperty("properties")->getProperty($key); - $parser = $schemaProperty->getValueOfProperty("parser"); - $property = $this->getProperty($key); - if (is_callable($parser)) { - if (is_object($parser)) { - $result = $parser($property, $schemaProperty, $arg); - } else { - call_user_func($parser, $property, $schemaProperty, $arg); - } - if (!$arg && $this->_attributes) { - $this->_attributes[$key] = $result; - } - return $result; - } - //else - return $property->getValue(); - } - - /** - * Returns all the attributes of the schema. - * - * @returns {Object} A map of all parsed attribute values - */ - - function getAttributes() - { - if (!count($this->_attributes) && is_json_object($this->_value)) { - $properties = $this->getProperties(); - $schemaProperties = $this->_schema->getProperty("properties"); - $this->_attributes = array(); - foreach ($properties as $key => $val) { - if (count($schemaProperties)) { - $schemaProperty = $schemaProperties->getProperty($key); - if ($schemaProperty) { - $parser = $schemaProperty->getValueOfProperty("parser"); - } - } - if (is_callable($parser)) { - if (is_object($parser)) { - $this->_attributes[$key] = $parser($val, $schemaProperty); - } else { - $this->_attributes[$key] = call_user_func($parser, $val, $schemaProperty); - } - } else { - $this->_attributes[$key] = $val->getValue(); - } - } - } - - return JSV::dirtyClone($this->_attributes); - } - - /** - * Convenience method for retrieving a link or link object from a schema. - * This method is the same as calling schema.getAttribute("links", [rel, instance])[0];. - * - * @param {String} rel The link relationship - * @param {JSONInstance} [instance] The instance to resolve any URIs from - * @returns {String|Object|undefined} If instance is provided, a string containing the resolve URI of the link is returned. - * If instance is not provided, a link object is returned with details of the link. - * If no link with the provided relationship exists, undefined is returned. - * @see JSONSchema#getAttribute - */ - - function getLink($rel, JSONInstance $instance) - { - $schemaLinks = $this->getAttribute("links", array($rel, $instance)); - if ($schemaLinks && count($schemaLinks) && $schemaLinks[count($schemaLinks) - 1]) { - return $schemaLinks[count($schemaLinks) - 1]; - } - } - - /** - * Validates the provided instance against the target schema and returns a {@link Report}. - * - * @param {JSONInstance|Any} instance The instance to validate; may be a {@link JSONInstance} or any JavaScript value - * @param {Report} [report] A {@link Report} to concatenate the result of the validation to. If undefined, a new {@link Report} is created. - * @param {JSONInstance} [parent] The parent/containing instance of the provided instance - * @param {JSONSchema} [parentSchema] The schema of the parent/containing instance - * @param {String} [name] The name of the parent object's property that references the instance - * @returns {Report} The result of the validation - */ - - function validate($instance, Report $report = null, JSONInstance $parent = null, JSONSchema $parentSchema = null, $name = null) - { - $validator = $this->_schema->getValueOfProperty("validator"); - - if (!($instance instanceof JSONInstance)) { - $instance = $this->getEnvironment()->createInstance($instance); - } - - if (!($report instanceof Report)) { - $report = new Report(); - } - - if (is_callable($validator) && !$report->isValidatedBy($instance->getURI(), $this->getURI())) { - $report->registerValidation($instance->getURI(), $this->getURI()); - $validator($instance, $this, $this->_schema, $report, $parent, $parentSchema, $name); - } - - return $report; - } -} - -class EnvironmentOptions -{ - public $defaultFragmentDelimiter = '', - $defaultSchemaURI = '', - $validateReferences = false, - $latestJSONSchemaSchemaURI = '', - $latestJSONSchemaHyperSchemaURI = '', - $latestJSONSchemaLinksURI = ''; - function __set($var, $value) - { - throw new Exception('Unknown option value: ' . $var); - } - function __get($var) - { - throw new Exception('Unknown option value: ' . $var); - } -} - -class Environment -{ - protected $_schemas = array(); - protected $_options; - protected $_id; - /** - * An Environment is a sandbox of schemas thats behavior is different from other environments. - * - * @name Environment - * @class - */ - - function __construct() { - $this->_id = JSV::randomUUID(); - $this->_options = new EnvironmentOptions; - } - - /** - * Returns a clone of the target environment. - * - * @returns {Environment} A new {@link Environment} that is a exact copy of the target environment - */ - - function __clone() - { - $this->_options = clone $this->_options; - $this->_schemas = JSV::inherits($this->_schemas); - } - - /** - * Returns a new {@link JSONInstance} of the provided data. - * - * @param {JSONInstance|Any} data The value of the instance - * @param {String} [uri] The URI of the instance. If undefined, the URI will be a randomly generated UUID. - * @returns {JSONInstance} A new {@link JSONInstance} from the provided data - */ - - function createInstance($data, $uri = '') - { - $uri = JSV::formatURI($uri); - - if ($data instanceof JSONInstance && (!$uri || $data->getURI() === $uri)) { - return $data; - } - //else - $instance = new JSONInstance($this, $data, $uri); - - return $instance; - } - - /** - * Creates a new {@link JSONSchema} from the provided data, and registers it with the environment. - * - * @param {JSONInstance|Any} data The value of the schema - * @param {JSONSchema|Boolean} [schema] The schema to bind to the instance. If undefined, the environment's default schema will be used. If true, the instance's schema will be itself. - * @param {String} [uri] The URI of the schema. If undefined, the URI will be a randomly generated UUID. - * @returns {JSONSchema} A new {@link JSONSchema} from the provided data - * @throws {InitializationError} If a schema that is not registered with the environment is referenced - */ - - function createSchema($data, $schema = null, $uri = '') - { - $uri = JSV::formatURI($uri); - - if ($data instanceof JSONSchema && (!$uri || $data->getUri() === $uri) && (!$schema || $data->getSchema()->equals($schema))) { - return $data; - } - - $instance = new JSONSchema($this, $data, $uri, $schema); - - $initializer = $instance->getSchema()->getValueOfProperty("initializer"); - if (is_callable($initializer)) { - if (is_object($initializer)) { - $instance = $initializer($instance); - } else { - $instance = call_user_func($initializer, $instance); - } - } - - //register schema - $this->_schemas[$instance->getUri()] = $instance; - settype($uri, 'string'); - $this->_schemas[$uri] = $instance; - - //build & cache the rest of the schema - $instance->getAttributes(); - - return $instance; - } - - /** - * Creates an empty schema. - * - * @param {Environment} env The environment of the schema - * @returns {JSONSchema} The empty schema, who's schema is itself. - */ - - function createEmptySchema() - { - $schema = JSONSchema::createEmptySchema($this); - $this->_schemas[$schema->getUri()] = $schema; - return $schema; - } - - /** - * Returns the schema registered with the provided URI. - * - * @param {String} uri The absolute URI of the required schema - * @returns {JSONSchema|undefined} The request schema, or undefined if not found - */ - - function findSchema($uri) - { - if (!isset($this->_schemas[JSV::formatURI($uri)])) { - return null; - } - return $this->_schemas[JSV::formatURI($uri)]; - } - - /** - * Sets the specified environment option to the specified value. - * - * @param {String} name The name of the environment option to set - * @param {Any} value The new value of the environment option - */ - - function setOption($name, $value) - { - $this->_options->$name = $value; - } - - /** - * Returns the specified environment option. - * - * @param {String} name The name of the environment option to set - * @returns {Any} The value of the environment option - */ - - function getOption($name) - { - return $this->_options->$name; - } - - /** - * Sets the default fragment delimiter of the environment. - * - * @deprecated Use {@link Environment#setOption} with option "defaultFragmentDelimiter" - * @param {String} fd The fragment delimiter character - */ - - function setDefaultFragmentDelimiter($fd) - { - if (is_string($fd) && strlen($fd) > 0) { - $this->_options->defaultFragmentDelimiter = $fd; - } - } - - /** - * Returns the default fragment delimiter of the environment. - * - * @deprecated Use {@link Environment#getOption} with option "defaultFragmentDelimiter" - * @returns {String} The fragment delimiter character - */ - - function getDefaultFragmentDelimiter() - { - return $this->_options->defaultFragmentDelimiter; - } - - /** - * Sets the URI of the default schema for the environment. - * - * @deprecated Use {@link Environment#setOption} with option "defaultSchemaURI" - * @param {String} uri The default schema URI - */ - - function setDefaultSchemaURI($uri) - { - if (is_string($uri)) { - $this->_options->defaultSchemaURI = JSV::formatURI($uri); - } - } - - /** - * Returns the default schema of the environment. - * - * @returns {JSONSchema} The default schema - */ - - function getDefaultSchema() - { - return $this->findSchema($this->_options->defaultSchemaURI); - } - - /** - * Validates both the provided schema and the provided instance, and returns a {@link Report}. - * If the schema fails to validate, the instance will not be validated. - * - * @param {JSONInstance|Any} instanceJSON The {@link JSONInstance} or JavaScript value to validate. - * @param {JSONSchema|Any} schemaJSON The {@link JSONSchema} or JavaScript value to use in the validation. This will also be validated againt the schema's schema. - * @returns {Report} The result of the validation - */ - - function validate($instanceJSON, $schemaJSON = null) - { - $report = new Report(); - - try { - $instance = $this->createInstance($instanceJSON); - $report->instance = $instance; - } catch (Exception $e) { - $report->addError($e->uri, $e->schemaUri, $e->attribute, $e->getMessage(), $e->details); - } - - try { - $schema = $this->createSchema($schemaJSON); - $report->schema = $schema; - - $schemaSchema = $schema->getSchema(); - $report->schemaSchema = $schemaSchema; - } catch (Exception $e) { - $report->addError($e->uri, $e->schemaUri, $e->attribute, $e->getMessage(), $e->details); - } - - if ($schemaSchema) { - $schemaSchema->validate($schema, $report); - } - - if (count($report->errors)) { - return $report; - } - - return $schema->validate($instance, $report); - } - - /** - * @private - */ - - protected function _checkForInvalidInstances($stackSize, $schemaURI) - { - $result = array(); - $stack = - array( - array($schemaURI, $this->_schemas[$schemaURI]) - ); - $counter = 0; - - while ($counter++ < $stackSize && count($stack)) { - $item = array_shift($stack); - $uri = $item[0]; - $instance = $item[1]; - - if ($instance instanceof JSONSchema) { - if ($this->_schemas[$instance->getUri()] !== $instance) { - array_push($result, "Instance " . $uri . " does not match " . $instance->getUri()); - } else { - //$schema = $instance->getSchema(); - //array_push($stack, array($uri . "/{schema}", $schema)); - - $properties = $instance->getAttributes(); - foreach ($properties as $key => $val) { - array_push($stack, array($uri . "/" . urlencode($key), $val)); - } - } - } else if (is_object($instance)) { - $properties = $instance; - foreach (get_object_vars($properties) as $key => $val) { - if (isset($val)) { - array_push($stack, array($uri . "/" . urlencode($key), $val)); - } - } - } else if (is_array($instance)) { - $properties = $instance; - foreach ($properties as $key => $val) { - array_push($stack, array($uri . "/" . urlencode($key), $val)); - } - } - } - - return count($result) ? $result : $counter; - } - - function setId($id) - { - $this->_id = $id; - } - - function getId() - { - return $this->_id; - } - - function getSchemas() - { - return $this->_schemas; - } - - // hack do not use unless you are Gary Court or porting his work - function replaceSchema($uri, JSONSchema $schema) - { - $this->_schemas[$uri] = $schema; - } -} - - /** - * A globaly accessible object that provides the ability to create and manage {@link Environments}, - * as well as providing utility methods. - * - * Note: when porting JSV to PHP, remove all references to an "O" (the letter O) variable, this hack is - * only necessary in javascript to make for (a in blah) work and is not needed in PHP - * - * @namespace - */ - -class JSV -{ - static protected $_environments = array(); - static protected $_defaultEnvironmentID = ""; - - /** - * Creates and returns a new {@link Environment} that is a clone of the environment registered with the provided ID. - * If no environment ID is provided, the default environment is cloned. - * - * @param {String} [id] The ID of the environment to clone. If undefined, the default environment ID is used. - * @returns {Environment} A newly cloned {@link Environment} - * @throws {Error} If there is no environment registered with the provided ID - * @return class JsonSchema\Environment environment object - */ - - static function createEnvironment($id) - { - if (!$id) { - $id = static::$_defaultEnvironmentID; - } - - if (!static::$_environments[$id]) { - throw new Exception("Unknown Environment ID"); - } - //else - return clone static::$_environments[$id]; - } - - /** - * Registers the provided {@link Environment} with the provided ID. - * - * @param {String} id The ID of the environment - * @param {Environment} env The environment to register - */ - - static function registerEnvironment($id, $env) - { - if (!$id && $env) { - $id = $env->_id; - } - if ($id && !static::$_environments[$id] && $env instanceof Environment) { - $env->setId($id); - static::$_environments[$id] = $env; - } - } - - /** - * Sets which registered ID is the default environment. - * - * @param {String} id The ID of the registered environment that is default - * @throws {Error} If there is no registered environment with the provided ID - */ - - static function setDefaultEnvironmentID($id) - { - if (is_string($id)) { - if (!static::$_environments[$id]) { - throw new Exception("Unknown Environment ID"); - } - - static::$_defaultEnvironmentID = $id; - } - } - - /** - * Returns the ID of the default environment. - * - * @returns {String} The ID of the default environment - */ - - static function getDefaultEnvironmentID() - { - return static::$_defaultEnvironmentID; - } - - // - // Utility Functions - // - - /** - * Returns the name of the type of the provided value. - * - * @event //utility - * @param {Any} o The value to determine the type of - * @returns {String} The name of the type of the value - */ - //typeOf : typeOf, use gettype - - /** - * Return a new object that inherits all of the properties of the provided object. - * - * @event //utility - * @param {Object} proto The prototype of the new object - * @returns {Object} A new object that inherits all of the properties of the provided object - */ - //createObject : createObject, use clone - - /** - * Returns a new object with each property transformed by the iterator. - * - * @event //utility - * @param {Object} obj The object to transform - * @param {Function} iterator A function that returns the new value of the provided property - * @returns {Object} A new object with each property transformed - */ - // unnecessary - - /** - * Returns a new array with each item transformed by the iterator. - * - * @event //utility - * @param {Array} arr The array to transform - * @param {Function} iterator A function that returns the new value of the provided item - * @param {Object} scope The value of this in the iterator - * @returns {Array} A new array with each item transformed - */ - //mapArray : mapArray, use array_map - - /** - * Returns a new array that only contains the items allowed by the iterator. - * - * @event //utility - * @param {Array} arr The array to filter - * @param {Function} iterator The function that returns true if the provided property should be added to the array - * @param {Object} scope The value of this within the iterator - * @returns {Array} A new array that contains the items allowed by the iterator - */ - //filterArray : filterArray, use array_filter - - /** - * Returns the first index in the array that the provided item is located at. - * - * @event //utility - * @param {Array} arr The array to search - * @param {Any} o The item being searched for - * @returns {Number} The index of the item in the array, or -1 if not found - */ - //searchArray : searchArray, use array_search - - /** - * Returns an array representation of a value. - *
    - *
  • For array-like objects, the value will be casted as an Array type.
  • - *
  • If an array is provided, the function will simply return the same array.
  • - *
  • For a null or undefined value, the result will be an empty Array.
  • - *
  • For all other values, the value will be the first element in a new Array.
  • - *
- * - * @event //utility - * @param {Any} o The value to convert into an array - * @returns {Array} The value as an array - */ - //toArray : toArray, use settype($var, 'array'); - - /** - * Returns an array of the names of all properties of an object. - * - * @event //utility - * @param {Object|Array} o The object in question - * @returns {Array} The names of all properties - */ - //keys : keys, use get_object_vars - - /** - * Mutates the array by pushing the provided value onto the array only if it is not already there. - * - * @event //utility - * @param {Array} arr The array to modify - * @param {Any} o The object to add to the array if it is not already there - * @returns {Array} The provided array for chaining - */ - static function pushUnique($arr, $o) - { - if (!in_array($o, $arr)) { - $arr[] = $o; - } - return $arr; - } - - /** - * Mutates the array by removing the first item that matches the provided value in the array. - * - * @event //utility - * @param {Array} arr The array to modify - * @param {Any} o The object to remove from the array - * @returns {Array} The provided array for chaining - */ - //popFirst : popFirst, use array_udiff($arr, array($o)) - - /** - * Creates a copy of the target object. - *

- * This method will create a new instance of the target, and then mixin the properties of the target. - * If deep is true, then each property will be cloned before mixin. - *

- *

Warning: This is not a generic clone function, as it will only properly clone objects and arrays.

- * - * @event //utility - * @param {Any} o The value to clone - * @param {Boolean} [deep=false] If each property should be recursively cloned - * @returns A cloned copy of the provided value - */ - //clone : clone, use built-in PHP clone - - /** - * Generates a pseudo-random UUID. - * - * @event //utility - * @returns {String} A new universally unique ID - */ - static function randomUUID() - { - return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', - - // 32 bits for "time_low" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - - // 16 bits for "time_mid" - mt_rand(0, 0xffff), - - // 16 bits for "time_hi_and_version", - // four most significant bits holds version number 4 - mt_rand(0, 0x0fff) | 0x4000, - - // 16 bits, 8 bits for "clk_seq_hi_res", - // 8 bits for "clk_seq_low", - // two most significant bits holds zero and one for variant DCE1.1 - mt_rand(0, 0x3fff) | 0x8000, - - // 48 bits for "node" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); - } - - /** - * Properly escapes a URI component for embedding into a URI string. - * - * @event //utility - * @param {String} str The URI component to escape - * @returns {String} The escaped URI component - */ - //escapeURIComponent : escapeURIComponent, use urlencode - - /** - * Returns a URI that is formated for JSV. Currently, this only ensures that the URI ends with a hash tag (#). - * - * @event //utility - * @param {String} uri The URI to format - * @returns {String} The URI formatted for JSV - */ - static function formatURI($uri) - { - if ($uri && $uri[strlen($uri)-1] != '#') { - $uri .= '#'; - } - return $uri; - } - - /** - * Merges two schemas/instance together. - * - * @event //utility - * @param {JSONSchema|Any} base The old value to merge - * @param {JSONSchema|Any} extra The new value to merge - * @param {Boolean} extension If the merge is a JSON Schema extension - * @return {Any} The modified base value - */ - - static function inherits($base, $extra = null, $extension = false) - { - if ($extra === null) { - if (is_object($base)) { - if (is_callable($base)) { - return $base; // Closure cannot be cloned - } - return clone $base; - } - if (is_array($base)) { - foreach ($base as $key => $val) { - if (is_object($val) || is_array($val)) { - $base[$key] = self::inherits($val); - } - } - } - return $base; - } else if ($base === null || gettype($base) != gettype($extra)) { - if (is_object($extra)) { - if (is_callable($extra)) { - return $extra; // Closure cannot be cloned - } - return clone $extra; - } - if (is_array($extra)) { - foreach ($extra as $key => $val) { - if (is_object($val) || is_array($val)) { - $extra[$key] = self::inherits($val); - } - } - } - return $extra; - } else if (is_json_object($extra)) { - if ($base instanceof JSONSchema) { - $base = $base->getAttributes(); - } - if ($extra instanceof JSONSchema) { - $extra = $extra->getAttributes(); - if ($extra["extends"] && $extension && $extra["extends"] instanceof JSONSchema) { - $extra["extends"] = array($extra["extends"]); - } - } - $child = $base; - foreach ($extra as $x => $unused) { - $child[$x] = self::inherits($base[$x], $extra[$x], $extension); - } - return $child; - } else { - if (is_object($extra)) { - if (is_callable($extra)) { - return $extra; // Closure cannot be cloned - } - return clone $extra; - } - if (is_array($extra)) { - foreach ($extra as $key => $val) { - if (is_object($val) || is_array($val)) { - $extra[$key] = self::inherits($val); - } - } - } - return $extra; - } - } - - - /** - * Warning: Not a generic clone function - * Produces a JSV acceptable clone - */ - - static function dirtyClone($obj) - { - if ($obj instanceof JSONInstance) { - $obj = $obj->getValue(); - } - if (!is_object($obj) && !is_array($obj)) { - return $obj; - } - - if (is_object($obj)) { - if (is_callable($obj)) { - return $obj; - } - $obj = get_object_vars($obj); - } - $newObj = array(); - foreach ($obj as $key => $val) { - $newObj[$key] = self::dirtyClone($val); - } - return $newObj; - } - - static function getMatchedPatternProperties($instance, $schema, $report, $self) - { - $matchedProperties = array(); - - if (is_json_object($instance.getValue())) { - $patternProperties = $schema->getAttribute("patternProperties"); - $properties = $instance->getProperties(); - foreach ($patternProperties as $pattern => $patproperty) { - if (!@preg_match($pattern, '')) { - if ($report) { - $report->addError($schema, $self, "patternProperties", "Invalid pattern", $pattern); - } - } - foreach ($properties as $key => $property) { - if (preg_match($pattern, $key)) { - $matchedProperties[$key] = isset($matchedProperties[$key]) ? - JSV::pushUnique($matchedProperties[$key], $patproperty) : - array($patproperty); - } - } - } - } - - return $matchedProperties; - } -} -new JsonSchemaDraft03; -$env = JSV::createEnvironment("json-schema-draft-03"); -echo $env->validate(array(14.0011), array('type' => 'array', 'items' => array('type' => 'number', 'divisibleBy' => 7.0005)))->errors[0]; \ No newline at end of file diff --git a/lib/uri/Uri.php b/lib/uri/Uri.php deleted file mode 100644 index 1105ed1..0000000 --- a/lib/uri/Uri.php +++ /dev/null @@ -1,766 +0,0 @@ - array()); - - function __set($var, $value) - { - throw new Exception('Unknown components value: ' . $var); - } - - function __get($var) - { - throw new Exception('Unknown components value: ' . $var); - } -} -class Uri -{ - static $schemeHandlers; - protected $options; - static protected $regex = array( - 'ALPHA' => "[A-Za-z]", - 'CR' => "[\\x0D]", - 'DIGIT' => "[0-9]", - 'DQUOTE' => "[\\x22]", - 'HEXDIG' => "[a-zA-Z0-9]", - 'LF' => "[\\x0A]", - 'SP' => "[\\x20]", - 'PCT_ENCODED' => "(?:%[a-zA-Z0-9][a-zA-Z0-9])", - 'GEN_DELIMS' => "[\\:\\/\\?\\#\\[\\]\\@]", - 'SUB_DELIMS' => "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]", - 'H16' => "(?:[0-9a-fA-F]{1,4})", - 'PORT' => "(?:\\d*)", - 'URI_PARSE' => "/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/i", - 'RDS1' => "/^\.\.?\//", - 'RDS2' => "/^\/\.(\/|$)/", - 'RDS3' => "/^\/\.\.(\/|$)/", - 'RDS4' => "/^\.\.?$/", - 'RDS5' => "/^\/?.*?(?=\/|$)/", - ); - - function __construct() - { - $this->options = new Options; - static::setupRegex(); - } - - static function mergeSet($set) - { - $set = substr($set, 0, strlen($set) - 1); - for ($i = 1; $i < func_num_args(); $i++) { - $nextSet = func_get_arg($i); - $set .= substr($nextSet, 1, strlen($nextSet) - 2); - } - return $set . ']'; - } - - - static function subexp($str) - { - return "(?:" . $str . ")"; - } - - static function setupRegex($cache = false) - { - static $done = 0; - if ($done) return; - if (class_exists(__NAMESPACE__ . '\UriCache', 1)) { - static::$regex = UriCache::$regex; - $done = 1; - return; - } - $r = &static::$regex; - $r['RESERVED'] = static::mergeSet($r['GEN_DELIMS'], $r['SUB_DELIMS']); - $r['UNRESERVED'] = static::mergeSet($r['ALPHA'], $r['DIGIT'], "[\\-\\.\\_\\~]"); - $r['UNRESERVED_SET'] = array(); - for ($i = ord('a'); $i <= ord('z'); $i++) { - $r['UNRESERVED_SET'][chr($i)] = 1; - $r['UNRESERVED_SET'][chr($i - 32)] = 1; - } - for ($i = 0; $i < 10; $i++) { // digits - $r['UNRESERVED_SET'][chr(48 + $i) . ''] = 1; - } - $r['UNRESERVED_SET']['-'] = 1; - $r['UNRESERVED_SET']['.'] = 1; - $r['UNRESERVED_SET']['_'] = 1; - $r['UNRESERVED_SET']['~'] = 1; - $r['SCHEME'] = static::subexp($r['ALPHA'] . static::mergeSet($r['ALPHA'], $r['DIGIT'], "[\\+\\-\\.]") . "*"); - $r['USERINFO'] = static::subexp(static::subexp($r['PCT_ENCODED'] . '|' . static::mergeSet($r['UNRESERVED'], $r['SUB_DELIMS'], "[\\:]")) . '*'); - $r['DEC_OCTET'] = static::subexp($r['DIGIT'] . "|" . static::subexp("[1-9]" . $r['DIGIT']) . "|" . static::subexp("1" . - $r['DIGIT'] . $r['DIGIT']) . - "|" . static::subexp("2[0-4]" . $r['DIGIT']) . "|" . static::subexp("25[0-5]")); - $r['IPV4ADDRESS'] = static::subexp($r['DEC_OCTET'] . "\\." . $r['DEC_OCTET'] . "\\." . $r['DEC_OCTET'] . "\\." . $r['DEC_OCTET']); - $r['LS32'] = static::subexp(static::subexp($r['H16'] . "\\:" . $r['H16']) . "|" . $r['IPV4ADDRESS']); - $r['IPV6ADDRESS'] = static::subexp(static::mergeSet($r['UNRESERVED'], $r['SUB_DELIMS'], "[\\:]") . "+"); //FIXME - $r['IPVFUTURE'] = static::subexp("v" . $r['HEXDIG'] . "+\\." . static::mergeSet($r['UNRESERVED'], $r['SUB_DELIMS'], "[\\:]") . "+"); - $r['IP_LITERAL'] = static::subexp("\\[" . static::subexp($r['IPV6ADDRESS'] . "|" . $r['IPVFUTURE']) . "\\]"); - $r['REG_NAME'] = static::subexp(static::subexp($r['PCT_ENCODED'] . "|" . static::mergeSet($r['UNRESERVED'], $r['SUB_DELIMS'])) . "*"); - $r['HOST'] = static::subexp($r['IP_LITERAL'] . "|" . $r['IPV4ADDRESS'] . "|" . $r['REG_NAME']); - $r['AUTHORITY'] = static::subexp(static::subexp($r['USERINFO'] . "@") . "?" . $r['HOST'] . static::subexp("\\:" . $r['PORT']) . "?"); - $r['PCHAR'] = static::subexp($r['PCT_ENCODED'] . "|" . static::mergeSet($r['UNRESERVED'], $r['SUB_DELIMS'], "[\\:\\@]")); - $r['SEGMENT'] = static::subexp($r['PCHAR'] . "*"); - $r['SEGMENT_NZ'] = static::subexp($r['PCHAR'] . "+"); - $r['SEGMENT_NZ_NC'] = static::subexp(static::subexp($r['PCT_ENCODED'] . "|" . static::mergeSet($r['UNRESERVED'], $r['SUB_DELIMS'], "[\\@]")) . "+"); - $r['PATH_ABEMPTY'] = static::subexp(static::subexp("\\/" . $r['SEGMENT']) . "*"); - $r['PATH_ABSOLUTE'] = static::subexp("\\/" . static::subexp($r['SEGMENT_NZ'] . $r['PATH_ABEMPTY']) . "?"); //simplified - $r['PATH_NOSCHEME'] = static::subexp($r['SEGMENT_NZ_NC'] . $r['PATH_ABEMPTY']); //simplified - $r['PATH_ROOTLESS'] = static::subexp($r['SEGMENT_NZ'] . $r['PATH_ABEMPTY']); //simplified - $r['PATH_EMPTY'] = static::subexp(""); //simplified - $r['PATH'] = static::subexp($r['PATH_ABEMPTY'] . "|" . $r['PATH_ABSOLUTE'] . "|" . $r['PATH_NOSCHEME'] . "|" . $r['PATH_ROOTLESS'] . "|" . $r['PATH_EMPTY']); - $r['QUERY'] = static::subexp(static::subexp($r['PCHAR'] . "|[\\/\\?]") . "*"); - $r['FRAGMENT'] = static::subexp(static::subexp($r['PCHAR'] . "|[\\/\\?]") . "*"); - $r['HIER_PART'] = static::subexp(static::subexp("\\/\\/" . $r['AUTHORITY'] . $r['PATH_ABEMPTY']) . "|" . $r['PATH_ABSOLUTE'] . "|" . $r['PATH_ROOTLESS'] . "|" . $r['PATH_EMPTY']); - $r['URI'] = static::subexp($r['SCHEME'] . "\\:" . $r['HIER_PART'] . static::subexp("\\?" . $r['QUERY']) . "?" . static::subexp("\\#" . $r['FRAGMENT']) . "?"); - $r['RELATIVE_PART'] = static::subexp(static::subexp("\\/\\/" . $r['AUTHORITY'] . $r['PATH_ABEMPTY']) . "|" . $r['PATH_ABSOLUTE'] . "|" . $r['PATH_NOSCHEME'] . "|" . $r['PATH_EMPTY']); - $r['RELATIVE_REF'] = static::subexp($r['RELATIVE_PART'] . static::subexp("\\?" . $r['QUERY']) . "?" . static::subexp("\\#" . $r['FRAGMENT']) . "?"); - $r['URI_REFERENCE'] = static::subexp($r['URI'] . "|" . $r['RELATIVE_REF']); - $r['ABSOLUTE_URI'] = static::subexp($r['SCHEME'] . "\\:" . $r['HIER_PART'] . static::subexp("\\?" . $r['QUERY']) . "?"); - - $r['URI_REF'] = "/^" . static::subexp("(" . $r['URI'] . ")|(" . $r['RELATIVE_REF'] . ")") . "\\z/"; - $r['GENERIC_REF'] = "/^(" . $r['SCHEME'] . ")\\:" . - static::subexp(static::subexp("\\/\\/(" . static::subexp("(" . $r['USERINFO'] . ")@") . "?(" . $r['HOST'] . ")" . - static::subexp("\\:(" . $r['PORT'] . ")") . "?)") . "?(" . $r['PATH_ABEMPTY'] . "|" . - $r['PATH_ABSOLUTE'] . "|" . $r['PATH_ROOTLESS'] . "|" . $r['PATH_EMPTY'] . ")") . - static::subexp("\\?(" . $r['QUERY'] . ")") . "?" . static::subexp("\\#(" . $r['FRAGMENT'] . ")") . "?\\z/"; - $r['RELATIVE_REF'] = "/^(){0}" . static::subexp(static::subexp("\\/\\/(" . static::subexp("(" . $r['USERINFO'] . ")@") . - "?(" . $r['HOST'] . ")" . static::subexp("\\:(" . $r['PORT'] . ")") . - "?)") . "?(" . $r['PATH_ABEMPTY'] . "|" . $r['PATH_ABSOLUTE'] . "|" . - $r['PATH_NOSCHEME'] . "|" . $r['PATH_EMPTY'] . ")") . - static::subexp("\\?(" . $r['QUERY'] . ")") - . "?" . static::subexp("\\#(" . $r['FRAGMENT'] . ")") . "?$/"; - $r['ABSOLUTE_REF'] = "/^(" . $r['SCHEME'] . ")\\:" . static::subexp(static::subexp("\\/\\/(" . - static::subexp("(" . $r['USERINFO'] . ")@") . "?(" . - $r['HOST'] . ")" . static::subexp("\\:(" . $r['PORT'] . ")") - . "?)") . "?(" . $r['PATH_ABEMPTY'] . "|" . - $r['PATH_ABSOLUTE'] . "|" . $r['PATH_ROOTLESS'] . "|" . - $r['PATH_EMPTY'] . ")") . static::subexp("\\?(" . $r['QUERY'] . ")") . "?\\z/"; - $r['SAMEDOC_REF'] = "/^" . static::subexp("\\#(" . $r['FRAGMENT'] . ")") . "?\\z/"; - $r['AUTHORITY'] = "/^" . static::subexp("(" . $r['USERINFO'] . ")@") . "?(" . $r['HOST'] . ")" . static::subexp("\\:(" . $r['PORT'] . ")") . "?\\z/"; - - $r['NOT_SCHEME'] = "/" . static::mergeSet("[^]", $r['ALPHA'], $r['DIGIT'], "[\\+\\-\\.]") . "/"; - $r['NOT_USERINFO'] = "/" . static::mergeSet("[^\\%\\:]", $r['UNRESERVED'], $r['SUB_DELIMS']) . "/"; - $r['NOT_HOST'] = "/" . static::mergeSet("[^\\%]", $r['UNRESERVED'], $r['SUB_DELIMS']) . "/"; - $r['NOT_PATH'] = "/" . static::mergeSet("[^\\%\\/\\:\\@]", $r['UNRESERVED'], $r['SUB_DELIMS']) . "/"; - $r['NOT_PATH_NOSCHEME'] = "/" . static::mergeSet("[^\\%\\/\\@]", $r['UNRESERVED'], $r['SUB_DELIMS']) . "/"; - $r['NOT_QUERY'] = "/" . static::mergeSet("[^\\%]", $r['UNRESERVED'], $r['SUB_DELIMS'], "[\\:\\@\\/\\?]") . "/"; - $r['NOT_FRAGMENT'] = $r['NOT_QUERY']; - $r['ESCAPE'] = "/" . static::mergeSet("[^]", $r['UNRESERVED'], $r['SUB_DELIMS']) . "/"; - $r['UNRESERVEDREGEX'] = "/" . $r['UNRESERVED'] . "/"; - $r['OTHER_CHARS'] = "/" . static::mergeSet("[^\\%]", $r['UNRESERVED'], $r['RESERVED']) . "/"; - $r['PCT_ENCODEDS'] = "/" . $r['PCT_ENCODED'] . "+" . "/"; - $done = 1; - if ($cache) { - // save this complicated crap to a cached php file for faster loading later - file_put_contents(__DIR__ . '/UriCache.php', str_replace(array( - '0 => 1', - '1 => 1', - '2 => 1', - '3 => 1', - '4 => 1', - '5 => 1', - '6 => 1', - '7 => 1', - '8 => 1', - '9 => 1', - ), - array( - '"0" => 1', - '"1" => 1', - '"2" => 1', - '"3" => 1', - '"4" => 1', - '"5" => 1', - '"6" => 1', - '"7" => 1', - '"8" => 1', - '"9" => 1', - ), 'utfCharToNumber(dechex($chr[0])); - - if ($c < 128) { - return "%" . strtoupper(dechex($c)); - } elseif (($c > 127) && ($c < 2048)) { - return "%" . strtoupper(dechex(($c >> 6) | 192)) . "%" . strtoupper(dechex(($c & 63) | 128)); - } else { - return "%" . strtoupper(dechex((c >> 12) | 224)) . "%" . strtoupper(dechex((($c >> 6) & 63) | 128)) . - "%" . strtoupper(dechex(($c & 63) | 128)); - } - } - - function pctDecUnreserved($str) - { - $newStr = ""; - $i = 0; - - while ($i < strlen($str)) { - $c = hexdec(substr($str, $i + 1, 2)); - - if ($c < 128) { - if (isset(static::$regex['UNRESERVED_SET'][chr($c)])) { - $newStr .= chr($c); - } else { - $newStr .= substr($str, $i, 3); - } - $i += 3; - } elseif (($c > 191) && ($c < 224)) { - $newStr .= substr($str, $i, 6); - $i += 6; - } else { - $newStr .= substr($str, $i, 9); - $i += 9; - } - } - - return $newStr; - } - - function pctDecChars($matches) - { - $str = $matches[0]; - $newStr = ""; - $i = 0; - - while ($i < strlen($str)) { - $c = hexdec(substr($str, $i + 1, 2)); - - if ($c < 128) { - $newStr .= chr($c); - $i += 3; - } elseif (($c > 191) && ($c < 224)) { - $c2 = hexdec(substr($str, $i + 4, 2)); - $newStr .= utf8_encode(chr($c & 0xff) . chr($c2 & 0xff)); - $i += 6; - } - else { - $c2 = hexdec(substr($str, $i + 4, 2)); - $c3 = hexdec(substr($str, $i + 7, 2)); - $newStr .= utf8_encode(chr($c & 0xff) . chr($c2 & 0xff) . chr($c3 & 0xff)); - $i += 9; - } - } - - return $newStr; - } - - /** - * @namespace - */ - - protected static $SCHEMES = array(); - - function addScheme(SchemeHandlerInterface $handler) - { - static::$SCHEMES[$handler->getName()] = $handler; - } - - /** - * @param {String} uriString - * @param {Options} [options] - * @returns {URIComponents} - */ - - function parse($uriString, Options $options = null) - { - $components = new Components; - - $uriString = $uriString ? (string) $uriString : ""; - if (null === $options) { - $options = $this->options; - } - - if ($options->reference === "suffix") { - $uriString = ($options->scheme ? $options->scheme . ":" : "") . "//" . $uriString; - } - - if (preg_match(static::$regex['URI_REF'], $uriString, $matches)) { - if ($matches[1]) { - //generic URI - $test = preg_match(static::$regex['GENERIC_REF'], $uriString, $matches); - } else { - //relative URI - $test = preg_match(static::$regex['RELATIVE_REF'], $uriString, $matches); - } - } else { - if (!$options->tolerant) { - $components->errors->E_ERROR[] = new Exception("URI is not strictly valid."); - } - $test = preg_match(self::URI_PARSE, $uriString, $matches); - } - - if ($test) { - //store each component - $components->scheme = $matches[1]; - $components->authority = $matches[2]; - $components->userinfo = $matches[3]; - $components->host = $matches[4]; - $components->port = $matches[5]; - $components->path = $matches[6]; - $components->query = $matches[7]; - $components->fragment = $matches[8]; - - //fix port number - if (is_numeric($components->port)) { - $components->port = (int)$matches[5]; - } - - //determine reference type - if (!$components->scheme && !$components->authority && !$components->path && !$components->query) { - $components->reference = "same-document"; - } else if (!$components->scheme) { - $components->reference = "relative"; - } else if (!$components->fragment) { - $components->reference = "absolute"; - } else { - $components->reference = "uri"; - } - - //check for reference errors - if ($options->reference && $options->reference !== "suffix" && $options->reference !== $components->reference) { - $components->errors->E_ERROR[] = new Exception("URI is not a " . $options->reference . " reference."); - } - - //check if a handler for the scheme exists - if (isset(static::$SCHEMES[$components->scheme ? $components->scheme : $options->scheme])) { - $schemeHandler = static::$SCHEMES[$components->scheme ? $components->scheme : $options->scheme]; - //perform extra parsing - $components = $schemeHandler->parse($components, $options); - } - } else { - $components->errors->E_ERROR[] = new Exception("URI can not be parsed."); - } - - return $components; - } - - /** - * @private - * @param {URIComponents} components - * @returns {String} - */ - - function _recomposeAuthority($components) - { - $uriTokens = array(); - - if ($components->userinfo || $components->host || is_int($components->port)) { - if ($components->userinfo !== "") { - $uriTokens[] = preg_replace_callback(static::$regex['NOT_USERINFO'], array($this, 'pctEncChar'), $components->userinfo); - $uriTokens[] = "@"; - } - if ($components->host !== "") { - $uriTokens[] = preg_replace_callback(static::$regex['NOT_HOST'], array($this, 'pctEncChar'), strtolower($components->host)); - } - if (is_int($components->port)) { - $uriTokens[] = ":"; - $uriTokens[] = $components->port + 0; - } - } - - return count($uriTokens) ? implode('', $uriTokens) : null; - } - - /** - * @param {String} input - * @returns {String} - */ - - function removeDotSegments($input) { - $output = array(); - - while (strlen($input)) { - if (preg_match(static::$regex['RDS1'], $input)) { - $input = preg_replace(static::$regex['RDS1'], "", $input); - } elseif (preg_match(static::$regex['RDS2'], $input)) { - $input = preg_replace(static::$regex['RDS2'], "/", $input); - } elseif (preg_match(static::$regex['RDS3'], $input)) { - $input = preg_replace(static::$regex['RDS3'], "/", $input); - array_pop($output); - } elseif ($input === "." || $input === "..") { - $input = ""; - } else { - preg_match(static::$regex['RDS5'], $input, $matches); - $output[] = $matches[0]; - $input = substr($input, strlen($matches[0])); - if (!$input) { - $input = ''; - } - } - } - - return implode('', $output); - } - - /** - * @param {URIComponents} components - * @param {Options} options - * @returns {String} - */ - - function serialize(Components $components, Options $options = null) - { - $uriTokens = array(); - - if (null === $options) { - $options = $this->options; - } - - //check if a handler for the scheme exists - if (isset(static::$SCHEMES[$components->scheme ? $components->scheme : $options->scheme])) { - $schemeHandler = static::$SCHEMES[$components->scheme ? $components->scheme : $options->scheme]; - //perform extra serialization - $schemeHandler->serialize($components, $options); - } - - if ($options->reference !== "suffix" && $components->scheme) { - $uriTokens[] = preg_replace(static::$regex['NOT_SCHEME'], '', strtolower($components->scheme)); - $uriTokens[] = ':'; - } - - $components->authority = $this->_recomposeAuthority($components); - if ($components->authority !== null) { - if ($options->reference !== "suffix") { - $uriTokens[] = "//"; - } - - $uriTokens[] = $components->authority; - - if ($components->path && $components->path[0] !== "/") { - $uriTokens[] = "/"; - } - } - - if ($components->path) { - $s = $this->removeDotSegments(str_replace(array('%2E', '%2e'), '.', $components->path)); - - if ($components->scheme) { - $s = preg_replace_callback(static::$regex['NOT_PATH'], array($this, 'pctEncChar'), $s); - } else { - $s = preg_replace_callback(static::$regex['NOT_PATH_NOSCHEME'], array($this, 'pctEncChar'), $s); - } - - if ($components->authority === null) { - if (strlen($s) > 1 && $s[0] == '/' && $s[1] == '/') { - $s = '/%2F' . substr($s, 2); //don't allow the path to start with "//" - } - } - $uriTokens[] = $s; - } - - if ($components->query) { - $uriTokens[] = "?"; - $uriTokens[] = preg_replace_callback(static::$regex['NOT_QUERY'], array($this, 'pctEncChar'), $components->query); - } - - if ($components->fragment) { - $uriTokens[] = "#"; - $uriTokens[] = preg_replace_callback(static::$regex['NOT_FRAGMENT'], array($this, 'pctEncChar'), $components->fragment); - } - - return preg_replace_callback('/%[0-9A-Fa-f]{2}/', function ($matches) { //uppercase percent encoded characters - return strtoupper($matches[0]); - }, - preg_replace_callback( - static::$regex['PCT_ENCODEDS'], array($this, 'pctDecUnreserved'), - implode('', $uriTokens) - ) - ); - } - - /** - * @param {URIComponents} base - * @param {URIComponents} relative - * @param {Options} [options] - * @param {Boolean} [skipNormalization] - * @returns {URIComponents} - */ - - function resolveComponents(Components $base, Components $relative, Options $options = null, $skipNormalization = false) - { - $target = new Components(); - - if (!$skipNormalization) { - $base = $this->parse($this->serialize($base, $options), $options); //normalize base components - $relative = $this->parse($this->serialize($relative, $options), $options); //normalize relative components - } - if (null === $options) { - $options = $this->options; - } - - if (!$options->tolerant && $relative->scheme) { - $target->scheme = $relative->scheme; - $target->authority = $relative->authority; - $target->userinfo = $relative->userinfo; - $target->host = $relative->host; - $target->port = $relative->port; - $target->path = $this->removeDotSegments($relative->path); - $target->query = $relative->query; - } else { - if ($relative->authority) { - $target->authority = $relative->authority; - $target->userinfo = $relative->userinfo; - $target->host = $relative->host; - $target->port = $relative->port; - $target->path = $this->removeDotSegments($relative->path); - $target->query = $relative->query; - } else { - if (!$relative->path) { - $target->path = $base->path; - if ($relative->query) { - $target->query = $relative->query; - } else { - $target->query = $base->query; - } - } else { - if ($relative->path[0] === "/") { - $target->path = $this->removeDotSegments($relative->path); - } else { - if ($base->authority !== null && !$base->path) { - $target->path = "/" . $relative->path; - } else if (!$base->path) { - $target->path = $relative->path; - } else { - $target->path = substr($base->path, 0, strrpos($base->path, "/") + 1) . $relative->path; - } - $target->path = $this->removeDotSegments($target->path); - } - $target->query = $relative->query; - } - $target->authority = $base->authority; - $target->userinfo = $base->userinfo; - $target->host = $base->host; - $target->port = $base->port; - } - $target->scheme = $base->scheme; - } - - $target->fragment = $relative->fragment; - - return $target; - } - - /** - * @param {String} baseURI - * @param {String} relativeURI - * @param {Options} [options] - * @returns {String} - */ - - function resolve($baseURI, $relativeURI, Options $options = null) - { - return $this->serialize($this->resolveComponents($this->parse($baseURI, $options), - $this->parse($relativeURI, $options), $options, true), $options); - } - - /** - * @param {String|URIComponents} uri - * @param {Options} options - * @returns {String|URIComponents} - */ - - function normalize($uri, Options $options = null) - { - if (is_string($uri)) { - return $this->serialize($this->parse($uri, $options), $options); - } else if ($uri instanceof Components) { - return $this->parse($this->serialize($uri, $options), $options); - } - - return $uri; - } - - /** - * @param {String|URIComponents} uriA - * @param {String|URIComponents} uriB - * @param {Options} options - */ - - function equal($uriA, $uriB, Options $options = null) - { - if (is_string($uriA)) { - $uriA = $this->serialize($this->parse($uriA, $options), $options); - } else if ($uriA instanceof Components) { - $uriA = $this->serialize($uriA, $options); - } - - if (is_string($uriB)) { - $uriB = $this->serialize($this->parse($uriB, $options), $options); - } else if ($uriB instanceof Components) { - $uriB = $this->serialize($uriB, $options); - } - - return $uriA == $uriB; - } - - /** - * @param {String} str - * @returns {String} - */ - - function escapeComponent($str) - { - if (!$str) { - return ''; - } - return preg_replace_callback(static::$regex['ESCAPE'], array($this, 'pctEncChar'), $str); - } - - /** - * @param {String} str - * @returns {String} - */ - - function unescapeComponent($str) - { - if (!$str) { - return ''; - } - return preg_replace_callback(static::$regex['PCT_ENCODEDS'], array($this, 'pctDecChar'), $str); - } -} \ No newline at end of file diff --git a/lib/uri/UriCache.php b/lib/uri/UriCache.php deleted file mode 100644 index 61bb518..0000000 --- a/lib/uri/UriCache.php +++ /dev/null @@ -1,138 +0,0 @@ - '[A-Za-z]', - 'CR' => '[\\x0D]', - 'DIGIT' => '[0-9]', - 'DQUOTE' => '[\\x22]', - 'HEXDIG' => '[a-zA-Z0-9]', - 'LF' => '[\\x0A]', - 'SP' => '[\\x20]', - 'PCT_ENCODED' => '(?:%[a-zA-Z0-9][a-zA-Z0-9])', - 'GEN_DELIMS' => '[\\:\\/\\?\\#\\[\\]\\@]', - 'SUB_DELIMS' => '[\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=]', - 'H16' => '(?:[0-9a-fA-F]{1,4})', - 'PORT' => '(?:\\d*)', - 'URI_PARSE' => '/^(?:([^:\\/?#]+):)?(?:\\/\\/((?:([^\\/?#@]*)@)?([^\\/?#:]*)(?:\\:(\\d*))?))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?/i', - 'RDS1' => '/^\\.\\.?\\//', - 'RDS2' => '/^\\/\\.(\\/|$)/', - 'RDS3' => '/^\\/\\.\\.(\\/|$)/', - 'RDS4' => '/^\\.\\.?$/', - 'RDS5' => '/^\\/?.*?(?=\\/|$)/', - 'RESERVED' => '[\\:\\/\\?\\#\\[\\]\\@\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=]', - 'UNRESERVED' => '[A-Za-z0-9\\-\\.\\_\\~]', - 'UNRESERVED_SET' => - array ( - 'a' => 1, - 'A' => 1, - 'b' => 1, - 'B' => 1, - 'c' => 1, - 'C' => 1, - 'd' => 1, - 'D' => 1, - 'e' => 1, - 'E' => 1, - 'f' => 1, - 'F' => 1, - 'g' => 1, - 'G' => 1, - 'h' => 1, - 'H' => 1, - 'i' => 1, - 'I' => 1, - 'j' => 1, - 'J' => 1, - 'k' => 1, - 'K' => 1, - 'l' => 1, - 'L' => 1, - 'm' => 1, - 'M' => 1, - 'n' => 1, - 'N' => 1, - 'o' => 1, - 'O' => 1, - 'p' => 1, - 'P' => 1, - 'q' => 1, - 'Q' => 1, - 'r' => 1, - 'R' => 1, - 's' => 1, - 'S' => 1, - 't' => 1, - 'T' => 1, - 'u' => 1, - 'U' => 1, - 'v' => 1, - 'V' => 1, - 'w' => 1, - 'W' => 1, - 'x' => 1, - 'X' => 1, - 'y' => 1, - 'Y' => 1, - 'z' => 1, - 'Z' => 1, - "0" => 1, - "1" => 1, - "2" => 1, - "3" => 1, - "4" => 1, - "5" => 1, - "6" => 1, - "7" => 1, - "8" => 1, - "9" => 1, - '-' => 1, - '.' => 1, - '_' => 1, - '~' => 1, - ), - 'SCHEME' => '(?:[A-Za-z][A-Za-z0-9\\+\\-\\.]*)', - 'USERINFO' => '(?:(?:(?:%[a-zA-Z0-9][a-zA-Z0-9])|[A-Za-z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=\\:])*)', - 'DEC_OCTET' => '(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))', - 'IPV4ADDRESS' => '(?:(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))\\.(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))\\.(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))\\.(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])))', - 'LS32' => '(?:(?:(?:[0-9a-fA-F]{1,4})\\:(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))\\.(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))\\.(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))\\.(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))))', - 'IPV6ADDRESS' => '(?:[A-Za-z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=\\:]+)', - 'IPVFUTURE'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z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=]/', - 'NOT_HOST' => '/[^\\%A-Za-z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=]/', - 'NOT_PATH' => '/[^\\%\\/\\:\\@A-Za-z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=]/', - 'NOT_PATH_NOSCHEME' => '/[^\\%\\/\\@A-Za-z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=]/', - 'NOT_QUERY' => '/[^\\%A-Za-z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=\\:\\@\\/\\?]/', - 'NOT_FRAGMENT' => '/[^\\%A-Za-z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=\\:\\@\\/\\?]/', - 'ESCAPE' => '/[^A-Za-z0-9\\-\\.\\_\\~\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=]/', - 'UNRESERVEDREGEX' => '/[A-Za-z0-9\\-\\.\\_\\~]/', - 'OTHER_CHARS' => '/[^\\%A-Za-z0-9\\-\\.\\_\\~\\:\\/\\?\\#\\[\\]\\@\\!\\$\\&\\\'\\(\\)\\*\\+\\,\\;\\=]/', - 'PCT_ENCODEDS' => '/(?:%[a-zA-Z0-9][a-zA-Z0-9])+/', -);} \ No newline at end of file