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\UiBundle\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Config\FileLocator; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
19
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
20
|
|
|
use Zend\Stdlib\SplPriorityQueue; |
21
|
|
|
|
22
|
|
|
final class SyliusUiExtension extends Extension |
23
|
|
|
{ |
24
|
|
|
public function load(array $config, ContainerBuilder $container): void |
25
|
|
|
{ |
26
|
|
|
$config = $this->processConfiguration($this->getConfiguration([], $container), $config); |
|
|
|
|
27
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
28
|
|
|
|
29
|
|
|
$loader->load('services.xml'); |
30
|
|
|
|
31
|
|
|
$this->loadEvents($config['events'], $container); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @psalm-param array<string, array{blocks: array<string, array{template: string, priority: int, enabled: bool}>}> $eventsConfig |
36
|
|
|
*/ |
37
|
|
|
private function loadEvents(array $eventsConfig, ContainerBuilder $container): void |
38
|
|
|
{ |
39
|
|
|
$templateEventExtensionDefinition = $container->getDefinition('sylius.twig.extension.template_event'); |
40
|
|
|
|
41
|
|
|
$blocksForEvents = []; |
42
|
|
|
foreach ($eventsConfig as $eventName => $eventConfiguration) { |
43
|
|
|
$blocksPriorityQueue = new SplPriorityQueue(); |
44
|
|
|
|
45
|
|
|
foreach ($eventConfiguration['blocks'] as $blockName => $details) { |
46
|
|
|
if (!$details['enabled']) { |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$blocksPriorityQueue->insert($details['template'], $details['priority']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($blocksPriorityQueue->count() === 0) { |
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$blocksForEvents[$eventName] = $blocksPriorityQueue->toArray(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$templateEventExtensionDefinition->setArgument(1, $blocksForEvents); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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: