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