* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class ApiManager implements ApiManagerInterface { const TYPE_ANNOTATION = 1; const TYPE_OPENAPI = 3; /** @var \Doctrine\Common\Annotations\Reader */ protected $reader; /** @var \PSX\Schema\SchemaManagerInterface */ protected $schemaManager; /** @var \PSX\Api\Parser\Annotation */ protected $parser; /** @var \Psr\Cache\CacheItemPoolInterface */ protected $cache; /** @var boolean */ protected $debug; /** * @param \Doctrine\Common\Annotations\Reader $reader * @param \PSX\Schema\SchemaManagerInterface $schemaManager * @param \Psr\Cache\CacheItemPoolInterface|null $cache * @param bool $debug */ public function __construct( Reader $reader, SchemaManagerInterface $schemaManager, CacheItemPoolInterface $cache = null, $debug = false, ) { $this->reader = $reader; $this->schemaManager = $schemaManager; $this->parser = new Parser\Annotation($reader, $schemaManager); $this->cache = $cache === null ? new Pool(new ArrayCache()) : $cache; $this->debug = $debug; } /** * @inheritdoc */ public function getApi(string $source, string $path, ?int $type = null): SpecificationInterface { $item = null; if (!$this->debug) { $item = $this->cache->getItem($source); if ($item->isHit()) { return $item->get(); } } if ($type === null) { $type = $this->guessTypeFromSource($source); } if ($type === self::TYPE_OPENAPI) { $api = OpenAPI::fromFile($source, $path); } elseif ($type === self::TYPE_ANNOTATION) { $api = $this->parser->parse($source, $path); } else { throw new \RuntimeException('Schema ' . $source . ' does not exist'); } if (!$this->debug && $item !== null) { $item->set($api); $this->cache->save($item); } return $api; } /** * @inheritDoc */ public function getBuilder(int $status, string $path): ResourceBuilderInterface { return new ResourceBuilder($this->schemaManager, $status, $path); } private function guessTypeFromSource($source): ?int { if (strpos($source, '.json') !== false) { return self::TYPE_OPENAPI; } elseif (class_exists($source)) { return self::TYPE_ANNOTATION; } else { return null; } } } __halt_compiler();----SIGNATURE:----KVOI4uxDvMB0eZMZGn39FKe7pX9mpDecQSATQQFrsIyQvCeZcroC8bbhJqIg1QiYHkye0054YtDqIzQae0Q2Xknz5UxnWoDbqkkem4pljuMOQMFMVLFtDZWT5V1AzntzP7UebxEe6z3IHuDHHFto+13ofXjaAiBbKGlSBaKnSVXCA0ceAzSdCAaRzIKNMtY4Y3NQfCa6jSfCxRUGqVNSvNBdj7C5TnYZUDfnNz7XCpe8AURz+ShJGoFLS7H7ye90VaizvCfUDvT0bjWd/8z2FekiW6JaT9HQ7otm9dkeIaHs8HRnzxdb89DmnBqolx5WiOSGRp7k2xCH20bSdtKo7AgfNdlp4Pg/H75x2byFv7h6zXQ6JPPxDXEoOm9z5pEMppYL07pEF+b3dm44+f1M/GDyoa4a9OVju2S+yVZF+TeqKwQl04JAKxZk0dWjFi6sze3gGyMwXoJNXltLQ2Wktt0e1OaHMx/F9upNVn8ANsW2hJpc6kVfMYMKgUiKCpNBrw2UxiHTyDDuZK6DNhI+8HoEll4y3PeibRtYG5P8E5iHGb1vlJCRZUnUB4gjIZpQro0WH2v9joYcP6n4Q8YqGJpChRspFV4rOr/HQQWbhKwPKuMNDc3YUv2VQimIGEzeaQDxbVBo0H5VAN9ORjMSVhN9Wdp7VCmiId+fvJVqkpM=----ATTACHMENT:----NTU1MTI0NzE4ODU3MzAwNCA4OTcwNjUwNjA3MDUzNDc2IDc2Mjc1NDA0MjIxOTg0MDI=