Completed
Push — master ( 1bb63a...7d7bb8 )
by
unknown
05:45 queued 03:50
created

Bundle/SculpinBundle/HttpKernel/AbstractKernel.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is a part of Sculpin.
7
 *
8
 * (c) Dragonfly Development Inc.
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 Sculpin\Bundle\SculpinBundle\HttpKernel;
15
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\Config\Loader\LoaderInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
20
use Symfony\Component\HttpKernel\Kernel;
21
22
/**
23
 * @author Beau Simensen <[email protected]>
24
 */
25
abstract class AbstractKernel extends Kernel
26
{
27
    protected $missingSculpinBundles = [];
28
    protected $outputDir;
29
    protected $projectDir;
30
    protected $sourceDir;
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function __construct(string $environment, bool $debug, array $overrides = [])
36
    {
37
        $this->projectDir = $overrides['projectDir'] ?? null;
38
        $this->outputDir  = $overrides['outputDir']  ?? null;
39
        $this->sourceDir  = $overrides['sourceDir']  ?? null;
40
41
        if (null !== $this->projectDir) {
42
            $this->rootDir = $this->projectDir . '/app';
0 ignored issues
show
Deprecated Code introduced by
The property Symfony\Component\HttpKernel\Kernel::$rootDir has been deprecated with message: since Symfony 4.2

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
43
        }
44
45
        parent::__construct($environment, $debug);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected function getKernelParameters(): array
52
    {
53
        if (null === $this->projectDir) {
54
            $this->projectDir = dirname($this->rootDir);
0 ignored issues
show
Deprecated Code introduced by
The property Symfony\Component\HttpKernel\Kernel::$rootDir has been deprecated with message: since Symfony 4.2

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
55
        }
56
57
        return array_merge(parent::getKernelParameters(), [
58
            'sculpin.project_dir'         => $this->projectDir,
59
            'sculpin.output_dir_override' => $this->outputDir,
60
            'sculpin.source_dir_override' => $this->sourceDir,
61
        ]);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function registerBundles(): array
68
    {
69
        $bundles = [
70
            new \Sculpin\Bundle\StandaloneBundle\SculpinStandaloneBundle,
71
            new \Sculpin\Bundle\MarkdownBundle\SculpinMarkdownBundle,
72
            new \Sculpin\Bundle\TextileBundle\SculpinTextileBundle,
73
            new \Sculpin\Bundle\MarkdownTwigCompatBundle\SculpinMarkdownTwigCompatBundle,
74
            new \Sculpin\Bundle\PaginationBundle\SculpinPaginationBundle,
75
            new \Sculpin\Bundle\SculpinBundle\SculpinBundle,
76
            new \Sculpin\Bundle\ThemeBundle\SculpinThemeBundle,
77
            new \Sculpin\Bundle\TwigBundle\SculpinTwigBundle,
78
            new \Sculpin\Bundle\ContentTypesBundle\SculpinContentTypesBundle,
79
            new \Sculpin\Bundle\PostsBundle\SculpinPostsBundle,
80
        ];
81
82
        foreach ($this->getAdditionalSculpinBundles() as $class) {
83
            if (class_exists($class)) {
84
                $bundles[] = new $class();
85
            } else {
86
                $this->missingSculpinBundles[] = $class;
87
            }
88
        }
89
90
        return $bundles;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function registerContainerConfiguration(LoaderInterface $loader)
97
    {
98
        // Load defaults.
99
        $loader->load(__DIR__.'/../Resources/config/kernel.yml');
100
101
        if (file_exists($file = $this->rootDir.'/config/sculpin_kernel_'.$this->getEnvironment().'.yml')) {
0 ignored issues
show
Deprecated Code introduced by
The property Symfony\Component\HttpKernel\Kernel::$rootDir has been deprecated with message: since Symfony 4.2

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
102
            $loader->load($file);
103
        } elseif (file_exists($file = $this->rootDir.'/config/sculpin_kernel.yml')) {
0 ignored issues
show
Deprecated Code introduced by
The property Symfony\Component\HttpKernel\Kernel::$rootDir has been deprecated with message: since Symfony 4.2

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
104
            $loader->load($file);
105
        }
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function boot(): void
112
    {
113
        if (true === $this->booted) {
114
            return;
115
        }
116
117
        parent::boot();
118
119
        $this->container->compile();
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    protected function buildContainer(): ContainerBuilder
126
    {
127
        $container = $this->getContainerBuilder();
128
        $container->addObjectResource($this);
129
        $this->prepareContainer($container);
130
131
        if (file_exists($this->rootDir.'/config/sculpin_services.yml')) {
0 ignored issues
show
Deprecated Code introduced by
The property Symfony\Component\HttpKernel\Kernel::$rootDir has been deprecated with message: since Symfony 4.2

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
132
            $loader = new YamlFileLoader($container, new FileLocator($this->rootDir.'/config'));
0 ignored issues
show
Deprecated Code introduced by
The property Symfony\Component\HttpKernel\Kernel::$rootDir has been deprecated with message: since Symfony 4.2

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
133
            $loader->load('sculpin_services.yml');
134
        }
135
136
        if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
137
            $container->merge($cont);
138
        }
139
140
        return $container;
141
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146
    protected function initializeContainer(): void
147
    {
148
        $container = $this->buildContainer();
149
        $container->set('kernel', $this);
150
        $this->container = $container;
151
    }
152
153
    /**
154
     * Get Sculpin bundles that were requested but were not found
155
     *
156
     * This can happen if a bundle is requested but has not been required and
157
     * installed by Composer. Chances are this will lead to a lot of really bad
158
     * things. This should be checked early by any Console applications to
159
     * ensure that proper warnings are issued if there are any missing bundles
160
     * detected.
161
     *
162
     * @return array
163
     */
164
    public function getMissingSculpinBundles(): array
165
    {
166
        return $this->missingSculpinBundles;
167
    }
168
169
    /**
170
     * Get additional Sculpin bundles to register.
171
     *
172
     * @return string[] Fully qualified class names of the bundles to register.
173
     */
174
    abstract protected function getAdditionalSculpinBundles(): array;
175
}
176