|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Borobudur-Kernel package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Hexacodelabs <http://hexacodelabs.com> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Borobudur\Kernel\Bundling; |
|
12
|
|
|
|
|
13
|
|
|
use Borobudur\DependencyInjection\ContainerAwareTrait; |
|
14
|
|
|
use Borobudur\DependencyInjection\ContainerBuilder; |
|
15
|
|
|
use Borobudur\Kernel\Exception\RuntimeException; |
|
16
|
|
|
use Borobudur\Kernel\IdentifierTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Iqbal Maulana <[email protected]> |
|
20
|
|
|
* @created 8/7/15 |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractBundle implements BundleInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use IdentifierTrait, ContainerAwareTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var AbstractExtension[] |
|
28
|
|
|
*/ |
|
29
|
|
|
private $extensions = null; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get bundle extensions. |
|
33
|
|
|
* |
|
34
|
|
|
* @return AbstractExtension[]|null |
|
35
|
|
|
*/ |
|
36
|
|
|
final public function getContainerExtensions() |
|
37
|
|
|
{ |
|
38
|
|
|
if (null !== $extensions = $this->getBuiltExtensions()) { |
|
39
|
|
|
foreach ($extensions as $extension) { |
|
40
|
|
|
$this->assertInstanceOfExtension($extension); |
|
41
|
|
|
if (!is_array($this->extensions)) { |
|
42
|
|
|
$this->extensions = array(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->extensions[] = $extension; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $this->extensions; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function build(ContainerBuilder $container) |
|
56
|
|
|
{ |
|
57
|
|
|
// prepare for customize build bundle |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function boot() |
|
64
|
|
|
{ |
|
65
|
|
|
// customize boot |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
public function shutdown() |
|
72
|
|
|
{ |
|
73
|
|
|
// customize shutdown |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get extension definition. |
|
78
|
|
|
* |
|
79
|
|
|
* @return AbstractExtension[]|null |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function getExtensions() |
|
82
|
|
|
{ |
|
83
|
|
|
$name = str_replace('Bundle', '', $this->getName()); |
|
84
|
|
|
$class = sprintf('%s\Extension\%s', $this->getNamespace(), $name.'Extension'); |
|
85
|
|
|
|
|
86
|
|
|
if (class_exists($class)) { |
|
87
|
|
|
return array(new $class()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return null; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Assert that extension should instance of \Borobudur\Kernel\Bundling\AbstractExtension |
|
95
|
|
|
* |
|
96
|
|
|
* @param mixed $extension |
|
97
|
|
|
* |
|
98
|
|
|
* @throws RuntimeException |
|
99
|
|
|
*/ |
|
100
|
|
|
private function assertInstanceOfExtension($extension) |
|
101
|
|
|
{ |
|
102
|
|
|
if (false === $extension instanceof AbstractExtension) { |
|
103
|
|
|
throw new RuntimeException(sprintf( |
|
104
|
|
|
'Extension "%s" should implement Borobudur\Kernel\Bundling\AbstractExtension', |
|
105
|
|
|
get_class($extension) |
|
106
|
|
|
)); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Get built extensions. |
|
112
|
|
|
* |
|
113
|
|
|
* @return AbstractExtension[]|null |
|
114
|
|
|
*/ |
|
115
|
|
|
private function getBuiltExtensions() |
|
116
|
|
|
{ |
|
117
|
|
|
if (null === $this->extensions && null !== $extensions = $this->getExtensions()) { |
|
118
|
|
|
return $extensions; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return null; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|