PublicStream.php 1 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

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

namespace Drupal\Core\StreamWrapper;

10
use Drupal\Component\Utility\UrlHelper;
11
use Drupal\Core\Site\Settings;
12

13 14 15 16 17 18 19 20 21
/**
 * Defines a Drupal public (public://) stream wrapper class.
 *
 * Provides support for storing publicly accessible files with the Drupal file
 * interface.
 */
class PublicStream extends LocalStream {

  /**
22
   * {@inheritdoc}
23 24
   */
  public function getDirectoryPath() {
25
    return static::basePath();
26 27 28
  }

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

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

47
}