class LocalPathProcessor in Flysystem 8
Same name and namespace in other branches
- 3.x src/PathProcessor/LocalPathProcessor.php \Drupal\flysystem\PathProcessor\LocalPathProcessor
- 2.0.x src/PathProcessor/LocalPathProcessor.php \Drupal\flysystem\PathProcessor\LocalPathProcessor
- 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
- class \Drupal\flysystem\PathProcessor\LocalPathProcessor implements InboundPathProcessorInterface
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\PathProcessorView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LocalPathProcessor:: |
protected | property | The root of the local filesystem. | |
LocalPathProcessor:: |
protected | property | The scheme. | |
LocalPathProcessor:: |
public | function |
Processes the inbound path. Overrides InboundPathProcessorInterface:: |
|
LocalPathProcessor:: |
public | function | Constructs a LocalPathProcessor. |