Ejemplo n.º 1
0
 /**
  * Returns the Controller instance associated with a Request.
  *
  * This method looks for a '_controller' request attribute that represents
  * the controller name (a string like ClassName::MethodName).
  *
  * @param Request $request A Request instance
  *
  * @return mixed|Boolean A PHP callable representing the Controller,
  *                       or false if this resolver is not able to determine the controller
  *
  * @throws \InvalidArgumentException|\LogicException If the controller can't be found
  *
  * @api
  */
 public function getController(Request $request)
 {
     if (!($controller = $request->attributes->get('_controller'))) {
         if (null !== $this->bbapp) {
             $this->bbapp->getLogging()->warning('Unable to look for the controller as the "_controller" parameter is missing');
         }
         return false;
     }
     if (is_array($controller)) {
         return $controller;
     }
     if (is_object($controller)) {
         if ($request->attributes->has('_action')) {
             return array($controller, $request->attributes->get('_action'));
         }
     }
     list($controller, $method) = $this->createController($controller, $request->attributes->get('_action'));
     if (!method_exists($controller, $method)) {
         throw new \InvalidArgumentException(sprintf('Method "%s::%s" does not exist.', get_class($controller), $method));
     }
     return array($controller, $method);
 }