1 | <?php |
||
21 | class DefaultRouteGenerator implements RouteGeneratorInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var RouterInterface |
||
25 | */ |
||
26 | private $router; |
||
27 | |||
28 | /** |
||
29 | * @var RoutesCache |
||
30 | */ |
||
31 | private $cache; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private $caches = array(); |
||
37 | |||
38 | /** |
||
39 | * @var string[] |
||
40 | */ |
||
41 | private $loaded = array(); |
||
42 | |||
43 | /** |
||
44 | * @param RouterInterface $router |
||
45 | * @param RoutesCache $cache |
||
46 | */ |
||
47 | public function __construct(RouterInterface $router, RoutesCache $cache) |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function generate($name, array $parameters = array(), $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function generateUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function generateMenuUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) |
||
75 | { |
||
76 | // if the admin is a child we automatically append the parent's id |
||
77 | if ($admin->isChild() && $admin->hasRequest()) { |
||
78 | // twig template does not accept variable hash key ... so cannot use admin.idparameter ... |
||
79 | // switch value |
||
80 | if (isset($parameters['id'])) { |
||
81 | $parameters[$admin->getIdParameter()] = $parameters['id']; |
||
82 | unset($parameters['id']); |
||
83 | } |
||
84 | |||
85 | for ($parentAdmin = $admin->getParent(); null !== $parentAdmin; $parentAdmin = $parentAdmin->getParent()) { |
||
86 | $parameters[$parentAdmin->getIdParameter()] = $admin->getRequest()->attributes->get($parentAdmin->getIdParameter()); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | // if the admin is linked to a parent FieldDescription (ie, embedded widget) |
||
91 | if ($admin->hasParentFieldDescription()) { |
||
92 | // merge link parameter if any provided by the parent field |
||
93 | $parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', array())); |
||
94 | |||
95 | $parameters['uniqid'] = $admin->getUniqid(); |
||
96 | $parameters['code'] = $admin->getCode(); |
||
97 | $parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode(); |
||
98 | $parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid(); |
||
99 | } |
||
100 | |||
101 | if ($name == 'update' || substr($name, -7) == '|update') { |
||
102 | $parameters['uniqid'] = $admin->getUniqid(); |
||
103 | $parameters['code'] = $admin->getCode(); |
||
104 | } |
||
105 | |||
106 | // allows to define persistent parameters |
||
107 | if ($admin->hasRequest()) { |
||
108 | $parameters = array_merge($admin->getPersistentParameters(), $parameters); |
||
109 | } |
||
110 | |||
111 | $code = $this->getCode($admin, $name); |
||
112 | |||
113 | if (!array_key_exists($code, $this->caches)) { |
||
114 | throw new \RuntimeException(sprintf('unable to find the route `%s`', $code)); |
||
115 | } |
||
116 | |||
117 | return array( |
||
118 | 'route' => $this->caches[$code], |
||
119 | 'routeParameters' => $parameters, |
||
120 | 'routeAbsolute' => $absolute, |
||
121 | ); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function hasAdminRoute(AdminInterface $admin, $name) |
||
128 | { |
||
129 | return array_key_exists($this->getCode($admin, $name), $this->caches); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param AdminInterface $admin |
||
134 | * @param string $name |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | private function getCode(AdminInterface $admin, $name) |
||
139 | { |
||
140 | $this->loadCache($admin); |
||
141 | |||
142 | // someone provide the fullname |
||
143 | if (!$admin->isChild() && array_key_exists($name, $this->caches)) { |
||
144 | return $name; |
||
145 | } |
||
146 | |||
147 | $codePrefix = $admin->getBaseCodeRoute(); |
||
148 | |||
149 | // someone provide a code, so it is a child |
||
150 | if (strpos($name, '.')) { |
||
151 | return $codePrefix.'|'.$name; |
||
152 | } |
||
153 | |||
154 | return $codePrefix.'.'.$name; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @param AdminInterface $admin |
||
159 | */ |
||
160 | private function loadCache(AdminInterface $admin) |
||
174 | } |
||
175 |
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: