PrivateStream.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Drupal\Core\StreamWrapper;
  3. use Drupal\Core\Routing\UrlGeneratorTrait;
  4. use Drupal\Core\Site\Settings;
  5. /**
  6. * Drupal private (private://) stream wrapper class.
  7. *
  8. * Provides support for storing privately accessible files with the Drupal file
  9. * interface.
  10. */
  11. class PrivateStream extends LocalStream {
  12. use UrlGeneratorTrait;
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public static function getType() {
  17. return StreamWrapperInterface::LOCAL_NORMAL;
  18. }
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function getName() {
  23. return t('Private files');
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function getDescription() {
  29. return t('Private local files served by Drupal.');
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getDirectoryPath() {
  35. return static::basePath();
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function getExternalUrl() {
  41. $path = str_replace('\\', '/', $this->getTarget());
  42. return $this->url('system.private_file_download', ['filepath' => $path], ['absolute' => TRUE, 'path_processing' => FALSE]);
  43. }
  44. /**
  45. * Returns the base path for private://.
  46. *
  47. * Note that this static method is used by \Drupal\system\Form\FileSystemForm
  48. * so you should alter that form or substitute a different form if you change
  49. * the class providing the stream_wrapper.private service.
  50. *
  51. * @return string
  52. * The base path for private://.
  53. */
  54. public static function basePath() {
  55. return Settings::get('file_private_path');
  56. }
  57. }