|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jenko\Flysystem; |
|
4
|
|
|
|
|
5
|
|
|
use Gaufrette\Adapter; |
|
6
|
|
|
use League\Flysystem\Adapter\AbstractAdapter; |
|
7
|
|
|
use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait; |
|
8
|
|
|
use League\Flysystem\Adapter\Polyfill\StreamedReadingTrait; |
|
9
|
|
|
use League\Flysystem\Config; |
|
10
|
|
|
|
|
11
|
|
|
class GaufretteAdapter extends AbstractAdapter |
|
12
|
|
|
{ |
|
13
|
|
|
use NotSupportingVisibilityTrait; |
|
14
|
|
|
use StreamedReadingTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var Adapter |
|
18
|
|
|
*/ |
|
19
|
|
|
private $adapter; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param Adapter $adapter |
|
23
|
|
|
*/ |
|
24
|
75 |
|
public function __construct(Adapter $adapter) |
|
25
|
|
|
{ |
|
26
|
75 |
|
$this->adapter = $adapter; |
|
27
|
75 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
6 |
|
public function write($path, $contents, Config $config) |
|
33
|
|
|
{ |
|
34
|
6 |
|
$result = $this->adapter->write($path, $contents); |
|
35
|
|
|
|
|
36
|
6 |
|
if ($result === false) { |
|
37
|
3 |
|
return false; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
3 |
|
return ['type' => 'file', 'contents' => $contents, 'size' => $result, 'path' => $path]; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
6 |
|
public function writeStream($path, $resource, Config $config) |
|
47
|
2 |
|
{ |
|
48
|
6 |
|
$contents = stream_get_contents($resource); |
|
49
|
6 |
|
$result = $this->adapter->write($path, $contents); |
|
50
|
|
|
|
|
51
|
6 |
|
if ($result === false) { |
|
52
|
3 |
|
return false; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
3 |
|
return ['type' => 'file', 'contents' => $contents, 'size' => $result, 'path' => $path]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
3 |
|
public function update($path, $contents, Config $config) |
|
62
|
|
|
{ |
|
63
|
3 |
|
throw new UnsupportedAdapterMethodException('update is not supported by this adapter.'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
3 |
|
public function updateStream($path, $resource, Config $config) |
|
70
|
|
|
{ |
|
71
|
3 |
|
throw new UnsupportedAdapterMethodException('update is not supported by this adapter.'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
3 |
|
public function rename($path, $newpath) |
|
78
|
|
|
{ |
|
79
|
3 |
|
return $this->adapter->rename($path, $newpath); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function copy($path, $newpath) |
|
86
|
|
|
{ |
|
87
|
3 |
|
throw new UnsupportedAdapterMethodException('copy is not supported by this adapter.'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
3 |
|
public function delete($path) |
|
94
|
|
|
{ |
|
95
|
3 |
|
return $this->adapter->delete($path); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
6 |
|
public function deleteDir($dirname) |
|
102
|
|
|
{ |
|
103
|
6 |
|
if ($this->adapter->isDirectory($dirname)) { |
|
104
|
3 |
|
return $this->adapter->delete($dirname); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
3 |
|
throw new \InvalidArgumentException($dirname . 'is not a valid directory.'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* {@inheritdoc} |
|
112
|
|
|
*/ |
|
113
|
3 |
|
public function createDir($dirname, Config $config) |
|
114
|
|
|
{ |
|
115
|
3 |
|
throw new UnsupportedAdapterMethodException('createDir is not supported by this adapter.'); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* {@inheritdoc} |
|
120
|
|
|
*/ |
|
121
|
3 |
|
public function has($path) |
|
122
|
|
|
{ |
|
123
|
3 |
|
return $this->adapter->exists($path); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* {@inheritdoc} |
|
128
|
|
|
*/ |
|
129
|
6 |
|
public function read($path) |
|
130
|
|
|
{ |
|
131
|
6 |
|
return ['contents' => $this->adapter->read($path), 'path' => $path]; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* {@inheritdoc} |
|
136
|
|
|
*/ |
|
137
|
3 |
|
public function listContents($directory = '', $recursive = false) |
|
138
|
|
|
{ |
|
139
|
3 |
|
return $this->adapter->keys(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* {@inheritdoc} |
|
144
|
|
|
*/ |
|
145
|
6 |
|
public function getMetadata($path) |
|
146
|
|
|
{ |
|
147
|
6 |
|
if ($this->adapter instanceof Adapter\MetadataSupporter) { |
|
148
|
3 |
|
return $this->adapter->getMetadata($path); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
3 |
|
throw new UnsupportedAdapterMethodException('getMetadata is not supported by this adapter.'); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* {@inheritdoc} |
|
156
|
|
|
*/ |
|
157
|
6 |
|
public function getSize($path) |
|
158
|
|
|
{ |
|
159
|
6 |
|
if ($this->adapter instanceof Adapter\SizeCalculator) { |
|
160
|
3 |
|
return $this->adapter->size($path); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
3 |
|
throw new UnsupportedAdapterMethodException('getSize is not supported by this adapter.'); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* {@inheritdoc} |
|
168
|
|
|
*/ |
|
169
|
6 |
|
public function getMimetype($path) |
|
170
|
|
|
{ |
|
171
|
6 |
|
if ($this->adapter instanceof Adapter\MimeTypeProvider) { |
|
172
|
3 |
|
return $this->adapter->mimeType($path); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
3 |
|
throw new UnsupportedAdapterMethodException('getMimetype is not supported by this adapter.'); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* {@inheritdoc} |
|
180
|
|
|
*/ |
|
181
|
3 |
|
public function getTimestamp($path) |
|
182
|
|
|
{ |
|
183
|
3 |
|
$timestamp = $this->adapter->mtime($path); |
|
184
|
|
|
|
|
185
|
3 |
|
return ['timestamp' => $timestamp]; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|