class PathProcessorSessions

Same name in other branches
  1. 3.x modules/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

  • class \Drupal\stream_wrapper_example\PathProcessor\PathProcessorSessions implements \Drupal\Core\PathProcessor\InboundPathProcessorInterface

Expanded class hierarchy of PathProcessorSessions

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

File

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
PathProcessorSessions::processInbound public function