TemporaryStream.php 999 Bytes
Newer Older
1 2 3 4
<?php

namespace Drupal\Core\StreamWrapper;

5
use Drupal\Core\Url;
6

7 8 9 10 11 12 13 14
/**
 * Defines a Drupal temporary (temporary://) stream wrapper class.
 *
 * Provides support for storing temporarily accessible files with the Drupal
 * file interface.
 */
class TemporaryStream extends LocalStream {

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  /**
   * {@inheritdoc}
   */
  public static function getType() {
    return StreamWrapperInterface::LOCAL_HIDDEN;
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return t('Temporary files');
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return t('Temporary local files for upload and previews.');
  }

36
  /**
37
   * {@inheritdoc}
38 39
   */
  public function getDirectoryPath() {
40
    return file_directory_temp();
41 42 43
  }

  /**
44
   * {@inheritdoc}
45 46 47
   */
  public function getExternalUrl() {
    $path = str_replace('\\', '/', $this->getTarget());
48
    return Url::fromRoute('system.temporary', [], ['absolute' => TRUE, 'query' => ['file' => $path]])->toString();
49
  }
50

51
}