From dadfb10890713dd0411ea95a0dde06669c16c753 Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Fri, 8 Dec 2023 15:18:45 +0200 Subject: [PATCH] Change cache key --- README.md | 2 +- src/Bootloader/SwaggerBootloader.php | 4 ++-- src/Config/SwaggerConfig.php | 8 ++++---- src/Generator/Generator.php | 8 ++++---- src/Generator/Merger.php | 2 +- tests/src/Functional/Bootloader/SwaggerBootloaderTest.php | 2 +- tests/src/Unit/Config/SwaggerConfigTest.php | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3593753..23e8b60 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ return [ 'exclude' => null, 'pattern' => null, 'version' => null, - 'cache_item_id' => SwaggerConfig::DEFAULT_CACHE_ITEM_ID, + 'cache_key' => SwaggerConfig::DEFAULT_CACHE_KEY, 'generator_config' => [ 'operationId' => [ 'hash' => true, diff --git a/src/Bootloader/SwaggerBootloader.php b/src/Bootloader/SwaggerBootloader.php index e03521a..3f138f9 100644 --- a/src/Bootloader/SwaggerBootloader.php +++ b/src/Bootloader/SwaggerBootloader.php @@ -98,7 +98,7 @@ private function initConfig(DebugMode $debugMode, DirectoriesInterface $dirs): v 'exclude' => null, 'pattern' => null, 'version' => null, - 'cache_item_id' => SwaggerConfig::DEFAULT_CACHE_ITEM_ID, + 'cache_key' => SwaggerConfig::DEFAULT_CACHE_KEY, 'generator_config' => [ 'operationId' => [ 'hash' => true, @@ -150,7 +150,7 @@ private function initGenerator( CacheInterface $cache, SwaggerConfig $config ): GeneratorInterface { - return new Generator($registry, $config->getCacheItemId(), $config->useCache() ? $cache : null); + return new Generator($registry, $config->getCacheKey(), $config->useCache() ? $cache : null); } private function initOpenApiParser(SwaggerConfig $config): OpenApiParser diff --git a/src/Config/SwaggerConfig.php b/src/Config/SwaggerConfig.php index 2ae7201..31965ce 100644 --- a/src/Config/SwaggerConfig.php +++ b/src/Config/SwaggerConfig.php @@ -12,7 +12,7 @@ final class SwaggerConfig extends InjectableConfig { public const CONFIG = 'swagger'; - public const DEFAULT_CACHE_ITEM_ID = 'cache_item_id'; + public const DEFAULT_CACHE_KEY = 'swagger_docs'; protected array $config = [ 'documentation' => [ @@ -28,7 +28,7 @@ final class SwaggerConfig extends InjectableConfig 'exclude' => null, 'pattern' => null, 'version' => null, - 'cache_item_id' => self::DEFAULT_CACHE_ITEM_ID, + 'cache_key' => self::DEFAULT_CACHE_KEY, 'generator_config' => [ 'operationId' => [ 'hash' => true, @@ -85,9 +85,9 @@ public function getPattern(): ?string /** * @psalm-return non-empty-string */ - public function getCacheItemId(): string + public function getCacheKey(): string { - return $this->config['cache_item_id'] ?? self::DEFAULT_CACHE_ITEM_ID; + return $this->config['cache_key'] ?? self::DEFAULT_CACHE_KEY; } /** diff --git a/src/Generator/Generator.php b/src/Generator/Generator.php index 2d4e37d..492ed09 100644 --- a/src/Generator/Generator.php +++ b/src/Generator/Generator.php @@ -14,11 +14,11 @@ final class Generator implements GeneratorInterface { /** - * @psalm-param non-empty-string $cacheItemId + * @psalm-param non-empty-string $cacheKey */ public function __construct( private readonly ParserRegistryInterface $parsers, - private readonly string $cacheItemId, + private readonly string $cacheKey, private readonly ?CacheInterface $cache = null, ) { } @@ -28,7 +28,7 @@ public function __construct( */ public function generate(): OpenApi { - $item = $this->cache?->get($this->cacheItemId); + $item = $this->cache?->get($this->cacheKey); if (null !== $item) { return $item; } @@ -43,7 +43,7 @@ public function generate(): OpenApi $parser->parse($openApi, $analysis); } - $this->cache?->set($this->cacheItemId, $openApi); + $this->cache?->set($this->cacheKey, $openApi); return $openApi; } diff --git a/src/Generator/Merger.php b/src/Generator/Merger.php index 710da5f..a563e49 100644 --- a/src/Generator/Merger.php +++ b/src/Generator/Merger.php @@ -30,7 +30,7 @@ public static function merge( private static function mergeFromArray(AbstractAnnotation $annotation, array $properties, bool $overwrite): void { $done = []; - $defaults = get_class_vars(\get_class($annotation)); + $defaults = get_class_vars($annotation::class); foreach ($annotation::$_nested as $className => $propertyName) { if (\is_string($propertyName)) { diff --git a/tests/src/Functional/Bootloader/SwaggerBootloaderTest.php b/tests/src/Functional/Bootloader/SwaggerBootloaderTest.php index 3f45cf9..cf09c79 100644 --- a/tests/src/Functional/Bootloader/SwaggerBootloaderTest.php +++ b/tests/src/Functional/Bootloader/SwaggerBootloaderTest.php @@ -90,7 +90,7 @@ public function testDefaultConfigShouldBeDefined(): void 'exclude' => null, 'pattern' => null, 'version' => null, - 'cache_item_id' => SwaggerConfig::DEFAULT_CACHE_ITEM_ID, + 'cache_key' => SwaggerConfig::DEFAULT_CACHE_KEY, 'generator_config' => [ 'operationId' => [ 'hash' => true, diff --git a/tests/src/Unit/Config/SwaggerConfigTest.php b/tests/src/Unit/Config/SwaggerConfigTest.php index 4623874..7679524 100644 --- a/tests/src/Unit/Config/SwaggerConfigTest.php +++ b/tests/src/Unit/Config/SwaggerConfigTest.php @@ -81,11 +81,11 @@ public function testGetPattern(): void $this->assertSame('foo', $config->getPattern()); } - public function testGetCacheItemId(): void + public function testGetCacheKey(): void { - $config = new SwaggerConfig(['cache_item_id' => 'some']); + $config = new SwaggerConfig(['cache_key' => 'some']); - $this->assertSame('some', $config->getCacheItemId()); + $this->assertSame('some', $config->getCacheKey()); } public function testGetVersion(): void