当前位置: 首页>>代码示例>>PHP>>正文


PHP Controller\ControllerResolver类代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\Controller\ControllerResolver的典型用法代码示例。如果您正苦于以下问题:PHP ControllerResolver类的具体用法?PHP ControllerResolver怎么用?PHP ControllerResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ControllerResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: resolveController

 /**
  * @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;
 }
开发者ID:athemcms,项目名称:netis,代码行数:31,代码来源:SymphonyBased.php

示例2: handle

 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;
 }
开发者ID:zyncro,项目名称:framework,代码行数:31,代码来源:App.php

示例3: execute

 /**
  * @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;
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:33,代码来源:ControllerRouteCallback.php

示例4: run

 /**
  * 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;
 }
开发者ID:Happensit,项目名称:test_task,代码行数:31,代码来源:Application.php

示例5: run

 /**
  * 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;
 }
开发者ID:Dominant,项目名称:Skull,代码行数:30,代码来源:Application.php

示例6: testGetVariadicArguments

 /**
  * @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));
 }
开发者ID:alekitto,项目名称:symfony,代码行数:12,代码来源:LegacyArgumentResolverTest.php

示例7: testGetArguments

 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');
 }
开发者ID:Werelds,项目名称:FrameworkBenchmarks,代码行数:55,代码来源:ControllerResolverTest.php

示例8: loadResource

 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;
 }
开发者ID:ronisaha,项目名称:Lemon,代码行数:11,代码来源:AppKernel.php

示例9: testGetArguments

    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');
    }
开发者ID:usefulthink,项目名称:symfony,代码行数:54,代码来源:ControllerResolverTest.php

示例10: handle

 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);
 }
开发者ID:allmarkedup,项目名称:super-sharp-router,代码行数:11,代码来源:CallableHandler.php

示例11: execute

 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;
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:12,代码来源:ClosureRouteCallback.php

示例12: __construct

 /**
  * 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);
 }
开发者ID:easselin,项目名称:orchestra,代码行数:24,代码来源:FrontController.php

示例13: start

 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) {
     }
 }
开发者ID:nexhero,项目名称:muffin,代码行数:48,代码来源:init.php

示例14: onKernelController

 /**
  * @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));
     }
 }
开发者ID:Amrit01,项目名称:KunstmaanBundlesCMS,代码行数:28,代码来源:SlugListener.php

示例15: __construct

 /**
  * 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);
 }
开发者ID:netixpro,项目名称:symfony,代码行数:14,代码来源:ControllerResolver.php


注:本文中的Symfony\Component\HttpKernel\Controller\ControllerResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。