You are here

class PrivateStream in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/StreamWrapper/PrivateStream.php \Drupal\Core\StreamWrapper\PrivateStream
  2. 9 core/lib/Drupal/Core/StreamWrapper/PrivateStream.php \Drupal\Core\StreamWrapper\PrivateStream

Drupal private (private://) stream wrapper class.

Provides support for storing privately accessible files with the Drupal file interface.

Hierarchy

Expanded class hierarchy of PrivateStream

4 files declare their use of PrivateStream
FileSystemForm.php in core/modules/system/src/Form/FileSystemForm.php
HtaccessWriter.php in core/lib/Drupal/Core/File/HtaccessWriter.php
ImageStyleCustomStreamWrappersTest.php in core/modules/image/tests/src/Kernel/ImageStyleCustomStreamWrappersTest.php
system.install in core/modules/system/system.install
Install, update and uninstall functions for the system module.

File

core/lib/Drupal/Core/StreamWrapper/PrivateStream.php, line 14

Namespace

Drupal\Core\StreamWrapper
View source
class PrivateStream extends LocalStream {

  /**
   * {@inheritdoc}
   */
  public static function getType() {
    return StreamWrapperInterface::LOCAL_NORMAL;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return t('Private local files served by Drupal.');
  }

  /**
   * {@inheritdoc}
   */
  public function getDirectoryPath() {
    return static::basePath();
  }

  /**
   * {@inheritdoc}
   */
  public function getExternalUrl() {
    $path = str_replace('\\', '/', $this
      ->getTarget());
    return Url::fromRoute('system.private_file_download', [
      'filepath' => $path,
    ], [
      'absolute' => TRUE,
      'path_processing' => FALSE,
    ])
      ->toString();
  }

  /**
   * Returns the base path for private://.
   *
   * Note that this static method is used by \Drupal\system\Form\FileSystemForm
   * so you should alter that form or substitute a different form if you change
   * the class providing the stream_wrapper.private service.
   *
   * @return string|null
   *   The base path for private://. NULL means the private directory is not
   *   set.
   */
  public static function basePath() {
    return Settings::get('file_private_path');
  }

}

Members