TemporaryStream.php 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Drupal\Core\StreamWrapper;
  3. use Drupal\Core\Url;
  4. /**
  5. * Defines a Drupal temporary (temporary://) stream wrapper class.
  6. *
  7. * Provides support for storing temporarily accessible files with the Drupal
  8. * file interface.
  9. */
  10. class TemporaryStream extends LocalStream {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public static function getType() {
  15. return StreamWrapperInterface::LOCAL_HIDDEN;
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function getName() {
  21. return t('Temporary files');
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function getDescription() {
  27. return t('Temporary local files for upload and previews.');
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function getDirectoryPath() {
  33. return file_directory_temp();
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function getExternalUrl() {
  39. $path = str_replace('\\', '/', $this->getTarget());
  40. return Url::fromRoute('system.temporary', [], ['absolute' => TRUE, 'query' => ['file' => $path]])->toString();
  41. }
  42. }