Skip to content

Commit 1f10317

Browse files
committed
Параметр kernel.bundles на проде.
1 parent 48cd8ce commit 1f10317

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/Services/AppKernel.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @since 22.10.2020 kernel.schema
1919
* @since 25.10.2020 Наследование от HttpKernel.
2020
* @since 13.12.2020 Создание директории кэша, если она не существует.
21+
* @since 27.01.2022 Баг-фикс с сохранением конфигурации бандлов в прод-режиме.
2122
*/
2223
class AppKernel extends Kernel
2324
{
@@ -29,7 +30,7 @@ class AppKernel extends Kernel
2930
/**
3031
* @var string $bundlesConfigFile Файл с конфигурацией бандлов.
3132
*/
32-
protected $bundlesConfigFile = '/local/configs/bundles.php';
33+
protected $bundlesConfigFile = '/local/configs/standalone_bundles.php';
3334

3435
/**
3536
* @var boolean $debug Отладка? Оно же служит для определения типа окружения.
@@ -238,8 +239,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
238239
* @return iterable|BundleInterface[]
239240
*
240241
* @since 02.06.2021 Если файл не существует - игнорим.
241-
*
242-
* @internal пока не используется. Манипуляции с бандлами - через класс BundlesLoader.
243242
*/
244243
public function registerBundles(): iterable
245244
{
@@ -249,7 +248,6 @@ public function registerBundles(): iterable
249248
return [];
250249
}
251250

252-
/* @noinspection PhpIncludeInspection */
253251
$contents = require $bundleConfigPath;
254252

255253
foreach ($contents as $class => $envs) {
@@ -267,7 +265,7 @@ public function registerBundles(): iterable
267265
* @return void
268266
* @throws LogicException Когда проскакивают дубликаты бандлов.
269267
*/
270-
public function registerBundle($bundle) : void
268+
public function registerBundle(object $bundle) : void
271269
{
272270
$name = $bundle->getName();
273271
if (isset($this->bundles[$name])) {
@@ -288,6 +286,19 @@ public function registerStandaloneBundles(): array
288286
{
289287
$bundles = BundlesLoader::getBundlesMap();
290288

289+
// Для регистрации kernel.bundles & kernel.bundles_meta в режиме прода.
290+
if (count($bundles) === 0) {
291+
$bundles = [];
292+
293+
if (file_exists($this->getProjectDir() . $this->bundlesConfigFile)) {
294+
$bundlesConfig = require $this->getProjectDir() . $this->bundlesConfigFile;
295+
296+
foreach ($bundlesConfig as $name => $itemBundle) {
297+
$bundles[$name] = new $name;
298+
}
299+
}
300+
}
301+
291302
foreach ($bundles as $bundle) {
292303
$this->registerBundle($bundle);
293304
}
@@ -362,8 +373,8 @@ private function getSchema() : string
362373
}
363374

364375
return array_key_exists('HTTPS', $_SERVER)
365-
&& ($_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] === 443)
366-
? 'https://' : 'http://';
376+
&& ($_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] === 443)
377+
? 'https://' : 'http://';
367378
}
368379

369380
/**
@@ -382,4 +393,4 @@ private function getHttpHost() : string
382393

383394
return (string)$_SERVER['HTTP_HOST'];
384395
}
385-
}
396+
}

0 commit comments

Comments
 (0)