You are here

public function LocalPathProcessor::processInbound in Flysystem 8

Same name and namespace in other branches
  1. 3.x src/PathProcessor/LocalPathProcessor.php \Drupal\flysystem\PathProcessor\LocalPathProcessor::processInbound()
  2. 2.0.x src/PathProcessor/LocalPathProcessor.php \Drupal\flysystem\PathProcessor\LocalPathProcessor::processInbound()
  3. 3.0.x src/PathProcessor/LocalPathProcessor.php \Drupal\flysystem\PathProcessor\LocalPathProcessor::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

src/PathProcessor/LocalPathProcessor.php, line 47

Class

LocalPathProcessor
Defines a path processor to serve public files directly for the local adapter.

Namespace

Drupal\flysystem\PathProcessor

Code

public function processInbound($path, Request $request) {
  if (strpos($path, '/' . $this->root . '/') !== 0) {
    return $path;
  }
  $rest = substr($path, strlen($this->root) + 2);
  if (strpos($rest, 'styles/') === 0 && substr_count($rest, '/') >= 3) {
    list(, $image_style, $scheme, $file) = explode('/', $rest, 4);

    // Set the file as query parameter.
    $request->query
      ->set('file', $file);
    return '/' . $this->root . '/styles/' . $image_style . '/' . $scheme;
  }
  $request->query
    ->set('file', $rest);
  return '/' . $this->root;
}