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


PHP Controller\ControllerResolverInterface类代码示例

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


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

示例1: getTitle

 /**
  * {@inheritdoc}
  */
 public function getTitle(Request $request, Route $route)
 {
     $route_title = NULL;
     // A dynamic title takes priority. Route::getDefault() returns NULL if the
     // named default is not set.  By testing the value directly, we also avoid
     // trying to use empty values.
     if ($callback = $route->getDefault('_title_callback')) {
         $callable = $this->controllerResolver->getControllerFromDefinition($callback);
         $arguments = $this->controllerResolver->getArguments($request, $callable);
         $route_title = call_user_func_array($callable, $arguments);
     } elseif ($title = $route->getDefault('_title')) {
         $options = array();
         if ($context = $route->getDefault('_title_context')) {
             $options['context'] = $context;
         }
         $args = array();
         if ($raw_parameters = $request->attributes->get('_raw_variables')) {
             foreach ($raw_parameters->all() as $key => $value) {
                 $args['@' . $key] = $value;
                 $args['%' . $key] = $value;
             }
         }
         if ($title_arguments = $route->getDefault('_title_arguments')) {
             $args = array_merge($args, (array) $title_arguments);
         }
         // Fall back to a static string from the route.
         $route_title = $this->t($title, $args, $options);
     }
     return $route_title;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:33,代码来源:TitleResolver.php

示例2: collect

 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     parent::collect($request, $response, $exception);
     $controller = $this->controllerResolver->getController($request);
     $this->data['controller'] = $this->getMethodData($controller[0], $controller[1]);
     $this->data['access_check'] = $this->accessCheck;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:RequestDataCollector.php

示例3: access

 /**
  * Checks access for the account and route using the custom access checker.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match object to be checked.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The account being checked.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $callable = $this->controllerResolver->getControllerFromDefinition($route->getRequirement('_custom_access'));
     $arguments_resolver = $this->argumentsResolverFactory->getArgumentsResolver($route_match, $account);
     $arguments = $arguments_resolver->getArguments($callable);
     return call_user_func_array($callable, $arguments);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:18,代码来源:CustomAccessCheck.php

示例4: getContentResult

 /**
  * Returns the result of invoking the sub-controller.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param mixed $controller_definition
  *   A controller definition string, or a callable object/closure.
  *
  * @return mixed
  *   The result of invoking the controller. Render arrays, strings, HtmlPage,
  *   and HtmlFragment objects are possible.
  */
 public function getContentResult(Request $request, $controller_definition)
 {
     if ($controller_definition instanceof \Closure) {
         $callable = $controller_definition;
     } else {
         $callable = $this->controllerResolver->getControllerFromDefinition($controller_definition);
     }
     $arguments = $this->controllerResolver->getArguments($request, $callable);
     $page_content = call_user_func_array($callable, $arguments);
     return $page_content;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:23,代码来源:AjaxController.php

示例5: onViewRenderArray

 /**
  * Sets a response given a (main content) render array.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The event to process.
  */
 public function onViewRenderArray(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $result = $event->getControllerResult();
     // Render the controller result into a response if it's a render array.
     if (is_array($result) && ($request->query->has(static::WRAPPER_FORMAT) || $request->getRequestFormat() == 'html')) {
         $wrapper = $request->query->get(static::WRAPPER_FORMAT, 'html');
         // Fall back to HTML if the requested wrapper envelope is not available.
         $wrapper = isset($this->mainContentRenderers[$wrapper]) ? $wrapper : 'html';
         $renderer = $this->classResolver->getInstanceFromDefinition($this->mainContentRenderers[$wrapper]);
         $event->setResponse($renderer->renderResponse($result, $request, $this->routeMatch));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:19,代码来源:MainContentViewSubscriber.php

示例6: testPermissionsYamlStaticAndCallback

 /**
  * Tests a YAML file containing both static permissions and a callback.
  */
 public function testPermissionsYamlStaticAndCallback()
 {
     vfsStreamWrapper::register();
     $root = new vfsStreamDirectory('modules');
     vfsStreamWrapper::setRoot($root);
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->moduleHandler->expects($this->once())->method('getModuleDirectories')->willReturn(array('module_a' => vfsStream::url('modules/module_a')));
     $url = vfsStream::url('modules');
     mkdir($url . '/module_a');
     file_put_contents($url . '/module_a/module_a.permissions.yml', "'access module a':\n  title: 'Access A'\n  description: 'bla bla'\npermission_callbacks:\n  - 'Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription'\n");
     $modules = array('module_a');
     $extensions = array('module_a' => $this->mockModuleExtension('module_a', 'Module a'));
     $this->moduleHandler->expects($this->any())->method('getImplementations')->with('permission')->willReturn(array());
     $this->moduleHandler->expects($this->any())->method('getModuleList')->willReturn(array_flip($modules));
     $this->controllerResolver->expects($this->once())->method('getControllerFromDefinition')->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription')->willReturn(array(new TestPermissionCallbacks(), 'titleDescription'));
     $this->permissionHandler = new TestPermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver);
     // Setup system_rebuild_module_data().
     $this->permissionHandler->setSystemRebuildModuleData($extensions);
     $actual_permissions = $this->permissionHandler->getPermissions();
     $this->assertCount(2, $actual_permissions);
     $this->assertEquals($actual_permissions['access module a']['title'], 'Access A');
     $this->assertEquals($actual_permissions['access module a']['provider'], 'module_a');
     $this->assertEquals($actual_permissions['access module a']['description'], 'bla bla');
     $this->assertEquals($actual_permissions['access module b']['title'], 'Access B');
     $this->assertEquals($actual_permissions['access module b']['provider'], 'module_a');
     $this->assertEquals($actual_permissions['access module b']['description'], 'bla bla');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:30,代码来源:PermissionHandlerTest.php

示例7: rebuild

 /**
  * {@inheritdoc}
  */
 public function rebuild()
 {
     if ($this->building) {
         throw new \RuntimeException('Recursive router rebuild detected.');
     }
     if (!$this->lock->acquire('router_rebuild')) {
         // Wait for another request that is already doing this work.
         // We choose to block here since otherwise the routes might not be
         // available, resulting in a 404.
         $this->lock->wait('router_rebuild');
         return FALSE;
     }
     $this->building = TRUE;
     $collection = new RouteCollection();
     foreach ($this->getRouteDefinitions() as $routes) {
         // The top-level 'routes_callback' is a list of methods in controller
         // syntax, see \Drupal\Core\Controller\ControllerResolver. These methods
         // should return a set of \Symfony\Component\Routing\Route objects, either
         // in an associative array keyed by the route name, which will be iterated
         // over and added to the collection for this provider, or as a new
         // \Symfony\Component\Routing\RouteCollection object, which will be added
         // to the collection.
         if (isset($routes['route_callbacks'])) {
             foreach ($routes['route_callbacks'] as $route_callback) {
                 $callback = $this->controllerResolver->getControllerFromDefinition($route_callback);
                 if ($callback_routes = call_user_func($callback)) {
                     // If a RouteCollection is returned, add the whole collection.
                     if ($callback_routes instanceof RouteCollection) {
                         $collection->addCollection($callback_routes);
                     } else {
                         foreach ($callback_routes as $name => $callback_route) {
                             $collection->add($name, $callback_route);
                         }
                     }
                 }
             }
             unset($routes['route_callbacks']);
         }
         foreach ($routes as $name => $route_info) {
             $route_info += array('defaults' => array(), 'requirements' => array(), 'options' => array());
             $route = new Route($route_info['path'], $route_info['defaults'], $route_info['requirements'], $route_info['options']);
             $collection->add($name, $route);
         }
     }
     // DYNAMIC is supposed to be used to add new routes based upon all the
     // static defined ones.
     $this->dispatcher->dispatch(RoutingEvents::DYNAMIC, new RouteBuildEvent($collection));
     // ALTER is the final step to alter all the existing routes. We cannot stop
     // people from adding new routes here, but we define two separate steps to
     // make it clear.
     $this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection));
     $this->checkProvider->setChecks($collection);
     $this->dumper->addRoutes($collection);
     $this->dumper->dump();
     $this->lock->release('router_rebuild');
     $this->dispatcher->dispatch(RoutingEvents::FINISHED, new Event());
     $this->building = FALSE;
     $this->rebuildNeeded = FALSE;
     return TRUE;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:63,代码来源:RouteBuilder.php

示例8: getTitle

 /**
  * {@inheritdoc}
  */
 public function getTitle(LocalTaskInterface $local_task)
 {
     $controller = array($local_task, 'getTitle');
     $request = $this->requestStack->getCurrentRequest();
     $arguments = $this->controllerResolver->getArguments($request, $controller);
     return call_user_func_array($controller, $arguments);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:10,代码来源:LocalTaskManager.php

示例9: testRebuildWithProviderBasedRoutes

 /**
  * Tests the rebuild with routes provided by a callback.
  *
  * @see \Drupal\Core\Routing\RouteBuilder::rebuild()
  */
 public function testRebuildWithProviderBasedRoutes()
 {
     $this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE));
     $this->yamlDiscovery->expects($this->once())->method('findAll')->will($this->returnValue(array('test_module' => array('route_callbacks' => array('\\Drupal\\Tests\\Core\\Routing\\TestRouteSubscriber::routesFromArray', 'test_module.route_service:routesFromCollection')))));
     $container = new ContainerBuilder();
     $container->set('test_module.route_service', new TestRouteSubscriber());
     $this->controllerResolver->expects($this->any())->method('getControllerFromDefinition')->will($this->returnCallback(function ($controller) use($container) {
         $count = substr_count($controller, ':');
         if ($count == 1) {
             list($service, $method) = explode(':', $controller, 2);
             $object = $container->get($service);
         } else {
             list($class, $method) = explode('::', $controller, 2);
             $object = new $class();
         }
         return array($object, $method);
     }));
     $route_collection_filled = new RouteCollection();
     $route_collection_filled->add('test_route.1', new Route('/test-route/1'));
     $route_collection_filled->add('test_route.2', new Route('/test-route/2'));
     $route_build_event = new RouteBuildEvent($route_collection_filled);
     // Ensure that the alter routes events are fired.
     $this->dispatcher->expects($this->at(0))->method('dispatch')->with(RoutingEvents::DYNAMIC, $route_build_event);
     $this->dispatcher->expects($this->at(1))->method('dispatch')->with(RoutingEvents::ALTER, $route_build_event);
     // Ensure that the routes are set to the dumper and dumped.
     $this->dumper->expects($this->at(0))->method('addRoutes')->with($route_collection_filled);
     $this->dumper->expects($this->at(1))->method('dump');
     $this->assertTrue($this->routeBuilder->rebuild());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:34,代码来源:RouteBuilderTest.php

示例10: getContentResult

 /**
  * Invokes the form and returns the result.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return array
  *   The render array that results from invoking the controller.
  */
 public function getContentResult(Request $request)
 {
     $form_object = $this->getFormObject($request, $this->formDefinition);
     // Add the form and form_state to trick the getArguments method of the
     // controller resolver.
     $form_state = array();
     $request->attributes->set('form', array());
     $request->attributes->set('form_state', $form_state);
     $args = $this->controllerResolver->getArguments($request, array($form_object, 'buildForm'));
     $request->attributes->remove('form');
     $request->attributes->remove('form_state');
     // Remove $form and $form_state from the arguments, and re-index them.
     unset($args[0], $args[1]);
     $form_state['build_info']['args'] = array_values($args);
     return $this->formBuilder->buildForm($form_object, $form_state);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:25,代码来源:FormController.php

示例11: onViewRenderArray

 /**
  * Sets a response given a (main content) render array.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The event to process.
  */
 public function onViewRenderArray(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $result = $event->getControllerResult();
     $format = $request->getRequestFormat();
     // Render the controller result into a response if it's a render array.
     if (is_array($result)) {
         if (isset($this->mainContentRenderers[$format])) {
             $renderer = $this->classResolver->getInstanceFromDefinition($this->mainContentRenderers[$format]);
             $event->setResponse($renderer->renderResponse($result, $request, $this->routeMatch));
         } else {
             $supported_formats = array_keys($this->mainContentRenderers);
             $supported_mimetypes = array_map([$request, 'getMimeType'], $supported_formats);
             $event->setResponse(new JsonResponse(['message' => 'Not Acceptable.', 'supported_mime_types' => $supported_mimetypes], 406));
         }
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:23,代码来源:MainContentViewSubscriber.php

示例12: getContentResult

 /**
  * Invokes the form and returns the result.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match.
  *
  * @return array
  *   The render array that results from invoking the controller.
  */
 public function getContentResult(Request $request, RouteMatchInterface $route_match)
 {
     $form_arg = $this->getFormArgument($route_match);
     $form_object = $this->getFormObject($route_match, $form_arg);
     // Add the form and form_state to trick the getArguments method of the
     // controller resolver.
     $form_state = new FormState();
     $request->attributes->set('form', []);
     $request->attributes->set('form_state', $form_state);
     $args = $this->controllerResolver->getArguments($request, [$form_object, 'buildForm']);
     $request->attributes->remove('form');
     $request->attributes->remove('form_state');
     // Remove $form and $form_state from the arguments, and re-index them.
     unset($args[0], $args[1]);
     $form_state->addBuildInfo('args', array_values($args));
     return $this->formBuilder->buildForm($form_object, $form_state);
 }
开发者ID:318io,项目名称:318-io,代码行数:28,代码来源:FormController.php

示例13: testAccess

 /**
  * Test the access method.
  */
 public function testAccess()
 {
     $request = new Request(array());
     $this->controllerResolver->expects($this->at(0))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessDeny')->will($this->returnValue(array(new TestController(), 'accessDeny')));
     $this->argumentsResolver->expects($this->at(0))->method('getArguments')->will($this->returnValue(array()));
     $this->controllerResolver->expects($this->at(1))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessAllow')->will($this->returnValue(array(new TestController(), 'accessAllow')));
     $this->argumentsResolver->expects($this->at(1))->method('getArguments')->will($this->returnValue(array()));
     $this->controllerResolver->expects($this->at(2))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessParameter')->will($this->returnValue(array(new TestController(), 'accessParameter')));
     $this->argumentsResolver->expects($this->at(2))->method('getArguments')->will($this->returnValue(array('parameter' => 'TRUE')));
     $route = new Route('/test-route', array(), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessDeny'));
     $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $this->assertSame(AccessInterface::DENY, $this->accessChecker->access($route, $request, $account));
     $route = new Route('/test-route', array(), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessAllow'));
     $this->assertSame(AccessInterface::ALLOW, $this->accessChecker->access($route, $request, $account));
     $route = new Route('/test-route', array('parameter' => 'TRUE'), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessParameter'));
     $this->assertSame(AccessInterface::ALLOW, $this->accessChecker->access($route, $request, $account));
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:20,代码来源:CustomAccessCheckTest.php

示例14: testDynamicTitle

 /**
  * Tests a dynamic title.
  *
  * @see \Drupal\Core\Controller\TitleResolver::getTitle()
  */
 public function testDynamicTitle()
 {
     $request = new Request();
     $route = new Route('/test-route', array('_title' => 'static title', '_title_callback' => 'Drupal\\Tests\\Core\\Controller\\TitleCallback::example'));
     $callable = array(new TitleCallback(), 'example');
     $this->controllerResolver->expects($this->once())->method('getControllerFromDefinition')->with('Drupal\\Tests\\Core\\Controller\\TitleCallback::example')->will($this->returnValue($callable));
     $this->controllerResolver->expects($this->once())->method('getArguments')->with($request, $callable)->will($this->returnValue(array('example')));
     $this->assertEquals('test example', $this->titleResolver->getTitle($request, $route));
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:14,代码来源:TitleResolverTest.php

示例15: onController

 /**
  * Ensures bubbleable metadata from early rendering is not lost.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
  *   The controller event.
  */
 public function onController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     // See \Symfony\Component\HttpKernel\HttpKernel::handleRaw().
     $arguments = $this->controllerResolver->getArguments($event->getRequest(), $controller);
     $event->setController(function () use($controller, $arguments) {
         return $this->wrapControllerExecutionInRenderContext($controller, $arguments);
     });
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:15,代码来源:EarlyRenderingControllerWrapperSubscriber.php


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