public function FlysystemPathProcessor::processInbound in Flysystem 8
Same name and namespace in other branches
- 3.x src/PathProcessor/FlysystemPathProcessor.php \Drupal\flysystem\PathProcessor\FlysystemPathProcessor::processInbound()
- 2.0.x src/PathProcessor/FlysystemPathProcessor.php \Drupal\flysystem\PathProcessor\FlysystemPathProcessor::processInbound()
- 3.0.x src/PathProcessor/FlysystemPathProcessor.php \Drupal\flysystem\PathProcessor\FlysystemPathProcessor::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/ FlysystemPathProcessor.php, line 19
Class
- FlysystemPathProcessor
- Defines a path processor to rewrite Flysystem URLs.
Namespace
Drupal\flysystem\PathProcessorCode
public function processInbound($path, Request $request) {
// Quick exit.
if (strpos($path, '/_flysystem/') !== 0) {
return $path;
}
// Stream wrapper protocols must conform to /^[a-zA-Z0-9+.-]+$/
// Via php_stream_wrapper_scheme_validate() in the PHP source.
if (!preg_match('|^/_flysystem/([a-zA-Z0-9+.-]+)/|', $path, $matches)) {
return $path;
}
$rest = substr($path, strlen($matches[0]));
// Support image styles.
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 '/_flysystem/styles/' . $image_style . '/' . $scheme;
}
// Routes to FileDownloadController::download().
$request->query
->set('file', $rest);
return '/_flysystem/' . $matches[1];
}