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