This implementation uses the '_controller' request attribute to determine the controller to execute and uses the request attributes to determine the controller method arguments.
Автор: Fabien Potencier (fabien@symfony.com)
Наследование: implements Symfony\Component\HttpKernel\Controller\ControllerResolverInterface
Пример #1
0
 /**
  * @return array|bool
  */
 protected function resolveController()
 {
     try {
         // doctrine mabo jambo to prepare route detection
         $context = new RequestContext();
         $context->fromRequest($this->request);
         $matcher = new UrlMatcher($this->routeCollection, $context);
         // try detecting controller & stuff
         $this->request->attributes->add($matcher->match($this->request->getPathInfo()));
         // resolve controller
         $resolver = new ControllerResolver();
         $controller = $resolver->getController($this->request);
         $controller = $this->assembleController($controller);
         // adding request and response variables to the controller
         if (!empty($controller[0]) && $controller[0] instanceof AbstractSimplexController) {
             $controller[0]->setRequest($this->request)->setResponse($this->response);
         } else {
             // or as attributes for a 'function' controller
             $req = array('request' => $this->request, 'response' => $this->response);
             $this->request->attributes->add($req);
         }
         // parsing arguments for the request and adding a last argument the request parameter itself
         $arguments = $resolver->getArguments($this->request, $controller);
         return array($controller, $arguments);
     } catch (ResourceNotFoundException $e) {
     }
     return false;
 }
Пример #2
0
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     try {
         $this->request = $request;
         $pathInfo = $request->getPathInfo();
         $this->loadRoutes($pathInfo);
         $this->loadGeneralConfig();
         $this->loadZyncroAppConfig($pathInfo);
         $this->loadDatabaseConfig($pathInfo);
         $this->loadSecurityConfig($pathInfo);
         $this->loadTwig($pathInfo);
         $this->loadUtils();
         $this->method = $request->getMethod();
         $this->dispatcher->dispatch('request', new RequestEvent($request, $this->session, $this->securityConfig, $this->routes));
         $this->loadApi();
         $context = new Routing\RequestContext();
         $matcher = new Routing\Matcher\UrlMatcher($this->routes, $context);
         $context->fromRequest($request);
         $request->attributes->add($matcher->match($request->getPathInfo()));
         $resolver = new ControllerResolver();
         $controller = $resolver->getController($request);
         $arguments = $resolver->getArguments($request, $controller);
         $arguments[0] = $this;
         $response = call_user_func_array($controller, $arguments);
     } catch (Routing\Exception\ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (\Exception $e) {
         $response = new Response('An error occurred: ' . $e->getMessage(), 500);
     }
     return $response;
 }
Пример #3
0
 /**
  * @param Request $request
  * @param Route $route
  * @param array $parameters
  * @return Response
  */
 public function execute(Request $request, Route $route, $parameters)
 {
     $resolver = new HttpKernel\Controller\ControllerResolver();
     $callback = $resolver->getController($request);
     $arguments = $resolver->getArguments($request, $callback);
     $controller = $callback[0];
     $method = $callback[1];
     $controller->on_start();
     $response = $controller->runAction($method, $arguments);
     if ($response instanceof \Symfony\Component\HttpFoundation\Response) {
         // note, our RedirectResponse doesn't extend Response, it extends symfony2 response
         return $response;
     } elseif ($response instanceof \Concrete\Core\View\AbstractView) {
         $content = $response->render();
     } else {
         $view = $controller->getViewObject();
         if (is_object($view)) {
             $view->setController($controller);
             if (isset($view) && $view instanceof \Concrete\Core\View\AbstractView) {
                 $content = $view->render();
             }
         }
     }
     $response = new Response();
     $response->setContent($content);
     return $response;
 }
