Further modules included.
[yaffs-website] / web / modules / contrib / libraries / src / StreamWrapper / LibraryDefinitionsStream.php
1 <?php
2
3 namespace Drupal\libraries\StreamWrapper;
4
5 use Drupal\Core\StreamWrapper\LocalStream;
6
7 /**
8  * Provides a stream wrapper for library definitions.
9  *
10  * Can be used with the 'library-definitions' scheme, for example
11  * 'library-definitions://example.json' for a library ID of 'example'.
12  *
13  * By default this stream wrapper reads from a single directory that is
14  * configurable and points to the 'library-definitions' directory within the
15  * public files directory by default. This makes library definitions writable
16  * by the webserver by default, which is in anticipation of a user interface
17  * that fetches definitions from a remote repository and stores them locally.
18  * For improved security the library definitions can be managed manually (or put
19  * under version control) and placed in a directory that is not writable by the
20  * webserver.
21  *
22  * The idea of using a stream wrapper for this as well as the default location
23  * is taken from the 'translations' stream wrapper provided by the Interface
24  * Translation module.
25  *
26  * @see \Drupal\locale\StreamWrapper\TranslationsStream
27  *
28  * @todo Use a setting instead of configuration for the directory.
29  */
30 class LibraryDefinitionsStream extends LocalStream {
31
32   use LocalHiddenStreamTrait;
33   use PrivateStreamTrait;
34
35   /**
36    * The config factory
37    *
38    * @var \Drupal\Core\Config\ConfigFactoryInterface
39    */
40   protected $configFactory;
41
42   /**
43    * Constructs an external library registry.
44    *
45    * @todo Dependency injection.
46    */
47   public function __construct() {
48     $this->configFactory = \Drupal::configFactory();
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getName() {
55     return t('Library definitions');
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function getDescription() {
62     return t('Provides access to library definition files.');
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function getDirectoryPath() {
69     return $this->getConfig('local.path');
70   }
71
72   /**
73    * Fetches a configuration value from the library definitions configuration.
74    * @param $key
75    *   The configuration key to fetch.
76    *
77    * @return array|mixed|null
78    *   The configuration value.
79    */
80   protected function getConfig($key) {
81     return $this->configFactory
82       ->get('libraries.settings')
83       ->get("definitions.$key");
84   }
85
86 }