|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Loevgaard\SyliusBrandPlugin\Menu; |
|
6
|
|
|
|
|
7
|
|
|
use Knp\Menu\FactoryInterface; |
|
8
|
|
|
use Knp\Menu\ItemInterface; |
|
9
|
|
|
use Loevgaard\SyliusBrandPlugin\Event\BrandMenuBuilderEvent; |
|
10
|
|
|
use Loevgaard\SyliusBrandPlugin\Model\BrandInterface; |
|
11
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
12
|
|
|
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; |
|
13
|
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; |
|
14
|
|
|
|
|
15
|
|
|
final class BrandFormMenuBuilder |
|
16
|
|
|
{ |
|
17
|
|
|
public const EVENT_NAME = 'loevgaard_sylius_brand.menu.admin.brand.form'; |
|
18
|
|
|
|
|
19
|
|
|
/** @var FactoryInterface */ |
|
20
|
|
|
private $factory; |
|
21
|
|
|
|
|
22
|
|
|
/** @var EventDispatcherInterface */ |
|
23
|
|
|
private $eventDispatcher; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->factory = $factory; |
|
28
|
|
|
|
|
29
|
|
|
if (class_exists('Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy')) { |
|
30
|
|
|
/** |
|
31
|
|
|
* It could return null only if we pass null, but we pass not null in any case |
|
32
|
|
|
* |
|
33
|
|
|
* @var ContractsEventDispatcherInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
$eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function createMenu(array $options = []): ItemInterface |
|
42
|
|
|
{ |
|
43
|
|
|
$menu = $this->factory->createItem('root'); |
|
44
|
|
|
|
|
45
|
|
|
if (!array_key_exists('brand', $options) || !$options['brand'] instanceof BrandInterface) { |
|
46
|
|
|
return $menu; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$menu |
|
50
|
|
|
->addChild('details') |
|
51
|
|
|
->setAttribute('template', '@LoevgaardSyliusBrandPlugin/Admin/Brand/Tab/_details.html.twig') |
|
52
|
|
|
->setLabel('sylius.ui.details') |
|
53
|
|
|
->setCurrent(true) |
|
54
|
|
|
; |
|
55
|
|
|
|
|
56
|
|
|
$menu |
|
57
|
|
|
->addChild('media') |
|
58
|
|
|
->setAttribute('template', '@LoevgaardSyliusBrandPlugin/Admin/Brand/Tab/_media.html.twig') |
|
59
|
|
|
->setLabel('sylius.ui.media') |
|
60
|
|
|
; |
|
61
|
|
|
|
|
62
|
|
|
if (class_exists('Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy')) { |
|
63
|
|
|
$this->eventDispatcher->dispatch( |
|
64
|
|
|
new BrandMenuBuilderEvent($this->factory, $menu, $options['brand']), |
|
65
|
|
|
self::EVENT_NAME |
|
|
|
|
|
|
66
|
|
|
); |
|
67
|
|
|
} else { |
|
68
|
|
|
$this->eventDispatcher->dispatch( |
|
69
|
|
|
self::EVENT_NAME, |
|
|
|
|
|
|
70
|
|
|
new BrandMenuBuilderEvent($this->factory, $menu, $options['brand']) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $menu; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.