3 namespace Drupal\libraries\StreamWrapper;
5 use Drupal\Core\StreamWrapper\LocalStream;
8 * Provides a stream wrapper for library definitions.
10 * Can be used with the 'library-definitions' scheme, for example
11 * 'library-definitions://example.json' for a library ID of 'example'.
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
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
26 * @see \Drupal\locale\StreamWrapper\TranslationsStream
28 * @todo Use a setting instead of configuration for the directory.
30 class LibraryDefinitionsStream extends LocalStream {
32 use LocalHiddenStreamTrait;
33 use PrivateStreamTrait;
38 * @var \Drupal\Core\Config\ConfigFactoryInterface
40 protected $configFactory;
43 * Constructs an external library registry.
45 * @todo Dependency injection.
47 public function __construct() {
48 $this->configFactory = \Drupal::configFactory();
54 public function getName() {
55 return t('Library definitions');
61 public function getDescription() {
62 return t('Provides access to library definition files.');
68 public function getDirectoryPath() {
69 return $this->getConfig('local.path');
73 * Fetches a configuration value from the library definitions configuration.
75 * The configuration key to fetch.
77 * @return array|mixed|null
78 * The configuration value.
80 protected function getConfig($key) {
81 return $this->configFactory
82 ->get('libraries.settings')
83 ->get("definitions.$key");