Completed
Pull Request — experimental/sf (#3393)
by chihiro
41:59
created

Kernel::getLogDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
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
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
51
{
52
    use MicroKernelTrait;
53
54
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
55
56 1280
    public function getCacheDir()
57
    {
58 1280
        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 1280
    public function registerBundles()
67
    {
68 1280
        $contents = require $this->getProjectDir().'/app/config/eccube/bundles.php';
69 1280
        foreach ($contents as $class => $envs) {
70 1280
            if (isset($envs['all']) || isset($envs[$this->environment])) {
71 1280
                yield new $class();
72
            }
73
        }
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     *
79
     * @see \Symfony\Component\HttpKernel\Kernel::boot()
80
     */
81 1280
    public function boot()
82
    {
83
        // Symfonyがsrc/Eccube/Entity以下を読み込む前にapp/proxy/entity以下をロードする
84 1280
        $this->loadEntityProxies();
85
86 1280
        parent::boot();
87
88
        // DateTime/DateTimeTzのタイムゾーンを設定.
89 1280
        UTCDateTimeType::setTimeZone($this->container->getParameter('timezone'));
0 ignored issues
show
Bug introduced by
The method getParameter cannot be called on $this->container (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
90 1280
        UTCDateTimeTzType::setTimeZone($this->container->getParameter('timezone'));
0 ignored issues
show
Bug introduced by
The method getParameter cannot be called on $this->container (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
91
92
        // Activate to $app
93 1280
        $app = Application::getInstance(['debug' => $this->isDebug()]);
94 1280
        $app->setParentContainer($this->container);
0 ignored issues
show
Documentation introduced by
$this->container is of type null, but the function expects a object<Psr\Container\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
95 1280
        $app->initialize();
96 1280
        $app->boot();
97
98 1280
        $this->container->set('app', $app);
0 ignored issues
show
Bug introduced by
The method set cannot be called on $this->container (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
99
    }
100
101 1
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
102
    {
103 1
        $confDir = $this->getProjectDir().'/app/config/eccube';
104 1
        $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
105 1
        if (is_dir($confDir.'/packages/'.$this->environment)) {
106 1
            $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
107
        }
108 1
        $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
109 1
        $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
110
111
        // プラグインのservices.phpをロードする.
112 1
        $dir = dirname(__DIR__).'/../app/Plugin/*/Resource/config';
113 1
        $loader->load($dir.'/services'.self::CONFIG_EXTS, 'glob');
114
    }
115
116 57
    protected function configureRoutes(RouteCollectionBuilder $routes)
117
    {
118 57
        $container = $this->getContainer();
119
120 57
        $forceSSL = $container->getParameter('eccube_force_ssl');
121 57
        $scheme = $forceSSL ? 'https' : 'http';
122 57
        $routes->setSchemes($scheme);
123
124 57
        $confDir = $this->getProjectDir().'/app/config/eccube';
125 57
        if (is_dir($confDir.'/routes/')) {
126 57
            $builder = $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
127 57
            $builder->setSchemes($scheme);
128
        }
129 57
        if (is_dir($confDir.'/routes/'.$this->environment)) {
130
            $builder = $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
131
            $builder->setSchemes($scheme);
132
        }
133 57
        $builder = $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
134 57
        $builder->setSchemes($scheme);
135 57
        $builder = $routes->import($confDir.'/routes_'.$this->environment.self::CONFIG_EXTS, '/', 'glob');
136 57
        $builder->setSchemes($scheme);
137
138
        // 有効なプラグインのルーティングをインポートする.
139 57
        $plugins = $container->getParameter('eccube.plugins.enabled');
140 57
        $pluginDir = $this->getProjectDir().'/app/Plugin';
141 57
        foreach ($plugins as $plugin) {
142
            $dir = $pluginDir.'/'.$plugin.'/Controller';
143
            if (file_exists($dir)) {
144
                $builder = $routes->import($dir, '/', 'annotation');
145
                $builder->setSchemes($scheme);
146
            }
147
        }
148
    }
149
150 1
    protected function build(ContainerBuilder $container)
151
    {
152 1
        $this->addEntityExtensionPass($container);
153
154 1
        $container->registerExtension(new EccubeExtension());
155
156
        // サービスタグの自動設定を行う
157 1
        $container->addCompilerPass(new AutoConfigurationTagPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 11);
158
159
        // サービスタグの収集より先に実行し, 付与されているタグをクリアする.
160
        // FormPassは優先度0で実行されているので, それより速いタイミングで実行させる.
161
        // 自動登録されるタグやコンパイラパスの登録タイミングは, FrameworkExtension::load(), FrameworkBundle::build()を参考に.
162 1
        $container->addCompilerPass(new PluginPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10);
163
164
        // DocumentRootをルーティディレクトリに設定する.
165 1
        $container->addCompilerPass(new WebServerDocumentRootPass('%kernel.project_dir%/'));
166
167 1
        if ($this->environment !== 'install') {
168
            // テンプレートフックポイントを動作させるように.
169 1
            $container->addCompilerPass(new TemplateListenerPass());
170
        }
171
172
        // twigのurl,path関数を差し替え
173 1
        $container->addCompilerPass(new TwigExtensionPass());
174
175 1
        $container->register('app', Application::class)
176 1
            ->setSynthetic(true)
177 1
            ->setPublic(true);
178
179
        // クエリカスタマイズの拡張.
180 1
        $container->registerForAutoconfiguration(QueryCustomizer::class)
181 1
            ->addTag(QueryCustomizerPass::QUERY_CUSTOMIZER_TAG);
182 1
        $container->addCompilerPass(new QueryCustomizerPass());
183
184
        // 管理画面ナビの拡張
185 1
        $container->registerForAutoconfiguration(EccubeNav::class)
186 1
            ->addTag(NavCompilerPass::NAV_TAG);
187 1
        $container->addCompilerPass(new NavCompilerPass());
188
189
        // TwigBlockの拡張
190 1
        $container->registerForAutoconfiguration(EccubeTwigBlock::class)
191 1
            ->addTag(TwigBlockPass::TWIG_BLOCK_TAG);
192 1
        $container->addCompilerPass(new TwigBlockPass());
193
194
        // PaymentMethod の拡張
195 1
        $container->registerForAutoconfiguration(PaymentMethodInterface::class)
196 1
            ->addTag(PaymentMethodPass::PAYMENT_METHOD_TAG);
197 1
        $container->addCompilerPass(new PaymentMethodPass());
198
199
        // PurchaseFlow の拡張
200 1
        $container->registerForAutoconfiguration(ItemPreprocessor::class)
201 1
            ->addTag(PurchaseFlowPass::ITEM_PREPROCESSOR_TAG);
202 1
        $container->registerForAutoconfiguration(ItemValidator::class)
203 1
            ->addTag(PurchaseFlowPass::ITEM_VALIDATOR_TAG);
204 1
        $container->registerForAutoconfiguration(ItemHolderPreprocessor::class)
205 1
            ->addTag(PurchaseFlowPass::ITEM_HOLDER_PREPROCESSOR_TAG);
206 1
        $container->registerForAutoconfiguration(ItemHolderValidator::class)
207 1
            ->addTag(PurchaseFlowPass::ITEM_HOLDER_VALIDATOR_TAG);
208 1
        $container->registerForAutoconfiguration(PurchaseProcessor::class)
209 1
            ->addTag(PurchaseFlowPass::PURCHASE_PROCESSOR_TAG);
210 1
        $container->addCompilerPass(new PurchaseFlowPass());
211
    }
212
213 1
    protected function addEntityExtensionPass(ContainerBuilder $container)
214
    {
215 1
        $projectDir = $container->getParameter('kernel.project_dir');
216
217
        // Eccube
218 1
        $paths = ['%kernel.project_dir%/src/Eccube/Entity'];
219 1
        $namespaces = ['Eccube\\Entity'];
220 1
        $reader = new Reference('annotation_reader');
221 1
        $driver = new Definition(AnnotationDriver::class, [$reader, $paths]);
222 1
        $driver->addMethodCall('setTraitProxiesDirectory', [$projectDir.'/app/proxy/entity']);
223 1
        $container->addCompilerPass(new DoctrineOrmMappingsPass($driver, $namespaces, []));
224
225
        // Customize
226 1
        $container->addCompilerPass(DoctrineOrmMappingsPass::createAnnotationMappingDriver(
227 1
            ['Customize\\Entity'],
228 1
            ['%kernel.project_dir%/app/Customize/Entity']
229
        ));
230
231
        // Plugin
232 1
        $pluginDir = $projectDir.'/app/Plugin';
233 1
        $finder = (new Finder())
234 1
            ->in($pluginDir)
235 1
            ->sortByName()
236 1
            ->depth(0)
237 1
            ->directories();
238 1
        $plugins = array_map(function ($dir) {
239 1
            return $dir->getBaseName();
240 1
        }, iterator_to_array($finder));
241
242 1
        foreach ($plugins as $code) {
243 1
            if (file_exists($pluginDir.'/'.$code.'/Entity')) {
244 1
                $container->addCompilerPass(DoctrineOrmMappingsPass::createAnnotationMappingDriver(
245 1
                    ['Plugin\\'.$code.'\\Entity'],
246 1
                    ['%kernel.project_dir%/app/Plugin/'.$code.'/Entity']
247
                ));
248
            }
249
        }
250
    }
251
252 1280
    protected function loadEntityProxies()
253
    {
254 1280
        foreach (glob(__DIR__.'/../../app/proxy/entity/*.php') as $file) {
255
            require_once $file;
256
        }
257
    }
258
}
259