* @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:----UTzj3AUfuYB1G4wpt4vVS4Hi9jNiQ3bgP0yZ76kkVjcPWIs5cXMruugXoizEDRxrZ65OpT5jZ5ZMOa0Zwu08rteD9kOGqQPIc34JndHOAVPdV9cBrIY50FmCh0AgDYA7ev+9GAC0RyHmLQ8mrh8kevgnPpQ85yVmjaK4x7n4dtbTOmmi1qBPRb70kPf5M1Vc/5I42uavMIb83uoglVPQ/ZwKoVYIakbTPW+WSMe1i+rxqLS6mUcG3ClzYsfiG4JKMhqIWjkxgqyatvC1mHx6rK1IKWnusm17y/A6Ynoq9T2FGNgdnMqcDUwpT/4MMG9Sblv1pUVW3tBJHMZ5TXZLeo02VhVwetSRy/8DTAL4ILn0h/XI9LNG1nXrYuNNjK+h4uxhhKmoG6zme1Y8q0Fu3HhBQzd++lpNsuPHxoi0A5FzF1z1I/vZF88TS5+343bhtcCtGm9MQoM3MVYs9uR2j9AnYh14WMv7fT/oGsZkkF6mmNA+ZRnd1ltjwD1fapi1Q/NLNAybJU9sf+IxWYi+feAzo9X2zksb1LCaFn8LtdhGp6D7HKZqGnv6mdSZ2fm3xyvufdlTiB26eC3/3INDPXD6elg4+ZxRvXiIIbXwnNt1eEcGffppPVYZJbmzyCV95s727ZaKOzdOAX0NZd1cxdQ/18IhkYegDJOIGkOuMWw=----ATTACHMENT:----Nzk0MTQ4ODU0NzM2OTY1NyA0NTMwMDM1MTIzNTYwMDM0IDUyMzc3ODY1NzMzMDg3NzE=