* @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:----TJRwQKPuFuyMjPqQRhBxpnzOdjGFrq4uNW66GHJ+R+W0m782+uI9b74WoqixcRrGQ1qTRUT9OmfYQ66z7Rz+pz96mzMjx2v0lZ3TLGKVeitelEhJtHZkRmyULRbskIfUIpoRx3uMPNxkqxU/KvJSfMBnN4PDjhQKU0uid6jvOpWWcUSxiotcXjUhDckPWrUuvm7dMLkiYEnjCyZwsn8W5gAcAD0+dkPN3Ip0VOlPZoIRQ5X+mZD62215ay5lfDpVhFm38O0/bYgDjRdbgHOHu5pOylhPhfprJbXQcwPt2HVd+G3ftT/l2AK7i+XPNlm51PBiQv97WgB5lgdv/gBCEngruw+lS4s0OQB6rWgyx8ysFfnBYIwxLWbCftIDUK+ngFf7P8synxFL1LJOc835oiGi/drRX5AW4LZIPKbMaZcsq7TagW8///m1iDoWVFEXyPkc9wS3JAAYhXyekAnYn4WWmWQ/fLSwwA7+PpEIDrh88MDylr6Gj/9cDcoIoKi8HFQKEkPjSz2N0En2mj8VdzZ4TGl7JyWHVSI8M3KZ/oyJ+UEdn7xLkm/Dg04dLoy0oiuZ0paxiLxIt8oGjj6/xYOClbxoh0WbMy17GhIozzSa7Zh6Kt0UD4/ZUJwKTcSr4Hm3ZIPylZFthK0uRMPmPCKTCo90hdlpUJE4FJn4oV8=----ATTACHMENT:----NTA2MzI1NDY1NTQzNzAwNyA2Mzg0NzQ3NjMwMDYzMDY2IDgwNjkwMjQ2Mzg4NDMyNzQ=