Completed
Push — master ( 6366df...fbe022 )
by Kirill
23s queued 19s
created

AttributesBootloader::boot()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 16
rs 9.9666
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Bootloader;
13
14
use Psr\Cache\CacheItemInterface;
15
use Psr\SimpleCache\CacheInterface;
16
use Spiral\Attributes\Factory;
17
use Spiral\Attributes\ReaderInterface;
18
use Spiral\Boot\Bootloader\Bootloader;
19
use Spiral\Core\Container;
20
21
class AttributesBootloader extends Bootloader
22
{
23
    /**
24
     * @param Container $container
25
     */
26
    public function boot(Container $container): void
27
    {
28
        $container->bindSingleton(ReaderInterface::class, function () use ($container) {
29
            $factory = new Factory();
30
31
            if ($container->has(CacheInterface::class)) {
32
                $factory = $factory->withCache(
33
                    $container->get(CacheInterface::class)
34
                );
35
            } elseif ($container->has(CacheItemInterface::class)) {
36
                $factory = $factory->withCache(
37
                    $container->get(CacheItemInterface::class)
38
                );
39
            }
40
41
            return $factory->create();
42
        });
43
    }
44
}
45