Skip to content

Commit

Permalink
rename ContainerConfigClassScanner to ClassScanner
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed May 24, 2024
1 parent 5acc9bf commit 1b8fa6f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
)
Expand All @@ -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,
Expand All @@ -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,
[
Expand Down
8 changes: 4 additions & 4 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Aura\Di\Resolver\Reflector;
use Composer\ClassMapGenerator\ClassMapGenerator;

class ContainerConfigClassScanner implements ContainerConfigInterface
class ClassScanner implements ContainerConfigInterface
{
/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
use Aura\Di\Resolver\Resolver;
use PHPUnit\Framework\TestCase;

class ContainerConfigClassScannerTest extends TestCase
class ClassScannerTest extends TestCase
{
/**
* @var ContainerConfigClassScanner
* @var ClassScanner
*/
protected $config;

protected function setUp(): void
{
parent::setUp();

$this->config = new ContainerConfigClassScanner(
$this->config = new ClassScanner(
[__DIR__ . '/Fake'],
['Aura\Di\Fake'],
);
Expand Down
2 changes: 1 addition & 1 deletion tests/ContainerBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
)
Expand Down

0 comments on commit 1b8fa6f

Please sign in to comment.