66use Symfony \Component \Routing \RouterInterface ;
77use Symfony \Component \Routing \RequestContext ;
88use Symfony \Component \Routing \Exception \RouteNotFoundException ;
9- use Doctrine \Common \Persistence \ObjectManager ;
9+ use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
10+ use Symfony \Component \Routing \RouteCollection ;
11+
1012use Symfony \Cmf \Bundle \ChainRoutingBundle \Resolver \ControllerResolverInterface ;
1113
14+ use Doctrine \Common \Persistence \ObjectManager ;
15+
1216/**
1317 * A router that reads entries from a Object-Document Mapper store.
1418 *
@@ -30,11 +34,13 @@ class DoctrineRouter implements RouterInterface
3034 * route has one associated
3135 */
3236 const CONTENT_KEY = 'contentDocument ' ;
37+
3338 /**
3439 * key for the request attribute that contains the template this document
3540 * wants to use
3641 */
3742 const CONTENT_TEMPLATE = 'contentTemplate ' ;
43+
3844 protected $ om ;
3945 protected $ resolvers ;
4046 protected $ routeClass ;
@@ -70,12 +76,17 @@ public function addControllerResolver(ControllerResolverInterface $resolver)
7076 $ this ->resolvers [] = $ resolver ;
7177 }
7278
73- // inherit doc
79+ /**
80+ * {@inheritDoc}
81+ */
7482 public function setContext (RequestContext $ context )
7583 {
7684 $ this ->context = $ context ;
7785 }
78- // inherit doc
86+
87+ /**
88+ * {@inheritDoc}
89+ */
7990 public function getContext ()
8091 {
8192 return $ this ->context ;
@@ -130,11 +141,13 @@ public function generate($name, $parameters = array(), $absolute = false)
130141 public function getRouteCollection ()
131142 {
132143 /* TODO */
133- return new \ Symfony \ Component \ Routing \ RouteCollection ();
144+ return new RouteCollection ();
134145 }
135146
136147 /**
137148 * Set the doctrine entity or document manager that will know the urls
149+ *
150+ * @param ObjectManager $om
138151 */
139152 public function setObjectManager (ObjectManager $ om )
140153 {
@@ -154,19 +167,19 @@ public function setObjectManager(ObjectManager $om)
154167 * cases, the action to call on that controller is appended, separated with
155168 * two colons.
156169 *
157- * @throws ResourceNotFoundException If the requested url does not exist in the ODM
158- * @throws MethodNotAllowedException If the resource was found but the request method is not allowed
159- *
160170 * @param string $url the full requested url. TODO: is locale eaten away or kept too?
161171 *
162172 * @return array as described above
173+ *
174+ * @throws ResourceNotFoundException If the requested url does not exist in the ODM
175+ * @throws MethodNotAllowedException If the resource was found but the request method is not allowed
163176 */
164177 public function match ($ url )
165178 {
166179 $ route = $ this ->findRouteForUrl ($ url );
167180
168181 if (! $ route instanceof RouteObjectInterface) {
169- throw new \ Symfony \ Component \ Routing \ Exception \ ResourceNotFoundException ("No entry or not a route at ' $ url' " );
182+ throw new ResourceNotFoundException ("No entry or not a route at ' $ url' " );
170183 }
171184
172185 $ defaults = $ route ->getRouteDefaults ();
@@ -178,14 +191,14 @@ public function match($url)
178191 if ($ controller !== false ) break ;
179192 }
180193 if (false === $ controller ) {
181- throw new \ Symfony \ Component \ Routing \ Exception \ ResourceNotFoundException ("The resolver was not able to determine a controller for ' $ url' " );;
194+ throw new ResourceNotFoundException ("The resolver was not able to determine a controller for ' $ url' " );;
182195 }
183196 $ defaults ['_controller ' ] = $ controller ;
184197 }
185198
186199 $ defaults [self ::CONTENT_KEY ] = $ route ->getRouteContent ();
187200 $ defaults ['path ' ] = $ url ; // TODO: get rid of this
188- $ defaults ['_route ' ] = 'whatever ' ; //FIXME: what is this? without, we get an undefined index in RouterListener::onKernelRequest
201+ $ defaults ['_route ' ] = 'chain_router_doctrine_route ' . str_replace ( ' / ' , ' _ ' , $ url );
189202
190203 return $ defaults ;
191204 }
@@ -196,7 +209,7 @@ public function match($url)
196209 *
197210 * Overwrite this method for other ODM or ORM repositories.
198211 *
199- * @param $url The url to find
212+ * @param string $url The url to find
200213 *
201214 * @return the RouteObjectInterface object for this url or null if none is found
202215 */
@@ -215,15 +228,18 @@ protected function findRouteForUrl($url)
215228 /**
216229 * Called in generate when there is no route given in the parameters
217230 *
218- * @param $parameters which should contain a content field containing a RouteAwareInterface object
231+ * @param array $parameters which should contain a content field containing a RouteAwareInterface object
232+ *
219233 * @return the route instance
234+ *
220235 * @throws RouteNotFoundException
221236 */
222237 protected function getRouteFromContent ($ parameters )
223238 {
224239 if (! isset ($ parameters ['content ' ])) {
225240 throw new RouteNotFoundException ;
226241 }
242+
227243 if (! $ parameters ['content ' ] instanceof RouteAwareInterface) {
228244 $ hint = is_object ($ parameters ['content ' ]) ? get_class ($ parameters ['content ' ]) : gettype ($ parameters ['content ' ]);
229245 throw new RouteNotFoundException ('The content does not implement RouteAwareInterface: ' . $ hint );
@@ -237,5 +253,4 @@ protected function getRouteFromContent($parameters)
237253
238254 return reset ($ routes );
239255 }
240-
241256}
0 commit comments