processInbound example



    // Create the processor manager and add the processors.     $processor_manager = new PathProcessorManager();
    foreach ($priorities as $priority => $processor) {
      $processor_manager->addInbound($processor$priority);
    }

    // Test resolving the French homepage using the incorrect processor order.     $test_path = '/fr';
    $request = Request::create($test_path);
    $processed = $processor_manager->processInbound($test_path$request);
    $this->assertEquals('/', $processed, 'Processing in the incorrect order fails to resolve the system path from the empty path');

    // Test resolving an existing alias using the incorrect processor order.     $test_path = '/fr/foo';
    $request = Request::create($test_path);
    $processed = $processor_manager->processInbound($test_path$request);
    $this->assertEquals('/foo', $processed, 'Processing in the incorrect order fails to resolve the system path from an alias');

    // Now create a new processor manager and add the processors, this time in     // the correct order.     $processor_manager = new PathProcessorManager();
    

  protected function getRequestForPath($path, array $exclude) {
    if (!empty($exclude[$path])) {
      return NULL;
    }
    $request = Request::create($path);
    // Performance optimization: set a short accept header to reduce overhead in     // AcceptHeaderMatcher when matching the request.     $request->headers->set('Accept', 'text/html');
    // Find the system path by resolving aliases, language prefix, etc.     $processed = $this->pathProcessor->processInbound($path$request);
    if (empty($processed) || !empty($exclude[$processed])) {
      // This resolves to the front page, which we already add.       return NULL;
    }
    $this->currentPath->setPath($processed$request);
    // Attempt to match this path to provide a fully built request.     try {
      $request->attributes->add($this->router->matchRequest($request));
      return $request;
    }
    catch (ParamNotConvertedException $e) {
      
public function addInbound(InboundPathProcessorInterface $processor$priority = 0) {
    $this->inboundProcessors[$priority][] = $processor;
    $this->sortedInbound = [];
  }

  /** * {@inheritdoc} */
  public function processInbound($path, Request $request) {
    $processors = $this->getInbound();
    foreach ($processors as $processor) {
      $path = $processor->processInbound($path$request);
    }
    return $path;
  }

  /** * Returns the sorted array of inbound processors. * * @return array * An array of processor objects. */
  protected function getInbound() {
    
/** * {@inheritdoc} */
  public function processInbound($path, Request $request) {
    if (!empty($path)) {
      $scope = 'inbound';
      if (!isset($this->processors[$scope])) {
        $this->initProcessors($scope);
      }
      foreach ($this->processors[$scope] as $instance) {
        $path = $instance->processInbound($path$request);
      }
    }
    return $path;
  }

  /** * {@inheritdoc} */
  public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    if (!isset($this->multilingual)) {
      $this->multilingual = $this->languageManager->isMultilingual();
    }
      // based on the path.       $route_match = $this->stackedRouteMatch->getRouteMatchFromRequest($request);
      if ($route_match && !$route_object = $route_match->getRouteObject()) {
        try {
          // Some inbound path processors make changes to the request. Make a           // copy as we're not actually routing the request so we do not want to           // make changes.           $cloned_request = clone $request;
          // Process the path as an inbound path. This will remove any language           // prefixes and other path components that inbound processing would           // clear out, so we can attempt to load the route clearly.           $path = $this->pathProcessorManager->processInbound(urldecode(rtrim($cloned_request->getPathInfo(), '/'))$cloned_request);
          $attributes = $this->router->match($path);
        }
        catch (ResourceNotFoundException $e) {
          return FALSE;
        }
        catch (AccessDeniedHttpException $e) {
          return FALSE;
        }
        $route_object = $attributes[RouteObjectInterface::ROUTE_OBJECT];
      }
      $result = $this->adminContext->isAdminRoute($route_object);
    }

  protected function getPathAttributes($path, Request $request$access_check) {
    if (!$access_check || $this->account->hasPermission('link to any page')) {
      $router = $this->accessUnawareRouter;
    }
    else {
      $router = $this->accessAwareRouter;
    }

    $initial_request_context = $router->getContext() ? $router->getContext() : new RequestContext();
    $path = $this->pathProcessor->processInbound('/' . $path$request);

    try {
      $router->setContext((new RequestContext())->fromRequest($request));
      $result = $router->match($path);
    }
    catch (ResourceNotFoundException $e) {
      $result = FALSE;
    }
    catch (ParamNotConvertedException $e) {
      $result = FALSE;
    }
    
    // routes.     $cid = $this->getRouteCollectionCacheId($request);
    if ($cached = $this->cache->get($cid)) {
      $this->currentPath->setPath($cached->data['path']$request);
      $request->query->replace($cached->data['query']);
      return $cached->data['routes'];
    }
    else {
      // Just trim on the right side.       $path = $request->getPathInfo();
      $path = $path === '/' ? $path : rtrim($request->getPathInfo(), '/');
      $path = $this->pathProcessor->processInbound($path$request);
      $this->currentPath->setPath($path$request);
      // Incoming path processors may also set query parameters.       $query_parameters = $request->query->all();
      $routes = $this->getRoutesByPath(rtrim($path, '/'));
      $cache_value = [
        'path' => $path,
        'query' => $query_parameters,
        'routes' => $routes,
      ];
      $this->cache->set($cid$cache_value, CacheBackendInterface::CACHE_PERMANENT, ['route_match']);
      return $routes;
    }

  public function testProcessInbound() {
    $this->aliasManager->expects($this->exactly(2))
      ->method('getPathByAlias')
      ->willReturnMap([
        ['urlalias', NULL, 'internal-url'],
        ['url', NULL, 'url'],
      ]);

    $request = Request::create('/urlalias');
    $this->assertEquals('internal-url', $this->pathProcessor->processInbound('urlalias', $request));
    $request = Request::create('/url');
    $this->assertEquals('url', $this->pathProcessor->processInbound('url', $request));
  }

  /** * @covers ::processOutbound * * @dataProvider providerTestProcessOutbound */
  public function testProcessOutbound($path, array $options$expected_path) {
    $this->aliasManager->expects($this->any())
      

  public function testProcessInbound($frontpage_path$path$expected, array $expected_query = []) {
    $config_factory = $this->prophesize(ConfigFactoryInterface::class);
    $config = $this->prophesize(ImmutableConfig::class);
    $config_factory->get('system.site')
      ->willReturn($config->reveal());
    $config->get('page.front')
      ->willReturn($frontpage_path);
    $processor = new PathProcessorFront($config_factory->reveal());
    $request = new Request();
    $this->assertEquals($expected$processor->processInbound($path$request));
    $this->assertEquals($expected_query$request->query->all());
  }

  /** * Inbound paths and expected results. */
  public function providerProcessInbound() {
    return [
      'accessing frontpage' => ['/node', '/', '/node'],
      'accessing non frontpage' => ['/node', '/user', '/user'],
      'accessing frontpage with query parameters' => ['/node?example=muh',
        
Home | Imprint | This part of the site doesn't use cookies.