variations = $variations; } /** * @inheritDoc */ public function type(): string { return self::TYPE_AFTER_REF; } /** * @inheritDoc */ public function parse( SchemaInfo $info, \Opis\JsonSchema\Parsers\SchemaParser $parser, object $shared, ): ?\Opis\JsonSchema\Keyword { $ref = null; $recursive = false; $schema = $info->data(); $variation = null; if ($this->keywordExists($schema)) { $ref = $this->keywordValue($schema); if (!is_string($ref) || $ref === '') { throw $this->keywordException('{keyword} must be a non-empty string', $info); } } elseif ($this->variations) { foreach ($this->variations as $v) { if (!$this->keywordExists($schema, $v['ref'])) { continue; } $ref = $this->keywordValue($schema, $v['ref']); if ($v['fragment']) { if (!preg_match('/^#[a-z][a-z0-9\\-.:_]*/i', $ref)) { $this->keywordException("{keyword} value is malformed", $info, $v['ref']); } } elseif ($ref !== '#') { $this->keywordException("{keyword} supports only '#' as value", $info, $v['ref']); } $variation = $v; $recursive = true; break; } if (!$recursive) { return null; } } else { return null; } // Mappers $mapper = null; if ($parser->option('allowMappers') && property_exists($schema, '$map')) { if (!is_object($schema->{'$map'}) && !is_array($schema->{'$map'})) { throw $this->keywordException('$map keyword must be an object or an array', $info, '$map'); } if (!empty($schema->{'$map'})) { $mapper = $this->createVariables($parser, $schema->{'$map'}); } } // Globals $globals = null; if ($parser->option('allowGlobals') && property_exists($schema, '$globals')) { if (!is_object($schema->{'$globals'})) { throw $this->keywordException('$globals keyword must be an object', $info, '$globals'); } if (!empty($schema->{'$globals'})) { $globals = $this->createVariables($parser, $schema->{'$globals'}); } } // Pass slots $slots = null; if ($parser->option('allowSlots') && property_exists($schema, '$inject')) { $slots = $this->parseInjectedSlots($info, $parser, '$inject'); } if ($recursive) { $ref = $info->idBaseRoot()->resolveRef($ref); if ($variation['fragment']) { return new \Opis\JsonSchema\Keywords\RecursiveRefKeyword($ref->resolveRef('#'), $mapper, $globals, $slots, $variation['ref'], $variation['anchor'], $ref->fragment()); } return new \Opis\JsonSchema\Keywords\RecursiveRefKeyword($ref, $mapper, $globals, $slots, $variation['ref'], $variation['anchor'], true); } if ($ref === '#') { return new \Opis\JsonSchema\Keywords\URIRefKeyword(\Opis\JsonSchema\Uri::merge('#', $info->idBaseRoot()), $mapper, $globals, $slots, $this->keyword); } if ($parser->option('allowTemplates') && UriTemplate::isTemplate($ref)) { $tpl = new UriTemplate($ref); if ($tpl->hasPlaceholders()) { $vars = null; if (property_exists($schema, '$vars')) { if (!is_object($schema->{'$vars'})) { throw $this->keywordException('$vars keyword must be an object', $info, '$vars'); } if (!empty($schema->{'$vars'})) { $vars = $this->createVariables($parser, $schema->{'$vars'}); } } return new \Opis\JsonSchema\Keywords\TemplateRefKeyword( $tpl, $vars, $mapper, $globals, $slots, $this->keyword, $parser->option('allowRelativeJsonPointerInRef') ); } unset($tpl); } if ($ref[0] === '#') { if (($pointer = \Opis\JsonSchema\JsonPointer::parse(substr($ref, 1))) && $pointer->isAbsolute()) { return new \Opis\JsonSchema\Keywords\PointerRefKeyword($pointer, $mapper, $globals, $slots, $this->keyword); } } elseif ($parser->option('allowRelativeJsonPointerInRef') && ($pointer = \Opis\JsonSchema\JsonPointer::parse($ref)) && $pointer->isRelative()) { return new \Opis\JsonSchema\Keywords\PointerRefKeyword($pointer, $mapper, $globals, $slots, $this->keyword); } $ref = \Opis\JsonSchema\Uri::merge($ref, $info->idBaseRoot(), true); if ($ref === null || !$ref->isAbsolute()) { throw $this->keywordException('{keyword} must be a valid uri, uri-reference, uri-template or json-pointer', $info); } return new \Opis\JsonSchema\Keywords\URIRefKeyword($ref, $mapper, $globals, $slots, $this->keyword); } /** * @param SchemaInfo $info * @param SchemaParser $parser * @param string $keyword * @return string[]|object[]|Schema[] */ protected function parseInjectedSlots( SchemaInfo $info, \Opis\JsonSchema\Parsers\SchemaParser $parser, string $keyword, ): ?array { $schema = $info->data(); if (!is_object($schema->{$keyword})) { throw $this->keywordException('{keyword} keyword value must be an object', $info, $keyword); } return $this->getSlotSchemas($info, $parser, $schema->{$keyword}, [$keyword]); } /** * @param SchemaInfo $info * @param SchemaParser $parser * @param object $slots * @param array $path * @return null */ protected function getSlotSchemas( SchemaInfo $info, \Opis\JsonSchema\Parsers\SchemaParser $parser, object $slots, array $path, ): ?array { $keyword = null; if ($path) { $keyword = end($path); $path = array_merge($info->path(), $path); } else { $path = $info->path(); } $list = []; foreach ($slots as $name => $value) { if ($value === null) { continue; } if (is_string($value) || is_object($value)) { $list[$name] = $value; } elseif (is_bool($value)) { $list[$name] = $parser->parseSchema(new SchemaInfo( $value, null, $info->id() ?? $info->base(), $info->root(), array_merge($path, [$name]), $info->draft() ?? $parser->defaultDraftVersion() )); } else { throw $this->keywordException('Slots must contain valid json schemas or slot names', $info, $keyword); } } return $list ?: null; } } __halt_compiler();----SIGNATURE:----ADOYE0tRr5tb0WFAUcWpRQxuu9+OayB7o5iVdN0qo/uVChnhKEzsBj6q5Ddv0nMVjTxI5TCsNhZFhqJCRXPCUEM+EzzG2GocxQSM3Lu1H8Eua0sUHYPSFO2JICa5T0wJJ5P8e0votYTsN9gjBcB8UL6hh4IMLvIQCAsawEGkN4gae0noSL3VXPEkxP3bQCdHcCnlXtT6vhd+wITLsS02tsanHTYrvNC8jxEuJYvNMxYmAGkMO7dpXIakbb9tunc9OyGHEfbxOtjzOQiWu4QYMOwqqJvru54fxjRd5awTZ82qAZKqerTI0LBkDf5HPTtb0TY0MCPDHJs3pXKAkrWqNJbrvGfB7T2EUhge70S8EnXtCAhfnW8jzswHMIc1UxOp4NAZZmi93ceFULWymO1bnfmsZEu88zsmdICRda5P39VVtrLIscUz7dCsvy5mbfIYQsJHyMbZsRXx94rjM916DR6qrqkoIBLn8ic+JmkcaKASWYhqysno0YjGKeY7u7n4y+Jh3JqTNn87BFrVXEi4SfCwodqpn5dz+3DLE7r52czVvjWbr8XakcWzY1mnQOh+xkiV4a251ST7s+im8hDCK/ShB6vRApwH3pcXOJOf4BllbqjmduAY8jmHChnLiRl5AZgNUvnK10opwxeiwI7CKGD2QForddx2wd/TX/BbnAw=----ATTACHMENT:----NjU2MjYyMjI3ODMyNjQ3NyA1ODk5ODI1OTI2MTc0NzExIDgwNzYyNjA2NjM2NDgxODM=