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

DomainBootloader::domainCore()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
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