Пример #4
0
 /**
  * Run Application.
  */
 public function run()
 {
     $request = $this['request'] = Request::createFromGlobals();
     $routes = $this['routes'];
     $context = $this['request_context'];
     $context->fromRequest($this['request']);
     $matcher = new UrlMatcher($routes, $context);
     $resolver = new ControllerResolver();
     try {
         $request->attributes->add($matcher->match($request->getPathInfo()));
         $controller = $resolver->getController($request);
         $arguments = $resolver->getArguments($request, $controller);
         if (is_array($controller) && $controller[0] instanceof \Task\Controllers\BaseController) {
             $controller[0]->setRequest($request);
             $controller[0]->setApplication($this);
         }
         $response = call_user_func_array($controller, $arguments);
     } catch (ResourceNotFoundException $e) {
         $response = new JsonResponse(["errors" => ["type" => "Not found"]], Response::HTTP_NOT_FOUND);
     } catch (\Exception $e) {
         $response = new JsonResponse(["errors" => ["type" => $e->getMessage(), "stacktrace" => $e->getTraceAsString()]], Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     $response->headers->set("Access-Control-Allow-Origin", "*");
     $response->headers->set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
     $response->headers->set("Access-Control-Allow-Headers", "Content-Type");
     $response->headers->set("Server", "Test task REST");
     return $response;
 }
Пример #5
0
 /**
  * Run Application.
  */
 public function run()
 {
     if (empty($this['request'])) {
         $this['request'] = Request::createFromGlobals();
     }
     $routes = $this['routes'];
     $request = $this['request'];
     $context = $this['requestContext'];
     $context->fromRequest($this['request']);
     $matcher = new UrlMatcher($routes, $context);
     $resolver = new ControllerResolver();
     try {
         $request->attributes->add($matcher->match($request->getPathInfo()));
         $controller = $resolver->getController($request);
         $arguments = $resolver->getArguments($request, $controller);
         if (is_array($controller) && $controller[0] instanceof BaseController) {
             $controller[0]->setRequest($request);
             $controller[0]->setApplication($this);
         }
         $response = call_user_func_array($controller, $arguments);
     } catch (ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (\Exception $e) {
         $response = new Response('An error occurred', 500);
     }
     return $response;
 }
Пример #6
0
 /**
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     // Check if the event has a nodeTranslation, if not this method can be skipped
     if (!$request->attributes->has('_nodeTranslation')) {
         return;
     }
     $nodeTranslation = $request->attributes->get('_nodeTranslation');
     if (!$nodeTranslation instanceof NodeTranslation) {
         $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslation);
         $request->attributes->set('_nodeTranslation', $nodeTranslation);
     }
     $entity = $nodeTranslation->getRef($this->em);
     // If the entity is an instance of the SlugActionInterface, change the controller
     if ($entity instanceof SlugActionInterface) {
         $request->attributes->set('_entity', $entity);
         // Do security check by firing an event that gets handled by the SlugSecurityListener
         $securityEvent = new SlugSecurityEvent();
         $securityEvent->setNode($nodeTranslation->getNode())->setEntity($entity)->setRequest($request)->setNodeTranslation($nodeTranslation);
         $this->eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent);
         // Set the right controller
         $request->attributes->set('_controller', $entity->getControllerAction());
         $event->setController($this->resolver->getController($request));
     }
 }
 /**
  * @requires PHP 5.6
  */
 public function testGetVariadicArguments()
 {
     $resolver = new ControllerResolver();
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $request->attributes->set('bar', array('foo', 'bar'));
     $controller = array(new VariadicController(), 'action');
     $this->assertEquals(array('foo', 'foo', 'bar'), $resolver->getArguments($request, $controller));
 }
 public function testGetArguments()
 {
     $resolver = new ControllerResolver();
     $request = Request::create('/');
     $controller = array(new self(), 'testGetArguments');
     $this->assertEquals(array(), $resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $controller = array(new self(), 'controllerMethod1');
     $this->assertEquals(array('foo'), $resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $controller = array(new self(), 'controllerMethod2');
     $this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
     $request->attributes->set('bar', 'bar');
     $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $controller = function ($foo) {
     };
     $this->assertEquals(array('foo'), $resolver->getArguments($request, $controller));
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $controller = function ($foo, $bar = 'bar') {
     };
     $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $controller = new self();
     $this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller));
     $request->attributes->set('bar', 'bar');
     $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $request->attributes->set('foobar', 'foobar');
     $controller = 'Symfony\\Component\\HttpKernel\\Tests\\some_controller_function';
     $this->assertEquals(array('foo', 'foobar'), $resolver->getArguments($request, $controller));
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $request->attributes->set('foobar', 'foobar');
     $controller = array(new self(), 'controllerMethod3');
     if (version_compare(PHP_VERSION, '5.3.16', '==')) {
         $this->markTestSkipped('PHP 5.3.16 has a major bug in the Reflection sub-system');
     } else {
         try {
             $resolver->getArguments($request, $controller);
             $this->fail('->getArguments() throws a \\RuntimeException exception if it cannot determine the argument value');
         } catch (\Exception $e) {
             $this->assertInstanceOf('\\RuntimeException', $e, '->getArguments() throws a \\RuntimeException exception if it cannot determine the argument value');
         }
     }
     $request = Request::create('/');
     $controller = array(new self(), 'controllerMethod5');
     $this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
 }
Пример #9
0
 private function loadResource()
 {
     $resolver = new ControllerResolver();
     $controller = $resolver->getController($this->request);
     $arguments = $resolver->getArguments($this->request, $controller);
     $controller[0]->setRequest($this->request);
     $controller[0]->setConfiguration($this->conf);
     $controller[0]->init();
     $response = call_user_func_array($controller, $arguments);
     return $response;
 }
Пример #10
0
    public function testGetArguments()
    {
        $resolver = new ControllerResolver();

        $request = Request::create('/');
        $controller = array(new self(), 'testGetArguments');
        $this->assertEquals(array(), $resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');

        $request = Request::create('/');
        $request->attributes->set('foo', 'foo');
        $controller = array(new self(), 'controllerMethod1');
        $this->assertEquals(array('foo'), $resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');

        $request = Request::create('/');
        $request->attributes->set('foo', 'foo');
        $controller = array(new self(), 'controllerMethod2');
        $this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller), '->getArguments() uses default values if present');

        $request->attributes->set('bar', 'bar');
        $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');

        $request = Request::create('/');
        $request->attributes->set('foo', 'foo');
        $controller = function ($foo) {};
        $this->assertEquals(array('foo'), $resolver->getArguments($request, $controller));

        $request = Request::create('/');
        $request->attributes->set('foo', 'foo');
        $controller = function ($foo, $bar = 'bar') {};
        $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));

        $request = Request::create('/');
        $request->attributes->set('foo', 'foo');
        $controller = new self();
        $this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller));
        $request->attributes->set('bar', 'bar');
        $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));

        $request = Request::create('/');
        $request->attributes->set('foo', 'foo');
        $request->attributes->set('foobar', 'foobar');
        $controller = array(new self(), 'controllerMethod3');

        try {
            $resolver->getArguments($request, $controller);
            $this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
        } catch (\Exception $e) {
            $this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
        }

        $request = Request::create('/');
        $controller = array(new self(), 'controllerMethod5');
        $this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
    }
 public function handle($params, Request $request)
 {
     if (empty($params['_controller'])) {
         throw new Exception('The CallableHandler requires a non-empty controller value');
     }
     $resolver = new ControllerResolver();
     $request->attributes->add($params);
     $controller = $resolver->getController($request);
     $arguments = $resolver->getArguments($request, $controller);
     return call_user_func_array($controller, $arguments);
 }
