getControllerFromDefinition example

return $callable;
  }

  /** * {@inheritdoc} */
  public function getController(Request $request): callable|FALSE {
    if (!$controller = $request->attributes->get('_controller')) {
      return FALSE;
    }
    return $this->getControllerFromDefinition($controller$request->getPathInfo());
  }

  /** * Returns a callable for the given controller. * * @param string $controller * A Controller string. * * @return mixed * A PHP callable. * * @throws \LogicException * If the controller cannot be parsed. * * @throws \InvalidArgumentException * If the controller class does not exist. */

    }
    return $tree;
  }

  /** * {@inheritdoc} */
  public function transform(array $tree, array $manipulators) {
    foreach ($manipulators as $manipulator) {
      $callable = $manipulator['callable'];
      $callable = $this->controllerResolver->getControllerFromDefinition($callable);
      // Prepare the arguments for the menu tree manipulator callable; the first       // argument is always the menu link tree.       if (isset($manipulator['args'])) {
        array_unshift($manipulator['args']$tree);
        $tree = call_user_func_array($callable$manipulator['args']);
      }
      else {
        $tree = call_user_func($callable$tree);
      }
    }
    return $tree;
  }

  protected function doCallback($callback_type$callback, array $args) {
    if (is_string($callback)) {
      $double_colon = strpos($callback, '::');
      if ($double_colon === FALSE) {
        $callback = $this->controllerResolver->getControllerFromDefinition($callback);
      }
      elseif ($double_colon > 0) {
        $callback = explode('::', $callback, 2);
      }
    }
    $message = sprintf('Render %s callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', $callback_type, '%s');
    // Add \Drupal\Core\Render\Element\RenderCallbackInterface as an extra     // trusted interface so that:     // - All public methods on Render elements are considered trusted.     // - Helper classes that contain only callback methods can implement this     // instead of TrustedCallbackInterface.
// Check that previewing a pending revision of a node works. This can not be     // accomplished through the UI so we have to use API calls.     // @todo Change this test to use the UI when we will be able to create     // pending revisions in core.     // @see https://www.drupal.org/node/2725533     $node->setNewRevision(TRUE);
    $node->isDefaultRevision(FALSE);

    /** @var \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver */
    $controller_resolver = \Drupal::service('controller_resolver');
    $node_preview_controller = $controller_resolver->getControllerFromDefinition('\Drupal\node\Controller\NodePreviewController::view');
    $node_preview_controller($node, 'full');
  }

  /** * Checks the node preview accessible for simultaneous node editing. */
  public function testSimultaneousPreview() {
    $title_key = 'title[0][value]';
    $node = $this->drupalCreateNode([]);

    $edit = [$title_key => 'New page title'];
    

  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
    try {
      $callable = $this->controllerResolver->getControllerFromDefinition($route->getRequirement('_custom_access'));
    }
    catch (\InvalidArgumentException $e) {
      // The custom access controller method was not found.       throw new \BadMethodCallException(sprintf('The "%s" method is not callable as a _custom_access callback in route "%s"', $route->getRequirement('_custom_access')$route->getPath()));
    }

    $arguments_resolver = $this->argumentsResolverFactory->getArgumentsResolver($route_match$account);
    $arguments = $arguments_resolver->getArguments($callable);

    return call_user_func_array($callable$arguments);
  }

}

  protected function buildPermissionsYaml() {
    $all_permissions = [];
    $all_callback_permissions = [];

    foreach ($this->getYamlDiscovery()->findAll() as $provider => $permissions) {
      // The top-level 'permissions_callback' is a list of methods in controller       // syntax, see \Drupal\Core\Controller\ControllerResolver. These methods       // should return an array of permissions in the same structure.       if (isset($permissions['permission_callbacks'])) {
        foreach ($permissions['permission_callbacks'] as $permission_callback) {
          $callback = $this->controllerResolver->getControllerFromDefinition($permission_callback);
          if ($callback_permissions = call_user_func($callback)) {
            // Add any callback permissions to the array of permissions. Any             // defaults can then get processed below.             foreach ($callback_permissions as $name => $callback_permission) {
              if (!is_array($callback_permission)) {
                $callback_permission = [
                  'title' => $callback_permission,
                ];
              }

              $callback_permission += [
                

  public function testBadHashParameter($hash) {
    /** @var callable $controller */
    $controller = $this->container
      ->get('controller_resolver')
      ->getControllerFromDefinition('\Drupal\media\Controller\OEmbedIframeController::render');

    $this->assertIsCallable($controller);

    $this->expectException('\Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
    $this->expectExceptionMessage('This resource is not available');
    $request = new Request([
      'url' => 'https://example.com/path/to/resource',
      'hash' => $hash,
    ]);
    $controller($request);
  }

  

  protected function handleRaw(Request $request) {
    $container = $this->getContainer();

    $this->handleAccess($request);

    /** @var \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver */
    $controller_resolver = $container->get('controller_resolver');

    /** @var callable $db_update_controller */
    $db_update_controller = $controller_resolver->getControllerFromDefinition('\Drupal\system\Controller\DbUpdateController::handle');

    $this->setupRequestMatch($request);

    /** @var \Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface $argument_resolver */
    $argument_resolver = $container->get('http_kernel.controller.argument_resolver');
    $arguments = $argument_resolver->getArguments($request$db_update_controller);
    return call_user_func_array($db_update_controller$arguments);
  }

  /** * Boots up the session. * * This method + shutdownSession() basically simulates what * \Drupal\Core\StackMiddleware\Session does. * * @param \Symfony\Component\HttpFoundation\Request $request * The incoming request. */
$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);
            }
            // Otherwise, add each Route object individually.             else {
              foreach ($callback_routes as $name => $callback_route) {
                $collection->add($name$callback_route);
              }
            }
          }
$this->httpMessageFactory = new PsrHttpFactory(new HttpFactory()new HttpFactory()new HttpFactory()new HttpFactory());
    $this->controllerResolver = new ControllerResolver($this->httpMessageFactory, $class_resolver);
  }

  /** * Tests createController(). * * @dataProvider providerTestCreateController */
  public function testCreateController($controller$class$output) {
    $this->container->set('some_service', new MockController());
    $result = $this->controllerResolver->getControllerFromDefinition($controller);
    $this->assertCallableController($result$class$output);
  }

  /** * Provides test data for testCreateController(). */
  public function providerTestCreateController() {
    return [
      // Tests class::method.       ['Drupal\Tests\Core\Controller\MockController::getResult', 'Drupal\Tests\Core\Controller\MockController', 'This is a regular controller.'],
      // Tests service:method.


  /** * {@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->argumentResolver->getArguments($request$callable);
      $route_title = call_user_func_array($callable$arguments);
    }
    elseif ($route->hasDefault('_title') && strlen($route->getDefault('_title')) > 0) {
      $title = $route->getDefault('_title');
      $options = [];
      if ($route->hasDefault('_title_context')) {
        $options['context'] = $route->getDefault('_title_context');
      }
      $args = [];
      if (($raw_parameters = $request->attributes->get('_raw_variables'))) {
        
Home | Imprint | This part of the site doesn't use cookies.