Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Component / PhpStorage / FileReadOnlyStorage.php
1 <?php
2
3 namespace Drupal\Component\PhpStorage;
4
5 /**
6  * Reads code as regular PHP files, but won't write them.
7  */
8 class FileReadOnlyStorage implements PhpStorageInterface {
9
10   /**
11    * The directory where the files should be stored.
12    *
13    * @var string
14    */
15   protected $directory;
16
17   /**
18    * Constructs this FileStorage object.
19    *
20    * @param $configuration
21    *   An associative array, containing at least two keys (the rest are ignored):
22    *   - directory: The directory where the files should be stored.
23    *   - bin: The storage bin. Multiple storage objects can be instantiated with
24    *   the same configuration, but for different bins.
25    */
26   public function __construct(array $configuration) {
27
28     $this->directory = $configuration['directory'] . '/' . $configuration['bin'];
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function exists($name) {
35     return file_exists($this->getFullPath($name));
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function load($name) {
42     // The FALSE returned on failure is enough for the caller to handle this,
43     // we do not want a warning too.
44     return (@include_once $this->getFullPath($name)) !== FALSE;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function save($name, $code) {
51     return FALSE;
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function delete($name) {
58     return FALSE;
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function getFullPath($name) {
65     return $this->directory . '/' . $name;
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function writeable() {
72     return FALSE;
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function deleteAll() {
79     return FALSE;
80   }
81
82   /**
83    * {@inheritdoc}
84    */
85   public function listAll() {
86     $names = [];
87     if (file_exists($this->directory)) {
88       foreach (new \DirectoryIterator($this->directory) as $fileinfo) {
89         if (!$fileinfo->isDot()) {
90           $name = $fileinfo->getFilename();
91           if ($name != '.htaccess') {
92             $names[] = $name;
93           }
94         }
95       }
96     }
97     return $names;
98   }
99
100   /**
101    * {@inheritdoc}
102    */
103   public function garbageCollection() {
104   }
105
106 }