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


PHP ControllerResolver::getController方法代码示例

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


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

示例1: testGetController

 public function testGetController()
 {
     $logger = new Logger();
     $resolver = new ControllerResolver($logger);
     $request = Request::create('/');
     $this->assertFalse($resolver->getController($request), '->getController() returns false when the request has no _controller attribute');
     $this->assertEquals(array('Unable to look for the controller as the "_controller" parameter is missing'), $logger->getLogs('err'));
     $request->attributes->set('_controller', 'Symfony\\Tests\\Component\\HttpKernel\\ControllerResolverTest::testGetController');
     $controller = $resolver->getController($request);
     $this->assertInstanceOf('Symfony\\Tests\\Component\\HttpKernel\\ControllerResolverTest', $controller[0], '->getController() returns a PHP callable');
     $this->assertEquals(array('Using controller "Symfony\\Tests\\Component\\HttpKernel\\ControllerResolverTest::testGetController"'), $logger->getLogs('info'));
     $request->attributes->set('_controller', 'foo');
     try {
         $resolver->getController($request);
         $this->fail('->getController() throws an \\InvalidArgumentException if the _controller attribute is not well-formatted');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getController() throws an \\InvalidArgumentException if the _controller attribute is not well-formatted');
     }
     $request->attributes->set('_controller', 'foo::bar');
     try {
         $resolver->getController($request);
         $this->fail('->getController() throws an \\InvalidArgumentException if the _controller attribute contains a non-existent class');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getController() throws an \\InvalidArgumentException if the _controller attribute contains a non-existent class');
     }
     $request->attributes->set('_controller', 'Symfony\\Tests\\Component\\HttpKernel\\ControllerResolverTest::bar');
     try {
         $resolver->getController($request);
         $this->fail('->getController() throws an \\InvalidArgumentException if the _controller attribute contains a non-existent method');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getController() throws an \\InvalidArgumentException if the _controller attribute contains a non-existent method');
     }
 }
开发者ID:netixpro,项目名称:symfony,代码行数:33,代码来源:ControllerResolverTest.php

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: onKernelController

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

示例9: 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

示例10: getController

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

示例11: 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

示例12: handle

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

示例13: getController

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

示例14: __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

示例15: 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


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