\d\d)/schema#?~i'; const SUPPORTED_DRAFTS = ['06', '07']; const BASE_ID_PROP = '$_base_id'; const PATH_PROP = '$_path'; const VARS_PROP = '$vars'; const FILTERS_PROP = '$filters'; const FUNC_NAME = '$func'; const ID_PROP = '$id'; const MAP_PROP = '$map'; const WALK_IGNORE_PROPERTIES = [ 'default', 'const', 'enum', self::FILTERS_PROP, self::VARS_PROP, self::MAP_PROP ]; /** @var string */ protected $id; /** @var string */ protected $draft; /** @var array */ protected $internal = []; /** * Schema constructor. * @param \stdClass|boolean $data * @param string|null $id */ public function __construct($data, string $id = null) { if (is_object($data)) { if (property_exists($data, static::ID_PROP)) { $id = $data->{static::ID_PROP}; } } elseif (!is_bool($data)) { throw new InvalidSchemaException($data); } if ($id === null) { $id = uniqid("json-schema-id:/"); } $id = URI::merge($id, $id); if (substr($id, -1) !== '#') { throw new InvalidSchemaIdException($id); } $this->id = $id; if (is_object($data)) { if (!property_exists($data, '$schema')) { $data->{'$schema'} = 'http://json-schema.org/draft-07/schema#'; } elseif (!is_string($data->{'$schema'})) { throw new InvalidSchemaDraftException($data); } if (!preg_match(static::SCHEMA_REGEX, $data->{'$schema'}, $m)) { throw new InvalidSchemaDraftException($data); } $this->draft = $m['draft']; unset($m); if (!in_array($this->draft, static::SUPPORTED_DRAFTS)) { throw new SchemaDraftNotSupportedException($data, $this->draft); } $data->{static::ID_PROP} = $id; static::walk($this->internal, $data, $id); if (isset($data->{'$ref'}) && is_string($data->{'$ref'})) { $this->internal[$id] = $data; } } else { $this->internal[$id] = $data; } } /** * @inheritDoc */ public function id(): string { return $this->id; } /** * @inheritDoc */ public function draft(): string { return $this->draft; } /** * @inheritDoc */ public function resolve(string $id = null) { if ($id === null) { $id = $this->id; } return $this->internal[$id] ?? null; } /** * @param array $container * @param mixed $schema * @param string $id * @param array $path * @throws DuplicateSchemaException */ public static function walk(array &$container, &$schema, string $id, array $path = []) { if (is_array($schema)) { foreach ($schema as $name => &$value) { $path[] = $name; static::walk($container, $value, $id, $path); array_pop($path); unset($value); } return; } if (!is_object($schema)) { return; } $has_ref = isset($schema->{'$ref'}) && is_string($schema->{'$ref'}); if (isset($schema->{static::ID_PROP}) && is_string($schema->{static::ID_PROP})) { // Set the base id $schema->{static::BASE_ID_PROP} = $id; // Add current path $schema->{static::PATH_PROP} = $path; $id = URI::merge($schema->{static::ID_PROP}, $id); if (array_key_exists($id, $container)) { throw new DuplicateSchemaException($id, $schema, $container); } $container[$id] = $schema; // Do not process $ref if ($has_ref) { return; } } elseif ($has_ref) { // Set the base id $schema->{static::BASE_ID_PROP} = $id; // Add current path $schema->{static::PATH_PROP} = $path; // Do not process $ref return; } unset($has_ref); foreach ($schema as $name => &$value) { if (is_null($value) || is_scalar($value)) { continue; } if (in_array($name, static::WALK_IGNORE_PROPERTIES)) { continue; } $path[] = $name; static::walk($container, $value, $id, $path); array_pop($path); } } /** * @param string $json * @param string|null $id * @return Schema */ public static function fromJsonString(string $json, string $id = null): self { return new self(json_decode($json, false), $id); } }__halt_compiler();----SIGNATURE:----oM18LQw33RgWL1GMimr4x+BItvc0x55HmqIkhvHRMRE6rVpyBmi0wQiNCdc3ktW+m08GbgsmDBVw4S+ZVx4vOYCXj2xgYqXW4xrQGDm1NhIlxalZwAwbASI+NwWAGYXo3avGxa6dG20CADgizm5u/zT1VaTaHpzGdlIfyY9PRqZKPUjkVbe9hZjN0+RE3eQtBVZiMPYl9hbsmcoZ9e3FhOTFpXejEQ1TulmeVQxT76l6MLFL+L5ptcxkCA1Fj+mocorViaU+nZCYcCS3axEm/em8CesJoCOL8fgwe1VM/084inaA58tIV42aGHph1EkSZ7GH2Hjk0oG060I8xFv8uOvAmkrHCxtB9Xw9fuqglMSm3hQm72+STAmRABuOcPZIEwSoSO6Y7gP6aSI2VwowaMYitFfPM4/Ep41iPERf7mnTkf8E+Rty84WM777b0V+gI4bsaf5ARPatgvKpa9hhpvyXsNwcF3Z+/3sWQyGnC4zYyP+ZgWahG7VdFyrrHB5rkc95QfBsmdY4FR4DqI6gsyOKjOie1w7sX0j+BO6KINzAP4tHZb7pxZTaaXCGx/kvvZ2Dr1jYo3fjlPZlCYGtNyAeuWePo6oYQfT+hWpFmLhXASg/MDhNgNhZaWhqXBdBSZreLWwCNGhE3XjxNgulNAxhwscGEkTC/YrhEZawPWs=----ATTACHMENT:----NTYyNzUzNjQyNjQ2NjY2NiA1NTA3NDE4NzAwODkyNTA4IDY5NTAwOTg2ODM2MDE4MTI=