Пример #12
0
 public function execute(Request $request, \Concrete\Core\Routing\Route $route, $parameters)
 {
     $resolver = new HttpKernel\Controller\ControllerResolver();
     $arguments = $resolver->getArguments($request, $this->callback);
     $callback_response = call_user_func_array($this->callback, $arguments);
     if ($callback_response instanceof \Concrete\Core\Http\Response) {
         return $callback_response;
     }
     $r = new Response();
     $r->setContent($callback_response);
     return $r;
 }
Пример #13
0
 /**
  * Determines which controller to call based on the current request
  * Sets the controller based on "page" (Wordpress' way of figuring out which plugin is called),
  * "orchestraController" and "orchestraAction"
  *
  * @param $request
  * @param $em
  * @param $twig
  * @param $formFactory
  */
 public function __construct($request, $em, $twig, $formFactory)
 {
     $attributes = $request->query->all();
     $attributes['_controller'] = Framework::$pluginNamespace . '\\Controller\\' . ucfirst($request->query->get('orchestraController', 'default')) . 'Controller::' . $request->query->get('orchestraAction', 'index') . 'Action';
     unset($attributes['orchestraController']);
     unset($attributes['orchestraAction']);
     unset($attributes['page']);
     $resolver = new ControllerResolver();
     $request->attributes->add($attributes);
     $controller = $resolver->getController($request);
     $controller[0]->init($request, $em, $twig, $formFactory);
     $arguments = $resolver->getArguments($request, $controller);
     $this->response = call_user_func_array($controller, $arguments);
 }
