Skip to content

Commit

Permalink
DI: remove registerUniqueLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jan 10, 2025
1 parent 8c666fc commit f03f360
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/DI/AnnotationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
namespace Nettrine\Annotations\DI;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\Cache;
use Nette\DI\CompilerExtension;
use Nette\DI\Definitions\Statement;
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\Literal;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use stdClass;
Expand Down Expand Up @@ -42,12 +39,12 @@ public function loadConfiguration(): void
$builder = $this->getContainerBuilder();
$config = $this->config;

$readerDefinition = $builder->addDefinition($this->prefix('delegatedReader'))
$annotationReaderDef = $builder->addDefinition($this->prefix('annotationReader'))
->setFactory(AnnotationReader::class)
->setAutowired(false);

foreach ($config->ignore as $annotationName) {
$readerDefinition->addSetup('addGlobalIgnoredName', [$annotationName]);
$annotationReaderDef->addSetup('addGlobalIgnoredName', [$annotationName]);
AnnotationReader::addGlobalIgnoredName($annotationName);
}

Expand All @@ -62,18 +59,10 @@ public function loadConfiguration(): void
$builder->addDefinition($this->prefix('reader'))
->setType(Reader::class)
->setFactory(PsrCachedReader::class, [
$readerDefinition,
$annotationReaderDef,
$cacheDefinition,
$config->debug,
]);
}

public function afterCompile(ClassType $classType): void
{
$initialize = $classType->getMethod('initialize');
$original = $initialize->getBody();
$initialize->setBody('?::registerUniqueLoader("class_exists");' . "\n", [new Literal(AnnotationRegistry::class)]);
$initialize->addBody($original);
}

}

0 comments on commit f03f360

Please sign in to comment.