Completed
Push — 1.2-sf-411 ( b05aee )
by Kamil
81:55 queued 65:43
created

Kernel::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
declare(strict_types=1);
13
14
namespace Sylius\Bundle\CoreBundle\Application;
15
16
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
17
use Symfony\Component\Config\Loader\DelegatingLoader;
18
use Symfony\Component\Config\Loader\LoaderInterface;
19
use Symfony\Component\Config\Loader\LoaderResolver;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\ContainerInterface;
22
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
23
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
24
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
25
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
26
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
27
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
28
use Symfony\Component\HttpKernel\Config\FileLocator;
29
use Symfony\Component\HttpKernel\Kernel as HttpKernel;
30
use Webmozart\Assert\Assert;
31
32
class Kernel extends HttpKernel
33
{
34
    public const VERSION = '1.2.1-DEV';
35
    public const VERSION_ID = '10201';
36
    public const MAJOR_VERSION = '1';
37
    public const MINOR_VERSION = '2';
38
    public const RELEASE_VERSION = '1';
39
    public const EXTRA_VERSION = 'DEV';
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function registerBundles(): array
45
    {
46
        $bundles = [
47
            new \Sylius\Bundle\OrderBundle\SyliusOrderBundle(),
48
            new \Sylius\Bundle\MoneyBundle\SyliusMoneyBundle(),
49
            new \Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle(),
50
            new \Sylius\Bundle\LocaleBundle\SyliusLocaleBundle(),
51
            new \Sylius\Bundle\ProductBundle\SyliusProductBundle(),
52
            new \Sylius\Bundle\ChannelBundle\SyliusChannelBundle(),
53
            new \Sylius\Bundle\AttributeBundle\SyliusAttributeBundle(),
54
            new \Sylius\Bundle\TaxationBundle\SyliusTaxationBundle(),
55
            new \Sylius\Bundle\ShippingBundle\SyliusShippingBundle(),
56
            new \Sylius\Bundle\PaymentBundle\SyliusPaymentBundle(),
57
            new \Sylius\Bundle\MailerBundle\SyliusMailerBundle(),
58
            new \Sylius\Bundle\PromotionBundle\SyliusPromotionBundle(),
59
            new \Sylius\Bundle\AddressingBundle\SyliusAddressingBundle(),
60
            new \Sylius\Bundle\InventoryBundle\SyliusInventoryBundle(),
61
            new \Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle(),
62
            new \Sylius\Bundle\UserBundle\SyliusUserBundle(),
63
            new \Sylius\Bundle\CustomerBundle\SyliusCustomerBundle(),
64
            new \Sylius\Bundle\UiBundle\SyliusUiBundle(),
65
            new \Sylius\Bundle\ReviewBundle\SyliusReviewBundle(),
66
            new \Sylius\Bundle\CoreBundle\SyliusCoreBundle(),
67
            new \Sylius\Bundle\ResourceBundle\SyliusResourceBundle(),
68
            new \Sylius\Bundle\GridBundle\SyliusGridBundle(),
69
            new \winzou\Bundle\StateMachineBundle\winzouStateMachineBundle(),
70
71
            new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
72
            new \Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(),
73
            new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
74
            new \Symfony\Bundle\MonologBundle\MonologBundle(),
75
            new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
76
            new \Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
77
            new \Symfony\Bundle\TwigBundle\TwigBundle(),
78
79
            new \Sonata\CoreBundle\SonataCoreBundle(),
80
            new \Sonata\BlockBundle\SonataBlockBundle(),
81
            new \Sonata\IntlBundle\SonataIntlBundle(),
82
            new \Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle(),
83
            new \JMS\SerializerBundle\JMSSerializerBundle(),
84
            new \FOS\RestBundle\FOSRestBundle(),
85
86
            new \Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(),
87
            new \Knp\Bundle\MenuBundle\KnpMenuBundle(),
88
            new \Liip\ImagineBundle\LiipImagineBundle(),
89
            new \Payum\Bundle\PayumBundle\PayumBundle(),
90
            new \Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
91
            new \WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
92
93
            new \Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
94
            new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
95
            new \Sylius\Bundle\FixturesBundle\SyliusFixturesBundle(),
96
            new \Sylius\Bundle\PayumBundle\SyliusPayumBundle(), // must be added after PayumBundle.
97
            new \Sylius\Bundle\ThemeBundle\SyliusThemeBundle(), // must be added after FrameworkBundle
98
99
            new \Symfony\Bundle\WebServerBundle\WebServerBundle(), // allows to run build in web server. Not recommended for prod environment
100
        ];
101
102
        if (in_array($this->getEnvironment(), ['dev', 'test', 'test_cached'], true)) {
103
            $bundles[] = new \Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
104
            $bundles[] = new \Symfony\Bundle\DebugBundle\DebugBundle();
105
            $bundles[] = new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
106
        }
107
108
        return $bundles;
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    protected function getContainerBaseClass(): string
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
115
    {
116
        if (in_array($this->getEnvironment(), ['test', 'test_cached'], true)) {
117
            return MockerContainer::class;
118
        }
119
120
        return parent::getContainerBaseClass();
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    protected function getContainerLoader(ContainerInterface $container): LoaderInterface
127
    {
128
        /** @var ContainerBuilder $container */
129
        Assert::isInstanceOf($container, ContainerBuilder::class);
130
131
        $locator = new FileLocator($this, $this->getRootDir() . '/Resources');
132
        $resolver = new LoaderResolver([
133
            new XmlFileLoader($container, $locator),
134
            new YamlFileLoader($container, $locator),
135
            new IniFileLoader($container, $locator),
136
            new PhpFileLoader($container, $locator),
137
            new DirectoryLoader($container, $locator),
138
            new ClosureLoader($container),
139
        ]);
140
141
        return new DelegatingLoader($resolver);
142
    }
143
144
    /**
145
     * {@inheritdoc}
146
     */
147
    public function registerContainerConfiguration(LoaderInterface $loader): void
148
    {
149
        $loader->load($this->getRootDir() . '/config/config_' . $this->getEnvironment() . '.yml');
150
151
        $file = $this->getRootDir() . '/config/config_' . $this->getEnvironment() . '.local.yml';
152
        if (is_file($file)) {
153
            $loader->load($file);
154
        }
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function getCacheDir(): string
161
    {
162
        if ($this->isVagrantEnvironment()) {
163
            return '/dev/shm/sylius/cache/' . $this->getEnvironment();
164
        }
165
166
        return dirname($this->getRootDir()) . '/var/cache/' . $this->getEnvironment();
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    public function getLogDir(): string
173
    {
174
        if ($this->isVagrantEnvironment()) {
175
            return '/dev/shm/sylius/logs';
176
        }
177
178
        return dirname($this->getRootDir()) . '/var/logs';
179
    }
180
181
    /**
182
     * @return bool
183
     */
184
    protected function isVagrantEnvironment(): bool
185
    {
186
        return (getenv('HOME') === '/home/vagrant' || getenv('VAGRANT') === 'VAGRANT') && is_dir('/dev/shm');
187
    }
188
}
189