Пример #14
0
 public static function start()
 {
     /*
      Loading preconfigured DataBased
     */
     try {
         Muffin\System\DataBase::initDB();
     } catch (Exception $e) {
     }
     /*
      Catching global variables, also we create the response
     */
     $request = Request::createFromGlobals();
     $response = new Response();
     /*
               Loading the routes file and define the routes as the container
               of the routers definitions
               More info: http://symfony.com/doc/current/components/routing/introduction.html#load-routes-fr
               om-a-file
     */
     $resolver = new HttpKernel\Controller\ControllerResolver();
     $locator = new FileLocator(array(__DIR__));
     $loader = new YamlFileLoader($locator);
     $routes = $loader->load('config/routes.yml');
     $context = new RequestContext($request->getMethod());
     try {
         $matcher = new UrlMatcher($routes, $context);
         $request->attributes->add($matcher->match($request->getPathInfo()));
         $controller = $resolver->getController($request);
         $arguments = $resolver->getArguments($request, $controller);
         $response = call_user_func_array($controller, $arguments);
         /*
          If the path doesn't exits
         */
     } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (Exception $e) {
         $response = new Response('An error occurred' . $e, 500);
     }
     $response->send();
     /*
      IF we created a connection to the DataBase we close it at the end
     */
     try {
         Muffin\System\DataBase::close();
     } catch (Exception $e) {
     }
 }
Пример #15
0
 /**
  * Constructor.
  *
  * @param ContainerInterface      $container A ContainerInterface instance
  * @param ControllerNameConverter $converter A ControllerNameConverter instance
  * @param LoggerInterface         $logger    A LoggerInterface instance
  */
 public function __construct(ContainerInterface $container, ControllerNameConverter $converter, LoggerInterface $logger = null)
 {
     $this->container = $container;
     $this->converter = $converter;
     $this->esiSupport = $container->has('esi') && $container->getEsiService()->hasSurrogateEsiCapability($container->getRequestService());
     parent::__construct($logger);
 }
