|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Spiral\Scaffolder\Declaration; |
|
6
|
|
|
|
|
7
|
|
|
use Nette\PhpGenerator\Literal; |
|
8
|
|
|
use Spiral\Boot\Bootloader\Bootloader; |
|
9
|
|
|
use Spiral\Boot\BootloadManager\Methods; |
|
10
|
|
|
use Spiral\Bootloader\DomainBootloader; |
|
11
|
|
|
use Spiral\Core\CoreInterface; |
|
12
|
|
|
use Spiral\Scaffolder\Config\ScaffolderConfig; |
|
13
|
|
|
|
|
14
|
|
|
class BootloaderDeclaration extends AbstractDeclaration |
|
15
|
|
|
{ |
|
16
|
|
|
public const TYPE = 'bootloader'; |
|
17
|
2 |
|
|
|
18
|
|
|
public function __construct( |
|
19
|
2 |
|
ScaffolderConfig $config, |
|
20
|
|
|
string $name, |
|
21
|
2 |
|
?string $comment = null, |
|
22
|
|
|
?string $namespace = null, |
|
23
|
2 |
|
private readonly bool $isDomain = false, |
|
24
|
2 |
|
) { |
|
25
|
2 |
|
parent::__construct($config, $name, $comment, $namespace); |
|
26
|
|
|
} |
|
27
|
2 |
|
|
|
28
|
2 |
|
/** |
|
29
|
|
|
* Declare constants and boot method. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function declare(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$extends = $this->isDomain ? DomainBootloader::class : Bootloader::class; |
|
34
|
|
|
|
|
35
|
|
|
$this->namespace->addUse($extends); |
|
36
|
|
|
$this->class->setExtends($extends); |
|
37
|
|
|
|
|
38
|
|
|
$this->class->setFinal(); |
|
39
|
|
|
|
|
40
|
|
|
$this->class->addConstant('BINDINGS', [])->setProtected(); |
|
41
|
|
|
$this->class->addConstant('SINGLETONS', [])->setProtected(); |
|
42
|
|
|
$this->class->addConstant('DEPENDENCIES', [])->setProtected(); |
|
43
|
|
|
|
|
44
|
|
|
if ($this->isDomain) { |
|
45
|
|
|
$this->class->addConstant('INTERCEPTORS', [])->setProtected(); |
|
46
|
|
|
$this->namespace->addUse(CoreInterface::class); |
|
47
|
|
|
$this->class->getConstant('SINGLETONS')->setValue([ |
|
48
|
|
|
new Literal('CoreInterface::class => [self::class, \'domainCore\']'), |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$this->class->addMethod(Methods::INIT->value)->setReturnType('void'); |
|
53
|
|
|
$this->class->addMethod(Methods::BOOT->value)->setReturnType('void'); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|