22fb90f0c18e99379bc91ff851a2e6a589173f7b
[yaffs-website] / web / core / lib / Drupal / Core / StreamWrapper / PrivateStream.php
1 <?php
2
3 namespace Drupal\Core\StreamWrapper;
4
5 use Drupal\Core\Routing\UrlGeneratorTrait;
6 use Drupal\Core\Site\Settings;
7
8 /**
9  * Drupal private (private://) stream wrapper class.
10  *
11  * Provides support for storing privately accessible files with the Drupal file
12  * interface.
13  */
14 class PrivateStream extends LocalStream {
15
16   use UrlGeneratorTrait;
17
18   /**
19    * {@inheritdoc}
20    */
21   public static function getType() {
22     return StreamWrapperInterface::LOCAL_NORMAL;
23   }
24
25   /**
26    * {@inheritdoc}
27    */
28   public function getName() {
29     return t('Private files');
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public function getDescription() {
36     return t('Private local files served by Drupal.');
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function getDirectoryPath() {
43     return static::basePath();
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getExternalUrl() {
50     $path = str_replace('\\', '/', $this->getTarget());
51     return $this->url('system.private_file_download', ['filepath' => $path], ['absolute' => TRUE, 'path_processing' => FALSE]);
52   }
53
54   /**
55    * Returns the base path for private://.
56    *
57    * Note that this static method is used by \Drupal\system\Form\FileSystemForm
58    * so you should alter that form or substitute a different form if you change
59    * the class providing the stream_wrapper.private service.
60    *
61    * @return string
62    *   The base path for private://.
63    */
64   public static function basePath() {
65     return Settings::get('file_private_path');
66   }
67
68 }