|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the CMS Kernel package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2016-present LIN3S <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LIN3S\CMSKernel\Infrastructure\Symfony\Bundle; |
|
13
|
|
|
|
|
14
|
|
|
use LIN3S\CMSKernel\Infrastructure\Symfony\Bundle\DependencyInjection\Compiler\ClassMapTemplateFactoryPass; |
|
15
|
|
|
use LIN3S\CMSKernel\Infrastructure\Symfony\Bundle\DependencyInjection\Compiler\DoctrineORMCustomTypesPass; |
|
16
|
|
|
use LIN3S\CMSKernel\Infrastructure\Symfony\Bundle\DependencyInjection\Compiler\RegisterBusesPass; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
|
20
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author Beñat Espiña <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class Lin3sCmsKernelBundle extends Bundle |
|
26
|
|
|
{ |
|
27
|
|
|
const DEPENDENT_BUNDLES = [ |
|
28
|
|
|
'SimpleBusCommandBusBundle', |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
public function build(ContainerBuilder $container) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->checkDependentBundlesAreEnable($container); |
|
34
|
|
|
|
|
35
|
|
|
$container->addCompilerPass(new ClassMapTemplateFactoryPass(), PassConfig::TYPE_OPTIMIZE); |
|
36
|
|
|
$container->addCompilerPass(new DoctrineORMCustomTypesPass(), PassConfig::TYPE_OPTIMIZE); |
|
37
|
|
|
$container->addCompilerPass(new RegisterBusesPass(), PassConfig::TYPE_OPTIMIZE); |
|
38
|
|
|
|
|
39
|
|
|
$container->loadFromExtension('doctrine', [ |
|
40
|
|
|
'orm' => [ |
|
41
|
|
|
'mappings' => [ |
|
42
|
|
|
'Lin3sCmsKernelMenu' => [ |
|
43
|
|
|
'type' => 'xml', |
|
44
|
|
|
'is_bundle' => false, |
|
45
|
|
|
'dir' => $this->doctrineORMBasePath() . '/Menu/Mapping/', |
|
46
|
|
|
'prefix' => 'LIN3S\CMSKernel\Domain\Model\Menu', |
|
47
|
|
|
], |
|
48
|
|
|
'Lin3sCmsKernelPage' => [ |
|
49
|
|
|
'type' => 'xml', |
|
50
|
|
|
'is_bundle' => false, |
|
51
|
|
|
'dir' => $this->doctrineORMBasePath() . '/Page/Mapping/', |
|
52
|
|
|
'prefix' => 'LIN3S\CMSKernel\Domain\Model\Page', |
|
53
|
|
|
], |
|
54
|
|
|
'Lin3sCmsKernelSeo' => [ |
|
55
|
|
|
'type' => 'xml', |
|
56
|
|
|
'is_bundle' => false, |
|
57
|
|
|
'dir' => $this->doctrineORMBasePath() . '/Seo/Mapping/', |
|
58
|
|
|
'prefix' => 'LIN3S\CMSKernel\Domain\Model\Seo', |
|
59
|
|
|
], |
|
60
|
|
|
'Lin3sCmsKernelTranslation' => [ |
|
61
|
|
|
'type' => 'xml', |
|
62
|
|
|
'is_bundle' => false, |
|
63
|
|
|
'dir' => $this->doctrineORMBasePath() . '/Translation/Mapping/', |
|
64
|
|
|
'prefix' => 'LIN3S\CMSKernel\Domain\Model\Translation', |
|
65
|
|
|
], |
|
66
|
|
|
], |
|
67
|
|
|
], |
|
68
|
|
|
]); |
|
69
|
|
|
|
|
70
|
|
|
$container->loadFromExtension('twig', [ |
|
71
|
|
|
'paths' => [ |
|
72
|
|
|
$this->twigBasePath(), |
|
73
|
|
|
], |
|
74
|
|
|
'form_themes' => [ |
|
75
|
|
|
'Form/date_picker.html.twig', |
|
76
|
|
|
'Form/file.html.twig', |
|
77
|
|
|
'Form/menu_tree.html.twig', |
|
78
|
|
|
'Form/slug.html.twig', |
|
79
|
|
|
'Form/template_selector.html.twig', |
|
80
|
|
|
'Form/wysiwyg.html.twig', |
|
81
|
|
|
], |
|
82
|
|
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
private function checkDependentBundlesAreEnable(ContainerBuilder $container) |
|
86
|
|
|
{ |
|
87
|
|
|
$enabledBundles = $container->getParameter('kernel.bundles'); |
|
88
|
|
|
foreach (self::DEPENDENT_BUNDLES as $requiredBundle) { |
|
89
|
|
|
if (!isset($enabledBundles[$requiredBundle])) { |
|
90
|
|
|
throw new RuntimeException( |
|
91
|
|
|
sprintf( |
|
92
|
|
|
'In order to use "%s" you also need to enable and configure the "%s"', |
|
93
|
|
|
$this->getName(), |
|
|
|
|
|
|
94
|
|
|
$requiredBundle |
|
95
|
|
|
) |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
private function doctrineORMBasePath() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->basePath() . '/../../Persistence/Doctrine/ORM'; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
private function twigBasePath() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->basePath() . '/../../Ui/Templates/Twig'; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
private function basePath() |
|
112
|
|
|
{ |
|
113
|
|
|
return dirname((new \ReflectionClass(self::class))->getFileName()); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|