These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of EC-CUBE |
||
5 | * |
||
6 | * Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
||
7 | * |
||
8 | * http://www.lockon.co.jp/ |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Eccube; |
||
15 | |||
16 | use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; |
||
17 | use Eccube\Common\EccubeNav; |
||
18 | use Eccube\Common\EccubeTwigBlock; |
||
19 | use Eccube\DependencyInjection\Compiler\AutoConfigurationTagPass; |
||
20 | use Eccube\DependencyInjection\Compiler\NavCompilerPass; |
||
21 | use Eccube\DependencyInjection\Compiler\PaymentMethodPass; |
||
22 | use Eccube\DependencyInjection\Compiler\PluginPass; |
||
23 | use Eccube\DependencyInjection\Compiler\PurchaseFlowPass; |
||
24 | use Eccube\DependencyInjection\Compiler\QueryCustomizerPass; |
||
25 | use Eccube\DependencyInjection\Compiler\TemplateListenerPass; |
||
26 | use Eccube\DependencyInjection\Compiler\TwigBlockPass; |
||
27 | use Eccube\DependencyInjection\Compiler\TwigExtensionPass; |
||
28 | use Eccube\DependencyInjection\Compiler\WebServerDocumentRootPass; |
||
29 | use Eccube\DependencyInjection\EccubeExtension; |
||
30 | use Eccube\Doctrine\DBAL\Types\UTCDateTimeType; |
||
31 | use Eccube\Doctrine\DBAL\Types\UTCDateTimeTzType; |
||
32 | use Eccube\Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
||
33 | use Eccube\Doctrine\Query\QueryCustomizer; |
||
34 | use Eccube\Service\Payment\PaymentMethodInterface; |
||
35 | use Eccube\Service\PurchaseFlow\ItemHolderPreprocessor; |
||
36 | use Eccube\Service\PurchaseFlow\ItemHolderValidator; |
||
37 | use Eccube\Service\PurchaseFlow\ItemPreprocessor; |
||
38 | use Eccube\Service\PurchaseFlow\ItemValidator; |
||
39 | use Eccube\Service\PurchaseFlow\PurchaseProcessor; |
||
40 | use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
||
41 | use Symfony\Component\Config\Loader\LoaderInterface; |
||
42 | use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
||
43 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
44 | use Symfony\Component\DependencyInjection\Definition; |
||
45 | use Symfony\Component\DependencyInjection\Reference; |
||
46 | use Symfony\Component\Finder\Finder; |
||
47 | use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
||
48 | use Symfony\Component\Routing\RouteCollectionBuilder; |
||
49 | |||
50 | class Kernel extends BaseKernel |
||
51 | { |
||
52 | use MicroKernelTrait; |
||
53 | |||
54 | const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
||
55 | |||
56 | 1238 | public function getCacheDir() |
|
57 | { |
||
58 | 1238 | return $this->getProjectDir().'/var/cache/'.$this->environment; |
|
59 | } |
||
60 | |||
61 | 13 | public function getLogDir() |
|
62 | { |
||
63 | 13 | return $this->getProjectDir().'/var/log'; |
|
64 | } |
||
65 | |||
66 | 1238 | public function registerBundles() |
|
67 | { |
||
68 | 1238 | $contents = require $this->getProjectDir().'/app/config/eccube/bundles.php'; |
|
69 | 1238 | foreach ($contents as $class => $envs) { |
|
70 | 1238 | if (isset($envs['all']) || isset($envs[$this->environment])) { |
|
71 | 1238 | yield new $class(); |
|
72 | } |
||
73 | } |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | * |
||
79 | * @see \Symfony\Component\HttpKernel\Kernel::boot() |
||
80 | */ |
||
81 | 1238 | public function boot() |
|
82 | { |
||
83 | // Symfonyがsrc/Eccube/Entity以下を読み込む前にapp/proxy/entity以下をロードする |
||
84 | 1238 | $this->loadEntityProxies(); |
|
85 | |||
86 | 1238 | parent::boot(); |
|
87 | |||
88 | // DateTime/DateTimeTzのタイムゾーンを設定. |
||
89 | 1238 | UTCDateTimeType::setTimeZone($this->container->getParameter('timezone')); |
|
90 | 1238 | UTCDateTimeTzType::setTimeZone($this->container->getParameter('timezone')); |
|
91 | date_default_timezone_set($this->container->getParameter('timezone')); |
||
0 ignored issues
–
show
|
|||
92 | |||
93 | 1238 | // Activate to $app |
|
94 | 1238 | $app = Application::getInstance(['debug' => $this->isDebug()]); |
|
95 | 1238 | $app->setParentContainer($this->container); |
|
96 | 1238 | $app->initialize(); |
|
97 | $app->boot(); |
||
98 | 1238 | ||
99 | $this->container->set('app', $app); |
||
100 | } |
||
101 | 1 | ||
102 | protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) |
||
103 | 1 | { |
|
104 | 1 | $confDir = $this->getProjectDir().'/app/config/eccube'; |
|
105 | 1 | $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob'); |
|
106 | 1 | if (is_dir($confDir.'/packages/'.$this->environment)) { |
|
107 | $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); |
||
108 | 1 | } |
|
109 | 1 | $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob'); |
|
110 | $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob'); |
||
111 | |||
112 | 1 | // プラグインのservices.phpをロードする. |
|
113 | 1 | $dir = dirname(__DIR__).'/../app/Plugin/*/Resource/config'; |
|
114 | $loader->load($dir.'/services'.self::CONFIG_EXTS, 'glob'); |
||
115 | } |
||
116 | 57 | ||
117 | protected function configureRoutes(RouteCollectionBuilder $routes) |
||
118 | 57 | { |
|
119 | $container = $this->getContainer(); |
||
120 | 57 | ||
121 | 57 | $forceSSL = $container->getParameter('eccube_force_ssl'); |
|
122 | 57 | $scheme = $forceSSL ? 'https' : 'http'; |
|
123 | $routes->setSchemes($scheme); |
||
124 | 57 | ||
125 | 57 | $confDir = $this->getProjectDir().'/app/config/eccube'; |
|
126 | 57 | if (is_dir($confDir.'/routes/')) { |
|
127 | 57 | $builder = $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob'); |
|
128 | $builder->setSchemes($scheme); |
||
129 | 57 | } |
|
130 | if (is_dir($confDir.'/routes/'.$this->environment)) { |
||
131 | $builder = $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
||
132 | $builder->setSchemes($scheme); |
||
133 | 57 | } |
|
134 | 57 | $builder = $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob'); |
|
135 | 57 | $builder->setSchemes($scheme); |
|
136 | 57 | $builder = $routes->import($confDir.'/routes_'.$this->environment.self::CONFIG_EXTS, '/', 'glob'); |
|
137 | $builder->setSchemes($scheme); |
||
138 | |||
139 | 57 | // 有効なプラグインのルーティングをインポートする. |
|
140 | 57 | $plugins = $container->getParameter('eccube.plugins.enabled'); |
|
141 | 57 | $pluginDir = $this->getProjectDir().'/app/Plugin'; |
|
142 | foreach ($plugins as $plugin) { |
||
143 | $dir = $pluginDir.'/'.$plugin.'/Controller'; |
||
144 | if (file_exists($dir)) { |
||
145 | $builder = $routes->import($dir, '/', 'annotation'); |
||
146 | $builder->setSchemes($scheme); |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | 1 | ||
151 | protected function build(ContainerBuilder $container) |
||
152 | 1 | { |
|
153 | $this->addEntityExtensionPass($container); |
||
154 | 1 | ||
155 | $container->registerExtension(new EccubeExtension()); |
||
156 | |||
157 | 1 | // サービスタグの自動設定を行う |
|
158 | $container->addCompilerPass(new AutoConfigurationTagPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 11); |
||
159 | |||
160 | // サービスタグの収集より先に実行し, 付与されているタグをクリアする. |
||
161 | // FormPassは優先度0で実行されているので, それより速いタイミングで実行させる. |
||
162 | 1 | // 自動登録されるタグやコンパイラパスの登録タイミングは, FrameworkExtension::load(), FrameworkBundle::build()を参考に. |
|
163 | $container->addCompilerPass(new PluginPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10); |
||
164 | |||
165 | 1 | // DocumentRootをルーティディレクトリに設定する. |
|
166 | $container->addCompilerPass(new WebServerDocumentRootPass('%kernel.project_dir%/')); |
||
167 | 1 | ||
168 | if ($this->environment !== 'install') { |
||
169 | 1 | // テンプレートフックポイントを動作させるように. |
|
170 | $container->addCompilerPass(new TemplateListenerPass()); |
||
171 | } |
||
172 | |||
173 | 1 | // twigのurl,path関数を差し替え |
|
174 | $container->addCompilerPass(new TwigExtensionPass()); |
||
175 | 1 | ||
176 | 1 | $container->register('app', Application::class) |
|
177 | 1 | ->setSynthetic(true) |
|
178 | ->setPublic(true); |
||
179 | |||
180 | 1 | // クエリカスタマイズの拡張. |
|
181 | 1 | $container->registerForAutoconfiguration(QueryCustomizer::class) |
|
182 | 1 | ->addTag(QueryCustomizerPass::QUERY_CUSTOMIZER_TAG); |
|
183 | $container->addCompilerPass(new QueryCustomizerPass()); |
||
184 | |||
185 | 1 | // 管理画面ナビの拡張 |
|
186 | 1 | $container->registerForAutoconfiguration(EccubeNav::class) |
|
187 | 1 | ->addTag(NavCompilerPass::NAV_TAG); |
|
188 | $container->addCompilerPass(new NavCompilerPass()); |
||
189 | |||
190 | 1 | // TwigBlockの拡張 |
|
191 | 1 | $container->registerForAutoconfiguration(EccubeTwigBlock::class) |
|
192 | 1 | ->addTag(TwigBlockPass::TWIG_BLOCK_TAG); |
|
193 | $container->addCompilerPass(new TwigBlockPass()); |
||
194 | |||
195 | 1 | // PaymentMethod の拡張 |
|
196 | 1 | $container->registerForAutoconfiguration(PaymentMethodInterface::class) |
|
197 | 1 | ->addTag(PaymentMethodPass::PAYMENT_METHOD_TAG); |
|
198 | $container->addCompilerPass(new PaymentMethodPass()); |
||
199 | |||
200 | 1 | // PurchaseFlow の拡張 |
|
201 | 1 | $container->registerForAutoconfiguration(ItemPreprocessor::class) |
|
202 | 1 | ->addTag(PurchaseFlowPass::ITEM_PREPROCESSOR_TAG); |
|
203 | 1 | $container->registerForAutoconfiguration(ItemValidator::class) |
|
204 | 1 | ->addTag(PurchaseFlowPass::ITEM_VALIDATOR_TAG); |
|
205 | 1 | $container->registerForAutoconfiguration(ItemHolderPreprocessor::class) |
|
206 | 1 | ->addTag(PurchaseFlowPass::ITEM_HOLDER_PREPROCESSOR_TAG); |
|
207 | 1 | $container->registerForAutoconfiguration(ItemHolderValidator::class) |
|
208 | 1 | ->addTag(PurchaseFlowPass::ITEM_HOLDER_VALIDATOR_TAG); |
|
209 | 1 | $container->registerForAutoconfiguration(PurchaseProcessor::class) |
|
210 | 1 | ->addTag(PurchaseFlowPass::PURCHASE_PROCESSOR_TAG); |
|
211 | $container->addCompilerPass(new PurchaseFlowPass()); |
||
212 | } |
||
213 | 1 | ||
214 | protected function addEntityExtensionPass(ContainerBuilder $container) |
||
215 | 1 | { |
|
216 | $projectDir = $container->getParameter('kernel.project_dir'); |
||
217 | |||
218 | 1 | // Eccube |
|
219 | 1 | $paths = ['%kernel.project_dir%/src/Eccube/Entity']; |
|
220 | 1 | $namespaces = ['Eccube\\Entity']; |
|
221 | 1 | $reader = new Reference('annotation_reader'); |
|
222 | 1 | $driver = new Definition(AnnotationDriver::class, [$reader, $paths]); |
|
223 | 1 | $driver->addMethodCall('setTraitProxiesDirectory', [$projectDir.'/app/proxy/entity']); |
|
224 | $container->addCompilerPass(new DoctrineOrmMappingsPass($driver, $namespaces, [])); |
||
225 | |||
226 | 1 | // Customize |
|
227 | 1 | $container->addCompilerPass(DoctrineOrmMappingsPass::createAnnotationMappingDriver( |
|
228 | 1 | ['Customize\\Entity'], |
|
229 | ['%kernel.project_dir%/app/Customize/Entity'] |
||
230 | )); |
||
231 | |||
232 | 1 | // Plugin |
|
233 | 1 | $pluginDir = $projectDir.'/app/Plugin'; |
|
234 | 1 | $finder = (new Finder()) |
|
235 | 1 | ->in($pluginDir) |
|
236 | 1 | ->sortByName() |
|
237 | 1 | ->depth(0) |
|
238 | 1 | ->directories(); |
|
239 | $plugins = array_map(function ($dir) { |
||
240 | return $dir->getBaseName(); |
||
241 | }, iterator_to_array($finder)); |
||
242 | |||
243 | foreach ($plugins as $code) { |
||
244 | 1238 | if (file_exists($pluginDir.'/'.$code.'/Entity')) { |
|
245 | $container->addCompilerPass(DoctrineOrmMappingsPass::createAnnotationMappingDriver( |
||
246 | 1238 | ['Plugin\\'.$code.'\\Entity'], |
|
247 | ['%kernel.project_dir%/app/Plugin/'.$code.'/Entity'] |
||
248 | )); |
||
249 | } |
||
250 | } |
||
251 | } |
||
252 | |||
253 | protected function loadEntityProxies() |
||
254 | { |
||
255 | foreach (glob(__DIR__.'/../../app/proxy/entity/*.php') as $file) { |
||
256 | require_once $file; |
||
257 | } |
||
258 | } |
||
259 | } |
||
260 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.