You are here

public function PathProcessorSessions::processInbound in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 stream_wrapper_example/src/PathProcessor/PathProcessorSessions.php \Drupal\stream_wrapper_example\PathProcessor\PathProcessorSessions::processInbound()

Processes the inbound path.

Implementations may make changes to the request object passed in but should avoid all other side effects. This method can be called to process requests other than the current request.

Parameters

string $path: The path to process, with a leading slash.

\Symfony\Component\HttpFoundation\Request $request: The HttpRequest object representing the request to process. Note, if this method is being called via the path_processor_manager service and is not part of routing, the current request object must be cloned before being passed in.

Return value

string The processed path.

Overrides InboundPathProcessorInterface::processInbound

File

modules/stream_wrapper_example/src/PathProcessor/PathProcessorSessions.php, line 20

Class

PathProcessorSessions
Defines a path processor to rewrite file URLs.

Namespace

Drupal\stream_wrapper_example\PathProcessor

Code

public function processInbound($path, Request $request) {
  if (strpos($path, '/examples/stream_wrapper_example/files/') === 0 && !$request->query
    ->has('file')) {
    $file_path = preg_replace('|^\\/examples\\/stream_wrapper_example\\/files\\/|', '', $path);
    $request->query
      ->set('file', $file_path);

    // We return the route we want to match.
    return '/examples/stream_wrapper_example/files';
  }
  return $path;
}