* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class SchemaManager implements SchemaManagerInterface { public const TYPE_TYPESCHEMA = 'typeschema'; public const TYPE_CLASS = 'class'; public const TYPE_ANNOTATION = 'annotation'; /** @deprecated */ public const TYPE_JSONSCHEMA = 'typeschema'; /** @var \PSX\Schema\Parser\Popo */ private $popoParser; /** @var \Psr\Cache\CacheItemPoolInterface */ private $cache; /** @var boolean */ private $debug; /** @var ImportResolver */ private $resolver; /** * @param \Doctrine\Common\Annotations\Reader|null $reader * @param \Psr\Cache\CacheItemPoolInterface|null $cache * @param boolean $debug * @param ImportResolver|null $resolver */ public function __construct( Reader $reader = null, CacheItemPoolInterface $cache = null, bool $debug = false, ?ImportResolver $resolver = null, ) { if ($reader === null) { $reader = new SimpleAnnotationReader(); $reader->addNamespace('PSX\\Schema\\Annotation'); } if ($resolver === null) { $resolver = ImportResolver::createDefault(new Client()); } $this->popoParser = new Parser\Popo($reader); $this->cache = $cache === null ? new Pool(new ArrayCache()) : $cache; $this->debug = $debug; $this->resolver = $resolver; } /** * @inheritdoc */ public function getSchema($schemaName, $type = null) { if (!is_string($schemaName)) { throw new InvalidArgumentException('Schema name must be a string'); } $item = null; if (!$this->debug) { $item = $this->cache->getItem($schemaName); if ($item->isHit()) { return $item->get(); } } if ($type === null) { $type = $this->guessTypeFromSchema($schemaName); } if ($type === self::TYPE_TYPESCHEMA) { $schema = Parser\TypeSchema::fromFile($schemaName, $this->resolver); } elseif ($type === self::TYPE_CLASS) { $schema = new $schemaName($this); } elseif ($type === self::TYPE_ANNOTATION) { $schema = $this->popoParser->parse($schemaName); } else { throw new InvalidSchemaException('Schema ' . $schemaName . ' does not exist'); } if (!$this->debug && $item !== null) { $schema = new Schema($schema->getType(), $schema->getDefinitions()); $item->set($schema); $this->cache->save($item); } return $schema; } /** * @param string $schemaName * @return string|null */ private function guessTypeFromSchema($schemaName) { if (strpos($schemaName, '.') !== false) { return self::TYPE_TYPESCHEMA; } elseif (class_exists($schemaName)) { if (in_array(SchemaInterface::class, class_implements($schemaName))) { return self::TYPE_CLASS; } else { return self::TYPE_ANNOTATION; } } else { return null; } } } __halt_compiler();----SIGNATURE:----wUmsrh5C8z7cOFojuRhhuX5MXlvCdwvB/YI27OTu6NgX0B07wSoqjhlzKSvKjif8ahz9uiUnAxqsy8xOwxfMNXWYv3L8e1BUoaYVASOxzFXvifWaRBoFL8eq1KXqJGpiZEwFXkvxHY15RgFdq4EMnA9h2iwJPlRtVoECEivaZ5prgLKDUnYig3Ax03+MPsTQmYA8FEuSyF94pRQ3s8nFQ6nD5L1sha3v0vUGMpAUH4G1MGlzztJWBmqZP6QZ5ZyZH1rFvMoSFcyosByFUbFHwJ4Gq616EjAffh1FAE5FPAYzvRLUEobBJm/VMRJ/GDWtCHECLkP81+T0FxVgdH808Gm8ltZh7IyWQt9nWXW4p7RTSKvFhjTou6VHJm6XCmE9kbBOVkyaQiSiZW1xGAn2lGMq5sCBFdLyxg1xV8dM4yvyTHItuk8OrwnKXt7FaDBwSuVN1VeHnXOYlXD40FhuL6w9Ru0bZWJ8VxAnMr4VGpIhQ7YCocwddcXEJ4YlZkPPOnoAQtkHRl7fwLys545KSk5qG+WQ3PXoxGaa9+LWojVupKuSsSHzyJflMOciJrwwAo8MHOc8EEwiRLnUTNWn3G7LTlVAhP+EK4bIP/SBWMG2SAgw2oWhtMGMxETOnl46DTcki2IMOvRyomSCdzSTNAetqDFw/jqBt8jhOoZRhgA=----ATTACHMENT:----MjY2MjQ5NjcwMjcwNDU1MSA3MDc0MDU2NjA2MzUzNTU1IDgxMTcyNDAzMjU3MjQzNzE=