class PathProcessorSessions

Same name in other branches
  1. 8.x-1.x stream_wrapper_example/src/PathProcessor/PathProcessorSessions.php \Drupal\stream_wrapper_example\PathProcessor\PathProcessorSessions
  2. 4.0.x modules/stream_wrapper_example/src/PathProcessor/PathProcessorSessions.php \Drupal\stream_wrapper_example\PathProcessor\PathProcessorSessions

Defines a path processor to rewrite file URLs.

As the route system does not allow arbitrary amount of parameters convert the file path to a query parameter on the request. This is similar to what Core does for the system/files/* URLs.

Hierarchy

Expanded class hierarchy of PathProcessorSessions

1 string reference to 'PathProcessorSessions'
stream_wrapper_example.services.yml in modules/stream_wrapper_example/stream_wrapper_example.services.yml
modules/stream_wrapper_example/stream_wrapper_example.services.yml
1 service uses PathProcessorSessions
path_processor.sessions in modules/stream_wrapper_example/stream_wrapper_example.services.yml
Drupal\stream_wrapper_example\PathProcessor\PathProcessorSessions

File

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

Namespace

Drupal\stream_wrapper_example\PathProcessor
View source
class PathProcessorSessions implements InboundPathProcessorInterface {
    
    /**
     * {@inheritdoc}
     */
    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;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
PathProcessorSessions::processInbound public function Processes the inbound path. Overrides InboundPathProcessorInterface::processInbound