You are here

class LocalPathProcessor in Flysystem 8

Same name and namespace in other branches
  1. 3.x src/PathProcessor/LocalPathProcessor.php \Drupal\flysystem\PathProcessor\LocalPathProcessor
  2. 2.0.x src/PathProcessor/LocalPathProcessor.php \Drupal\flysystem\PathProcessor\LocalPathProcessor
  3. 3.0.x src/PathProcessor/LocalPathProcessor.php \Drupal\flysystem\PathProcessor\LocalPathProcessor

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

As the route system does not allow arbitrary amount of parameters convert the file path to a query parameter on the request.

Hierarchy

Expanded class hierarchy of LocalPathProcessor

2 files declare their use of LocalPathProcessor
FlysystemServiceProviderTest.php in tests/src/Unit/FlysystemServiceProviderTest.php
LocalPathProcessorTest.php in tests/src/Unit/PathProcessor/LocalPathProcessorTest.php

File

src/PathProcessor/LocalPathProcessor.php, line 16

Namespace

Drupal\flysystem\PathProcessor
View source
class LocalPathProcessor implements InboundPathProcessorInterface {

  /**
   * The root of the local filesystem.
   *
   * @var string
   */
  protected $root;

  /**
   * The scheme.
   *
   * @var string
   */
  protected $scheme;

  /**
   * Constructs a LocalPathProcessor.
   *
   * @param string $scheme
   *   The public scheme.
   */
  public function __construct($scheme) {
    $this->scheme = $scheme;
    $settings = Settings::get('flysystem', []);
    $this->root = $settings[$scheme]['config']['root'];
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LocalPathProcessor::$root protected property The root of the local filesystem.
LocalPathProcessor::$scheme protected property The scheme.
LocalPathProcessor::processInbound public function Processes the inbound path. Overrides InboundPathProcessorInterface::processInbound
LocalPathProcessor::__construct public function Constructs a LocalPathProcessor.