stream_wrapper_example.services.yml 1.8 KB

12345678910111213141516171819202122232425262728293031323334
  1. #
  2. # As part of our demo, we implement a simple "file system" that lets us read and write
  3. # files out of the $_SESSION. This isn't very practical, but it's a simple way to
  4. # demonstrate what you can do with PHP's stream wrappers.
  5. #
  6. # To get a stream wrapper to work to define a stream wrapper class, we need to register
  7. # that with the system. We can either do this manually by calling up the 'stream_wrapper.manager'
  8. # service, but the better way to do this is to have the system autoload it by tagging the service,
  9. # as we do here.
  10. #
  11. # We also want to securely serve up our fake session files. We'd like to use the same nice
  12. # file paths that Core uses for private files. Since Drupal 8 no longer allows us to have
  13. # "menu tails" (i.e., extra/parts/of/the/path after the default part of the path), we need
  14. # to get some router superpowers. Our route (in stream_wrapper_example.routing.yml) will "gather up"
  15. # the path with with a regular expression. But we need to do a little more that that. We
  16. # also need to convince the routing system to see our weird, extra long route route. We
  17. # do that using a "Path Processor". We register the path_process.sessions service with special
  18. # tags to get it loaded for when the Drupal's routing system decides which path should get
  19. # used.
  20. #
  21. # @see src/StreamWrapper/FileExampleSessionStreamWrapper.php
  22. # @see src/PathProcessor/PathProcessorSessions.php
  23. # @see stream_wrapper_example.routing.yml
  24. #
  25. services:
  26. stream_wrapper_example.stream_wrapper:
  27. class: Drupal\stream_wrapper_example\StreamWrapper\FileExampleSessionStreamWrapper
  28. tags:
  29. - { name: stream_wrapper, scheme: session }
  30. path_processor.sessions:
  31. class: Drupal\stream_wrapper_example\PathProcessor\PathProcessorSessions
  32. tags:
  33. - { name: path_processor_inbound, priority: 200 }