Passed
Push — master ( 9164c0...eba218 )
by butschster
08:19
created

DomainBootloader::defineInterceptors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Bootloader;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\EventDispatcher\EventDispatcherInterface;
9
use Spiral\Boot\Bootloader\Bootloader;
10
use Spiral\Core\Core;
11
use Spiral\Core\CoreInterceptorInterface;
12
use Spiral\Core\InterceptableCore;
13
14
/**
15
 * Configures global domain core (CoreInterface) with the set of interceptors to alter domain layer functionality.
16
 *
17
 * The CoreInterface binding must be complete in child implementation.
18
 */
19
abstract class DomainBootloader extends Bootloader
20
{
21
    // the set of interceptors for the domain code
22
    protected const INTERCEPTORS = [];
23
24 36
    protected static function domainCore(
25
        Core $core,
26
        ContainerInterface $container,
27
        ?EventDispatcherInterface $dispatcher = null
28
    ): InterceptableCore {
29 36
        $interceptableCore = new InterceptableCore($core, $dispatcher);
30
31 36
        foreach (static::defineInterceptors() as $interceptor) {
32 36
            if (!$interceptor instanceof CoreInterceptorInterface) {
33 36
                $interceptor = $container->get($interceptor);
34
            }
35 36
            $interceptableCore->addInterceptor($interceptor);
36
        }
37
38 36
        return $interceptableCore;
39
    }
40
41
    /**
42
     * Defines list of interceptors.
43
     */
44 36
    protected static function defineInterceptors(): array
45
    {
46 36
        return static::INTERCEPTORS;
47
    }
48
}
49