Пример #16
0
 /**
  * @param string $class
  *
  * @return object
  */
 protected function instantiateController($class)
 {
     $controller = parent::instantiateController($class);
     if ($controller instanceof ServiceLocatorAwareInterface) {
         $controller->setServiceLocator($this->serviceManager);
     }
     return $controller;
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 protected function instantiateController($class)
 {
     $controller = parent::instantiateController($class);
     if ($controller instanceof ContainerAwareInterface) {
         $controller->setContainer($this->container);
     }
     return $controller;
 }
 protected function doGetArguments(Request $request, $controller, array $parameters)
 {
     foreach ($parameters as $param) {
         if ($param->getClass() && $param->getClass()->isInstance($this->app)) {
             $request->attributes->set($param->getName(), $this->app);
             break;
         }
     }
     return parent::doGetArguments($request, $controller, $parameters);
 }
 /**
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     //check if the event has anything to do with nodeTranslations, if not this method can be skipped
     if (!$request->attributes->has('_nodeTranslation')) {
         return;
     }
     $nodeTranslation = $request->attributes->get('_nodeTranslation');
     $entity = $nodeTranslation->getRef($this->em);
     //if the entity is an instance of the SlugControllerActionInterface, change the controller
     if ($entity instanceof SlugActionInterface) {
         $request->attributes->set('_entity', $entity);
         //do security check by firing an event that gets handled by the SlugSecurityListener
         $securityEvent = new SlugSecurityEvent();
         $this->eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent);
         //set the right controller
         $request->attributes->set('_controller', $entity->getControllerAction());
         $event->setController($this->resolver->getController($request));
     }
 }
Пример #20
0
 /**
  * Returns a callable controller
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @return Callable|False
  * @author Dan Cox
  */
 public function getController(\Symfony\Component\HttpFoundation\Request $request)
 {
     $controller = parent::getController($request);
     if (is_subclass_of($controller[0], 'Wasp\\Controller\\BaseController')) {
         $controller[0]->setDI($this->DI);
     }
     if (is_subclass_of($controller[0], 'Wasp\\Controller\\RestController') || is_a($controller[0], 'Wasp\\Controller\\RestController')) {
         $controller[0]->setEntity($request->attributes->get('entity'));
     }
     return $controller;
 }
 public function testGetControllerMatchedView()
 {
     $id = 123;
     $viewType = 'full';
     $templateIdentifier = 'FooBundle:full:template.twig.html';
     $customController = 'FooBundle::bar';
     $this->request->attributes->add(array('_controller' => 'ez_content:viewLocation', 'locationId' => $id, 'viewType' => $viewType));
     $this->viewBuilderRegistry->expects($this->once())->method('getFromRegistry')->will($this->returnValue($this->viewBuilderMock));
     $viewObject = new ContentView($templateIdentifier);
     $viewObject->setControllerReference(new ControllerReference($customController));
     $this->viewBuilderMock->expects($this->once())->method('buildView')->will($this->returnValue($viewObject));
     $this->event->expects($this->once())->method('setController');
     $this->controllerResolver->expects($this->once())->method('getController')->will($this->returnValue(function () {
     }));
     $this->controllerListener->getController($this->event);
     $this->assertEquals($customController, $this->request->attributes->get('_controller'));
     $expectedView = new ContentView();
     $expectedView->setTemplateIdentifier($templateIdentifier);
     $expectedView->setControllerReference(new ControllerReference($customController));
     $this->assertEquals($expectedView, $this->request->attributes->get('view'));
 }
Пример #22
0
 /**
  * @param Request $request
  * @return Response
  */
 public function handle(Request $request)
 {
     try {
         $request->attributes->add($this->matcher->match($request->getPathInfo()));
         $session = new Session(new NativeSessionStorage(array('cookie_lifetime' => 60 * 60)));
         $session->start();
         $request->setSession($session);
         $controllerParams = $this->resolver->getController($request);
         $arguments = $this->resolver->getArguments($request, $controllerParams);
         /** @var Controller $controller */
         $controller = $controllerParams[0];
         $controller->setContainer($this->container);
         $response = call_user_func_array($controllerParams, $arguments);
         $this->dispatcher->dispatch('post.controller', new ResponseEvent($session));
         return $response;
     } catch (ResourceNotFoundException $e) {
         return new Response('Not Found', 404);
     } catch (\Exception $e) {
         return new Response('An error occurred', 500);
     }
 }
Пример #23
0
 public function getController(Request $request)
 {
     if (false !== ($controller = parent::getController($request))) {
         return $controller;
     }
     if (!($namespace = $request->attributes->get('_namespace'))) {
         $namespace = $this->defaultNamespace;
     }
     if (!($object = $request->attributes->get('_object'))) {
         $object = 'index';
         // echo ($object = $request->attributes->get('_object'));
     }
     if (!($method = $request->attributes->get('_method'))) {
         $method = $request->getMethod();
     }
     $request->attributes->remove('_namespace');
     $request->attributes->remove('_object');
     $request->attributes->remove('_method');
     // if($request->attributes->has('object')) {
     // 	$controller .= '\\' . ucfirst($request->attributes->get('object')) . 'Controller';
     // } else {
     // }
     // if($request->attributes->has('method')) {
     // 	$controller .= '::' . $request->attributes->get('method');
     // } else {
     // 	$controller .= '::' . strtolower($request->getMethod());
     // }
     $controllerName = sprintf("%s\\%sController::%s", $namespace, ucfirst($object), strtolower($method));
     // echo '<pre>';
     // var_dump($request->attributes);
     // echo $controllerName . '<br>';
     list($controller, $method) = $this->createController($controllerName);
     if (!method_exists($controller, $method)) {
         throw new \InvalidArgumentException(sprintf('Method "%s::%s" does not exist.', get_class($controller), $method));
     }
     return array($controller, $method);
     // var_dump($request->attributes);
     // die();
     //       $url = $request->getPathInfo();
     //       $parts = explode('/', $url);
     //       if (count($parts) < 4) {
     //           return;
     //       }
     //       $controllerName = sprintf(
     //           'App\\%sBundle\\Controller\\%sController::%sAction',
     //           $parts[1],
     //           $parts[2],
     //           $parts[3]
     //       );
     // $request->attributes->add(array('_controller'=> 'Webwall\Controllers\IndexController::get'));
 }
Пример #24
0
 protected function doGetArguments(Request $request, $controller, array $parameters)
 {
     /** @var \ReflectionParameter $param */
     foreach ($parameters as $param) {
         /** @var \Symfony\Component\Routing\Route $route */
         $route = $this->app['routes']->get($request->attributes->get('_route'));
         $bundle = $this->app->getSubBundle($route->getOption('bundle_name'));
         if ($bundle && $param->getClass() && $param->getClass()->isInstance($bundle)) {
             $request->attributes->set($param->getName(), $bundle);
             continue;
         }
         if ($param->getClass() && $param->getClass()->isInstance($this->app)) {
             $request->attributes->set($param->getName(), $this->app);
             continue;
         }
     }
     return parent::doGetArguments($request, $controller, $parameters);
 }
Пример #25
0
 /**
  * Constructor
  *
  * @param Application $app
  * @param LoggerInterface $logger
  */
 public function __construct(Application $app, LoggerInterface $logger = null)
 {
     $this->app = $app;
     parent::__construct($logger);
 }
Пример #26
0
 public function __construct(ContainerInterface $container, ControllerNameParser $parser, LoggerInterface $logger = null)
 {
     $this->container = $container;
     $this->parser = $parser;
     parent::__construct($logger);
 }
Пример #27
0
 /**
  * Constructor.
  *
  * @param ContainerInterface   $container A ContainerInterface instance
  * @param ControllerNameParser $parser    A ControllerNameParser instance
  * @param LoggerInterface      $logger    A LoggerInterface instance
  */
 public function __construct(ContainerInterface $container, LoggerInterface $logger = null)
 {
     $this->container = $container;
     parent::__construct($logger);
 }
Пример #28
0
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing;
use Symfony\Component\HttpKernel;
function render_template(Request $request)
{
    extract($request->attributes->all(), EXTR_SKIP);
    ob_start();
    include sprintf(__DIR__ . '/../src/pages/%s.php', $_route);
    return new Response(ob_get_clean());
}
$request = Request::createFromGlobals();
$routes = (include __DIR__ . '/../src/app.php');
$context = new Routing\RequestContext();
$context->fromRequest($request);
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);
$resolver = new HttpKernel\Controller\ControllerResolver();
try {
    $request->attributes->add($matcher->match($request->getPathInfo()));
    $controller = $resolver->getController($request);
    $arguments = $resolver->getArguments($request, $controller);
    $response = call_user_func_array($controller, $arguments);
} catch (Routing\Exception\ResourceNotFoundException $e) {
    $response = new Response('Not found', 404);
} catch (Exception $e) {
    $response = new Response('An error occurred', 500);
}
$response->send();
Пример #29
0
 /**
  * @requires PHP 7.1
  */
 public function testGetNullableArgumentsWithDefaults()
 {
     $resolver = new ControllerResolver();
     $request = Request::create('/');
     $request->attributes->set('mandatory', 'mandatory');
     $controller = array(new NullableController(), 'action');
     $this->assertEquals(array(null, null, 'value', 'mandatory'), $resolver->getArguments($request, $controller));
 }
 /**
  * Constructs a new ControllerResolver.
  *
  * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
  *   The class resolver.
  * @param \Psr\Log\LoggerInterface $logger
  *   (optional) A LoggerInterface instance.
  */
 public function __construct(ClassResolverInterface $class_resolver, LoggerInterface $logger = NULL)
 {
     $this->classResolver = $class_resolver;
     parent::__construct($logger);
 }