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

DomainBootloader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A domainCore() 0 15 3
A defineInterceptors() 0 3 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