Пример #1
0
 /**
  * @param $params
  * @return mixed|string
  * @throws SmartyPluginException
  */
 public function processRender($params)
 {
     if (null === $params["action"]) {
         throw new SmartyPluginException("You must declare the 'action' parameter in the 'render' smarty function");
     }
     $request = $this->prepareRequest($params);
     $controller = $this->controllerResolver->getController($request);
     $controllerParameters = $this->controllerResolver->getArguments($request, $controller);
     $response = call_user_func_array($controller, $controllerParameters);
     if ($response instanceof Response) {
         return $response->getContent();
     }
     return $response;
 }
Пример #2
0
 /**
  * Check that controller methods for the routes are callable.
  */
 public function testTargetControllerMethodsAreCallable()
 {
     $controllerResolver = new ControllerResolver($this->getContainer());
     foreach (static::$routingFiles as $filePath => $fileNames) {
         $routerFileLoader = $this->routerFileLoaders[$filePath];
         foreach ($fileNames as $fileName) {
             $router = new Router($routerFileLoader, $fileName);
             /** @var Route $route */
             foreach ($router->getRouteCollection() as $route) {
                 // prepare a dummy request to the controller so that we can check it using the ControllerResolver
                 $request = new Request();
                 $request->attributes->set('_controller', $route->getDefault('_controller'));
                 // will throw an exception if the controller method is not callable
                 $controllerResolver->getController($request);
             }
         }
     }
 }