From 1b8fa6fc54bdbb044c8e30d57bbcfa228fa83467 Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Fri, 24 May 2024 14:36:06 +0200 Subject: [PATCH] rename ContainerConfigClassScanner to ClassScanner --- docs/attributes.md | 4 ++-- docs/config.md | 11 +++++++---- docs/getting-started.md | 8 ++++---- ...ntainerConfigClassScanner.php => ClassScanner.php} | 2 +- ...onfigClassScannerTest.php => ClassScannerTest.php} | 6 +++--- tests/ContainerBuilderTest.php | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) rename src/{ContainerConfigClassScanner.php => ClassScanner.php} (98%) rename tests/{ContainerConfigClassScannerTest.php => ClassScannerTest.php} (87%) diff --git a/docs/attributes.md b/docs/attributes.md index 4776f0b..0454af8 100644 --- a/docs/attributes.md +++ b/docs/attributes.md @@ -185,9 +185,9 @@ $di->params['Example']['foo'] = $di->lazyGetCall('config', 'get', 'alpha'); ## Modify the Container using attributes Modifying the container with attributes requires building the container with the -[`ContainerConfigClassScanner`](config.md#scan-for-classes-and-annotations). When done so, the builder will scan the +[`ClassScanner`](config.md#scan-for-classes-and-annotations). When done so, the builder will scan the passed directories for classes and annotations. Every attribute that implements the `AttributeConfigInterface` can modify the -container. See the [`ContainerConfigClassScanner` documentation](config.md#scan-for-classes-and-annotations) how to +container. See the [`ClassScanner` documentation](config.md#scan-for-classes-and-annotations) how to modify the container for external attributes. In the following example we create our own a `#[Route]` attribute that implements the `AttributeConfigInterface` and diff --git a/docs/config.md b/docs/config.md index 7e27579..e7f2319 100644 --- a/docs/config.md +++ b/docs/config.md @@ -160,7 +160,7 @@ $di->params[VendorClass::class] = [ ## Scan for classes and annotations -The `ContainerConfigClassScanner` scans the passed directories for classes and annotations. You will need that if you +The `ClassScanner` scans the passed directories for classes and annotations. You will need that if you want to [modify the container using attributes](attributes.md#modify-the-container-using-attributes). The classes inside the passed namespaces will be compiled into blueprints, making sure all the required meta-data is there to create an instance of the class. @@ -175,11 +175,14 @@ The following example demonstrates how to scan your project source files for ann controllers, services and repository classes into a blueprints. ```php +use Aura\Di\ClassScanner; +use Aura\Di\ContainerBuilder; + $builder = new ContainerBuilder(); $config_classes = [ new \MyApp\Config1, new \MyApp\Config2, - new ContainerConfigClassScanner( + new ClassScanner( [$rootDir . '/app/src'], // these directories should be scanned for classes and annotations ['MyApp\\Controller\\', 'MyApp\\Service\\', 'MyApp\\Repository\\'], // classes inside these namespaces should be compiled ) @@ -188,7 +191,7 @@ $config_classes = [ $di = $builder->newCompiledInstance($config_classes); ``` -When using the `ContainerConfigClassScanner`, make sure to serialize and cache the container output. If you do +When using the `ClassScanner`, make sure to serialize and cache the container output. If you do not do that, directories will be scanned every instance of the container. If your attribute cannot implement the `AttributeConfigInterface`, e.g. the attribute is defined in an external package, @@ -197,7 +200,7 @@ you can pass a map with the class name of the attribute and an implementation of ```php use Aura\Di\AttributeConfigInterface; -new ContainerConfigClassScanner( +new ClassScanner( [$rootDir . '/app/src'], // these directories should be scanned for classes and annotations ['MyApp\\'], // classes inside these namespaces should be compiled, [ diff --git a/docs/getting-started.md b/docs/getting-started.md index 7dd6ef6..c4c9d02 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -67,25 +67,25 @@ A full-featured container can use [attributes](attributes.md) for injection and maximum performance, we would have to compile the container, serialize it and save it to a cache layer like the filesystem. Subsequent processes would only have to unserialize to have a compiled container. -The `ContainerConfigClassScanner` scans for classes and annotations inside your project. This does require, +The `ClassScanner` scans for classes and annotations inside your project. This does require, however, to add a package to your dependencies. ```sh composer require composer/class-map-generator ``` -Creating a fully-featured container could look as follows: +Creating a fully-featured container could look as follows: ```php use Aura\Di\ContainerBuilder; -use Aura\Di\ContainerConfigClassScanner; +use Aura\Di\ClassScanner; use Aura\Di\Resolver\ResolverFactory; $serializedContainerFile = '/var/compiled.ser'; $config_classes = [ new \MyApp\Config1, new \MyApp\Config2, - new ContainerConfigClassScanner( + new ClassScanner( [$rootDir . '/app/src'], // these directories should be scanned for classes and annotations ['MyApp\\'], // classes inside these namespaces should be compiled ) diff --git a/src/ContainerConfigClassScanner.php b/src/ClassScanner.php similarity index 98% rename from src/ContainerConfigClassScanner.php rename to src/ClassScanner.php index 5023fcb..d45dbbd 100644 --- a/src/ContainerConfigClassScanner.php +++ b/src/ClassScanner.php @@ -7,7 +7,7 @@ use Aura\Di\Resolver\Reflector; use Composer\ClassMapGenerator\ClassMapGenerator; -class ContainerConfigClassScanner implements ContainerConfigInterface +class ClassScanner implements ContainerConfigInterface { /** * diff --git a/tests/ContainerConfigClassScannerTest.php b/tests/ClassScannerTest.php similarity index 87% rename from tests/ContainerConfigClassScannerTest.php rename to tests/ClassScannerTest.php index f8af492..3f6dcf3 100644 --- a/tests/ContainerConfigClassScannerTest.php +++ b/tests/ClassScannerTest.php @@ -6,10 +6,10 @@ use Aura\Di\Resolver\Resolver; use PHPUnit\Framework\TestCase; -class ContainerConfigClassScannerTest extends TestCase +class ClassScannerTest extends TestCase { /** - * @var ContainerConfigClassScanner + * @var ClassScanner */ protected $config; @@ -17,7 +17,7 @@ protected function setUp(): void { parent::setUp(); - $this->config = new ContainerConfigClassScanner( + $this->config = new ClassScanner( [__DIR__ . '/Fake'], ['Aura\Di\Fake'], ); diff --git a/tests/ContainerBuilderTest.php b/tests/ContainerBuilderTest.php index 196f778..c6738ed 100644 --- a/tests/ContainerBuilderTest.php +++ b/tests/ContainerBuilderTest.php @@ -168,7 +168,7 @@ public function testCompilationSerialization() new \Aura\Di\Fake\FakeLibraryConfig, new \Aura\Di\Fake\FakeProjectConfig, new \Aura\Di\Fake\FakeCompilationTestConfig(), - new ContainerConfigClassScanner( + new ClassScanner( [__DIR__ . '/Fake'], ['Aura\Di\Fake'], )