PublicStream.php 953 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php

/**
 * @file
 * Definition of Drupal\Core\StreamWrapper\PublicStream.
 */

namespace Drupal\Core\StreamWrapper;

/**
 * Defines a Drupal public (public://) stream wrapper class.
 *
 * Provides support for storing publicly accessible files with the Drupal file
 * interface.
 */
class PublicStream extends LocalStream {

  /**
19
   * {@inheritdoc}
20 21
   */
  public function getDirectoryPath() {
22
    return static::basePath();
23 24 25
  }

  /**
26
   * {@inheritdoc}
27
   */
28
  public function getExternalUrl() {
29 30 31
    $path = str_replace('\\', '/', $this->getTarget());
    return $GLOBALS['base_url'] . '/' . self::getDirectoryPath() . '/' . drupal_encode_path($path);
  }
32 33 34 35 36 37 38 39 40 41 42 43

  /**
   * Returns the base path for public://.
   *
   * @return string
   *   The base path for public:// typically sites/default/files.
   */
  public static function basePath() {
    $base_path = settings()->get('file_public_path', conf_path() . '/files');
    return $base_path;
  }

44
}