Further modules included.
[yaffs-website] / web / modules / contrib / libraries / tests / src / Kernel / ExternalLibrary / TestLibraryFilesStream.php
1 <?php
2
3 namespace Drupal\Tests\libraries\Kernel\ExternalLibrary;
4
5 use Drupal\Core\Extension\ModuleHandlerInterface;
6 use Drupal\Core\StreamWrapper\LocalStream;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 use Drupal\Core\StringTranslation\TranslationInterface;
9 use Drupal\libraries\StreamWrapper\LocalHiddenStreamTrait;
10 use Drupal\libraries\StreamWrapper\PrivateStreamTrait;
11
12 /**
13  * Provides a stream wrapper for accessing test library files.
14  */
15 class TestLibraryFilesStream extends LocalStream {
16
17   use LocalHiddenStreamTrait;
18   use PrivateStreamTrait;
19   use StringTranslationTrait;
20
21   /**
22    * The module handler.
23    *
24    * @var \Drupal\Core\Extension\ModuleHandlerInterface
25    */
26   protected $moduleHandler;
27
28   /**
29    * The test directory.
30    *
31    * @var string
32    */
33   protected $directory;
34
35   /**
36    * Constructs a stream wrapper for test library files.
37    *
38    * Dependency injection is generally not possible to implement for stream
39    * wrappers, because stream wrappers are initialized before the container is
40    * booted, but this stream wrapper is only registered explicitly from tests
41    * so it is possible here.
42    *
43    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
44    *   The module handler.
45    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
46    *   The string translation handler.
47    * @param string $directory
48    *   The directory within the Libraries API's tests directory that is to be
49    *   searched for test library files.
50    */
51   public function __construct(ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, $directory) {
52     $this->moduleHandler = $module_handler;
53     $this->directory = (string) $directory;
54
55     $this->setStringTranslation($string_translation);
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function getName() {
62     $this->t('Test library files');
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function getDescription() {
69     $this->t('Provides access to test library files.');
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   public function getDirectoryPath() {
76     $module_path = $this->moduleHandler->getModule('libraries')->getPath();
77     return $module_path . '/tests/' . $this->directory;
78   }
79
80 }