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

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

namespace Drupal\Core\StreamWrapper;

10 11
use Drupal\Component\Utility\Settings;

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

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

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

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

46
}