1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Menu\Provider; |
15
|
|
|
|
16
|
|
|
use Knp\Menu\ItemInterface; |
17
|
|
|
use Knp\Menu\Matcher\Matcher; |
18
|
|
|
|
19
|
|
|
// NEXT_MAJOR: Remove the else part when dropping support of knplabs/knp-menu 2.x |
20
|
|
|
if (!method_exists(Matcher::class, 'addVoter')) { |
21
|
|
|
/** |
22
|
|
|
* Menu provider based on group options. |
23
|
|
|
* |
24
|
|
|
* @final since sonata-project/admin-bundle 3.52 |
25
|
|
|
* |
26
|
|
|
* @author Alexandru Furculita <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class GroupMenuProvider extends BaseGroupMenuProvider |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Retrieves the menu based on the group options. |
32
|
|
|
* |
33
|
|
|
* @throws \InvalidArgumentException if the menu does not exists |
34
|
|
|
*/ |
35
|
|
|
public function get(string $name, array $options = []): ItemInterface |
36
|
|
|
{ |
37
|
|
|
return $this->doGet($name, $options); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function has(string $name, array $options = []): bool |
41
|
|
|
{ |
42
|
|
|
return $this->doHas($name, $options); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} else { |
46
|
|
|
/** |
47
|
|
|
* Menu provider based on group options. |
48
|
|
|
* |
49
|
|
|
* @final since sonata-project/admin-bundle 3.52 |
50
|
|
|
* |
51
|
|
|
* @author Alexandru Furculita <[email protected]> |
52
|
|
|
*/ |
53
|
|
|
class GroupMenuProvider extends BaseGroupMenuProvider |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
/** |
56
|
|
|
* Retrieves the menu based on the group options. |
57
|
|
|
* |
58
|
|
|
* @param string $name |
59
|
|
|
* |
60
|
|
|
* @throws \InvalidArgumentException if the menu does not exists |
61
|
|
|
* |
62
|
|
|
* @return \Knp\Menu\ItemInterface |
63
|
|
|
*/ |
64
|
|
|
public function get($name, array $options = []) |
65
|
|
|
{ |
66
|
|
|
return $this->doGet($name, $options); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Checks whether a menu exists in this provider. |
71
|
|
|
* |
72
|
|
|
* @param string $name |
73
|
|
|
* |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
|
|
public function has($name, array $options = []) |
77
|
|
|
{ |
78
|
|
|
return $this->doHas($name, $options); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This check looks for classes that have been defined more than once in the same file.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.