1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Menu Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2016 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\MenuBundle\Extension; |
18
|
|
|
|
19
|
|
|
use Knp\Menu\Factory\CoreExtension; |
20
|
|
|
use Knp\Menu\Factory\ExtensionInterface; |
21
|
|
|
use Knp\Menu\ItemInterface; |
22
|
|
|
|
23
|
|
|
class ExtensionChain implements ExtensionInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var \SplPriorityQueue|ExtensionInterface[] |
27
|
|
|
*/ |
28
|
|
|
private $extensions; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* ExtensionChain constructor. |
32
|
|
|
*/ |
33
|
12 |
|
public function __construct() |
34
|
|
|
{ |
35
|
12 |
|
$this->extensions = new \SplPriorityQueue(); |
36
|
12 |
|
$this->addExtension(new CoreExtension(), -20); |
37
|
12 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
12 |
|
public function buildOptions(array $options) |
43
|
|
|
{ |
44
|
12 |
|
foreach ($this->getExtensions() as $extension) { |
45
|
12 |
|
$options = $extension->buildOptions($options); |
46
|
|
|
} |
47
|
|
|
|
48
|
12 |
|
return $options; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
12 |
|
public function buildItem(ItemInterface $item, array $options) |
55
|
|
|
{ |
56
|
12 |
|
foreach ($this->getExtensions() as $extension) { |
57
|
12 |
|
$extension->buildItem($item, $options); |
58
|
|
|
} |
59
|
12 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
12 |
|
public function addExtension(ExtensionInterface $extension, int $priority = 0) |
65
|
|
|
{ |
66
|
12 |
|
$this->extensions->insert($extension, $priority); |
67
|
12 |
|
} |
68
|
|
|
|
69
|
12 |
|
private function getExtensions() |
70
|
|
|
{ |
71
|
12 |
|
return clone $this->extensions; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|