1 | <?php |
||
21 | class DocumentUrlGenerator extends ProviderBasedGenerator implements VersatileGeneratorInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var array Route map configuration to map Elasticsearch types and Controllers. |
||
25 | */ |
||
26 | private $routeMap; |
||
27 | |||
28 | /** |
||
29 | * @var MetadataCollector |
||
30 | */ |
||
31 | private $collector; |
||
32 | |||
33 | /** |
||
34 | * @return mixed |
||
35 | */ |
||
36 | public function getRouteMap() |
||
40 | |||
41 | /** |
||
42 | * @param mixed $routeMap |
||
43 | */ |
||
44 | public function setRouteMap($routeMap) |
||
48 | |||
49 | /** |
||
50 | * @return MetadataCollector |
||
51 | */ |
||
52 | public function getCollector() |
||
56 | |||
57 | /** |
||
58 | * @param MetadataCollector $collector |
||
59 | */ |
||
60 | public function setCollector(MetadataCollector $collector) |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) |
||
69 | { |
||
70 | try { |
||
71 | $document = $name; |
||
72 | if ($document instanceof SeoAwareInterface) { |
||
73 | $documentUrl = $document->getUrl(); |
||
74 | } else { |
||
75 | throw new RouteNotFoundException(); |
||
76 | } |
||
77 | |||
78 | $type = $this->collector->getDocumentType(get_class($document)); |
||
79 | $route = new Route( |
||
80 | $documentUrl, |
||
81 | [ |
||
82 | '_controller' => $this->routeMap[$type], |
||
83 | 'document' => $document, |
||
84 | 'type' => $type, |
||
85 | ] |
||
86 | ); |
||
87 | |||
88 | // the Route has a cache of its own and is not recompiled as long as it does not get modified |
||
89 | $compiledRoute = $route->compile(); |
||
90 | $hostTokens = $compiledRoute->getHostTokens(); |
||
91 | |||
92 | $debug_message = $this->getRouteDebugMessage($name); |
||
93 | |||
94 | return $this->doGenerate( |
||
95 | $compiledRoute->getVariables(), |
||
96 | $route->getDefaults(), |
||
97 | $route->getRequirements(), |
||
98 | $compiledRoute->getTokens(), |
||
99 | $parameters, |
||
100 | $debug_message, |
||
101 | $referenceType, |
||
102 | $hostTokens |
||
103 | ); |
||
104 | |||
105 | } catch (\Exception $e) { |
||
106 | throw new RouteNotFoundException('Document is not correct or route cannot be generated.'); |
||
107 | } |
||
108 | } |
||
109 | /** |
||
110 | * @param mixed $name The route "name" which may also be an object or anything |
||
111 | * |
||
112 | * @return bool |
||
113 | * @throws RouteNotFoundException |
||
114 | */ |
||
115 | public function supports($name) |
||
122 | /** |
||
123 | * @param mixed $name |
||
124 | * @param array $parameters which should contain a content field containing |
||
125 | * a RouteReferrersReadInterface object |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getRouteDebugMessage($name, array $parameters = array()) |
||
136 | } |
||
137 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..