13
13
use Prokl \ServiceProvider \Services \AppKernel ;
14
14
use Prokl \ServiceProvider \Utils \ErrorScreen ;
15
15
use Prokl \ServiceProvider \Utils \Loaders \PhpLoaderSettingsBitrix ;
16
+ use Psr \Container \ContainerExceptionInterface ;
16
17
use Psr \Container \ContainerInterface ;
17
18
use Psr \Container \ContainerInterface as PsrContainerInterface ;
19
+ use Psr \Container \NotFoundExceptionInterface ;
18
20
use RuntimeException ;
19
21
use Symfony \Bridge \ProxyManager \LazyProxy \PhpDumper \ProxyDumper ;
20
22
use Symfony \Component \Config \ConfigCache ;
@@ -85,7 +87,7 @@ class ServiceProvider
85
87
private const CONFIG_EXTS = '.{php,xml,yaml,yml} ' ;
86
88
87
89
/**
88
- * @var ContainerBuilder $containerBuilder Контейнер.
90
+ * @var ContainerBuilder|ContainerInterface $containerBuilder Контейнер.
89
91
*/
90
92
protected static $ containerBuilder ;
91
93
@@ -197,6 +199,7 @@ public function __construct(
197
199
198
200
$ this ->filename = $ filename ;
199
201
202
+ /** @psalm-suppress RedundantConditionGivenDocblockType */
200
203
if (static ::$ containerBuilder !== null ) {
201
204
return ;
202
205
}
@@ -231,10 +234,12 @@ public function get(string $id)
231
234
/**
232
235
* Контейнер.
233
236
*
234
- * @return ContainerInterface
237
+ * @return ContainerInterface|null
238
+ * @throws Exception Ошибки инициализации контейнера.
235
239
*/
236
- public function container () : ContainerInterface
240
+ public function container () : ? ContainerInterface
237
241
{
242
+ /** @psalm-suppress RedundantConditionGivenDocblockType */
238
243
return static ::$ containerBuilder ?: $ this ->initContainer ($ this ->filename );
239
244
}
240
245
@@ -270,6 +275,7 @@ public function reboot() : void
270
275
*/
271
276
public function shutdown () : void
272
277
{
278
+ /** @psalm-suppress DocblockTypeContradiction */
273
279
if (static ::$ containerBuilder === null ) {
274
280
return ;
275
281
}
@@ -340,15 +346,17 @@ private function boot() : void
340
346
*
341
347
* @param string $fileName Конфиг.
342
348
*
343
- * @return ContainerBuilder|Container
349
+ * @return ContainerBuilder|Container|ContainerInterface
344
350
* @throws Exception Ошибки контейнера.
351
+ * @throws ContainerExceptionInterface | NotFoundExceptionInterface Ошибки контейнера.
345
352
*
346
353
* @since 28.09.2020 Доработка.
347
354
*/
348
355
private function initContainer (string $ fileName )
349
356
{
350
357
// Если в dev режиме, то не компилировать контейнер.
351
358
if ((bool )$ _ENV ['DEBUG ' ] === true ) {
359
+ /** @psalm-suppress RedundantConditionGivenDocblockType */
352
360
if (static ::$ containerBuilder !== null ) {
353
361
return static ::$ containerBuilder ;
354
362
}
@@ -465,6 +473,7 @@ private function dumpContainer(ConfigCache $cache, ContainerBuilder $container,
465
473
$ asFiles = $ container ->getParameter ('container.dumper.inline_factories ' );
466
474
}
467
475
476
+ /** @psalm-suppress ArgumentTypeCoercion */
468
477
$ dumper = new PhpDumper (static ::$ containerBuilder );
469
478
if (class_exists (\ProxyManager \Configuration::class) && class_exists (ProxyDumper::class)) {
470
479
$ dumper ->setProxyDumper (new ProxyDumper ());
@@ -476,6 +485,7 @@ private function dumpContainer(ConfigCache $cache, ContainerBuilder $container,
476
485
'file ' => $ cache ->getPath (),
477
486
'as_files ' => $ asFiles ,
478
487
'debug ' => $ this ->debug ,
488
+ /** @psalm-suppress PossiblyUndefinedMethod */
479
489
'build_time ' => static ::$ containerBuilder ->hasParameter ('kernel.container_build_time ' )
480
490
? static ::$ containerBuilder ->getParameter ('kernel.container_build_time ' ) : time (),
481
491
'preload_classes ' => array_map ('get_class ' , $ this ->bundles ),
@@ -552,6 +562,7 @@ private function loadContainer(string $fileName)
552
562
$ this ->setDefaultParamsContainer ();
553
563
554
564
// Дополнить переменные приложения сведениями о зарегистрированных бандлах.
565
+ /** @psalm-suppress PossiblyNullReference */
555
566
static ::$ containerBuilder ->get ('kernel ' )->registerStandaloneBundles ();
556
567
557
568
// Инициализация автономных бандлов.
@@ -644,7 +655,7 @@ private function initialize(string $fileName): ?ContainerBuilder
644
655
$ this ->loadContainer ($ fileName );
645
656
646
657
$ this ->bundlesLoader ->registerExtensions (static ::$ containerBuilder );
647
-
658
+ /** @psalm-suppress PossiblyUndefinedMethod */
648
659
static ::$ containerBuilder ->compile (true );
649
660
650
661
// Boot bundles.
@@ -671,6 +682,7 @@ private function initialize(string $fileName): ?ContainerBuilder
671
682
*/
672
683
private function setDefaultParamsContainer () : void
673
684
{
685
+ /** @psalm-suppress PossiblyUndefinedMethod */
674
686
if (!static ::$ containerBuilder ->hasDefinition ('kernel ' )) {
675
687
$ this ->registerKernel ($ this ->kernelServiceClass );
676
688
}
@@ -813,7 +825,6 @@ private function runPostLoadingPasses(): void
813
825
/**
814
826
* Отсортировать по приоритету.
815
827
*
816
- * @psalm-suppress MissingClosureParamType
817
828
* @psalm-suppress InvalidScalarArgument
818
829
*/
819
830
usort ($ this ->postLoadingPassesBag , static function ($ a , $ b ) : bool {
0 commit comments