diff --git a/composer.json b/composer.json index 3861714..f1672c3 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "egorov/yii2-annotations", - "version": "1.0.2", + "version": "1.0.3", "description": "Allows you to use doctrine/annotations in Yii2 projects", "type": "yii2-extension", "require": { diff --git a/src/Annotations.php b/src/Annotations.php index 69b31d6..0c2ddf6 100644 --- a/src/Annotations.php +++ b/src/Annotations.php @@ -1,7 +1,6 @@ registerLoader(); - $cacheComponent = $this->getCacheComponent(); - $this->configurationCache($cacheComponent); - $reader = new AnnotationReader(); - $this->configurationReader($reader); - $this->reader = new AnnotationCacheReader( - $reader, - new AnnotationCache($cacheComponent), - $this->debug - ); + $this->enableCacheComponent(); } /** @@ -76,16 +71,24 @@ public function init(): void */ public function getReader(): AnnotationCacheReader { - return $this->reader; + $this->enableNewReader(); + return new AnnotationCacheReader( + $this->reader, + new AnnotationCache($this->cacheComponent), + $this->debug + ); } /** - * @return object|CacheInterface + * @return void * @throws InvalidConfigException */ - private function getCacheComponent(): CacheInterface + private function enableCacheComponent(): void { - return (is_string($this->cache) ? Instance::ensure($this->cache) : $this->cache) ?? $this->getDefaultCache(); + $this->cacheComponent = (is_string($this->cache) + ? Instance::ensure($this->cache) + : $this->cache) ?? $this->getDefaultCache(); + $this->configurationCache(); } /** @@ -97,18 +100,21 @@ private function getDefaultCache() } /** - * @param $cacheComponent + * */ - private function configurationCache(CacheInterface $cacheComponent) + private function configurationCache() { - if (property_exists($cacheComponent, 'cachePath') && $this->path !== null) { - $cacheComponent->cachePath = Yii::getAlias($this->path); + if (property_exists($this->cacheComponent, 'cachePath') && $this->path !== null) { + $this->cacheComponent->cachePath = Yii::getAlias($this->path); } - if (property_exists($cacheComponent, 'cacheFileSuffix')) { - $cacheComponent->cacheFileSuffix = static::CACHE_PREFIX; + if (property_exists($this->cacheComponent, 'cacheFileSuffix')) { + $this->cacheComponent->cacheFileSuffix = static::CACHE_PREFIX; } } + /** + * + */ private function registerLoader() { if (method_exists(AnnotationRegistry::class, 'registerLoader')) { @@ -117,12 +123,13 @@ private function registerLoader() } /** - * @param $reader + * */ - private function configurationReader(AnnotationReader $reader) + private function enableNewReader() { + $this->reader = new AnnotationReader(); foreach ($this->ignoreAnnotations as $annotation) { - $reader::addGlobalIgnoredName($annotation); + $this->reader::addGlobalIgnoredName($annotation); } } }