annotate core/lib/Drupal/Core/StreamWrapper/PrivateStream.php @ 0:4c8ae668cc8c

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