1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Flysystem; |
4
|
|
|
|
5
|
|
|
use BadMethodCallException; |
6
|
|
|
|
7
|
|
|
abstract class Handler |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
protected $path; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var FilesystemInterface |
16
|
|
|
*/ |
17
|
|
|
protected $filesystem; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Constructor. |
21
|
|
|
* |
22
|
|
|
* @param FilesystemInterface $filesystem |
23
|
|
|
* @param string $path |
24
|
|
|
*/ |
25
|
117 |
|
public function __construct(FilesystemInterface $filesystem = null, $path = null) |
26
|
|
|
{ |
27
|
117 |
|
$this->path = $path; |
28
|
117 |
|
$this->filesystem = $filesystem; |
29
|
117 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Check whether the entree is a directory. |
33
|
|
|
* |
34
|
|
|
* @return bool |
35
|
|
|
*/ |
36
|
3 |
|
public function isDir() |
37
|
|
|
{ |
38
|
3 |
|
return $this->getType() === 'dir'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Check whether the entree is a file. |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
3 |
|
public function isFile() |
47
|
|
|
{ |
48
|
3 |
|
return $this->getType() === 'file'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Retrieve the entree type (file|dir). |
53
|
|
|
* |
54
|
|
|
* @return string file or dir |
55
|
|
|
*/ |
56
|
6 |
|
public function getType() |
57
|
|
|
{ |
58
|
6 |
|
$metadata = $this->filesystem->getMetadata($this->path); |
59
|
|
|
|
60
|
6 |
|
return $metadata['type']; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Set the Filesystem object. |
65
|
|
|
* |
66
|
|
|
* @param FilesystemInterface $filesystem |
67
|
|
|
* |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
114 |
|
public function setFilesystem(FilesystemInterface $filesystem) |
71
|
|
|
{ |
72
|
114 |
|
$this->filesystem = $filesystem; |
73
|
|
|
|
74
|
114 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Retrieve the Filesystem object. |
79
|
|
|
* |
80
|
|
|
* @return FilesystemInterface |
81
|
|
|
*/ |
82
|
3 |
|
public function getFilesystem() |
83
|
|
|
{ |
84
|
3 |
|
return $this->filesystem; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Set the entree path. |
89
|
|
|
* |
90
|
|
|
* @param string $path |
91
|
|
|
* |
92
|
|
|
* @return $this |
93
|
|
|
*/ |
94
|
75 |
|
public function setPath($path) |
95
|
|
|
{ |
96
|
75 |
|
$this->path = $path; |
97
|
|
|
|
98
|
75 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Retrieve the entree path. |
103
|
|
|
* |
104
|
|
|
* @return string path |
105
|
|
|
*/ |
106
|
27 |
|
public function getPath() |
107
|
|
|
{ |
108
|
27 |
|
return $this->path; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Plugins pass-through. |
113
|
|
|
* |
114
|
|
|
* @param string $method |
115
|
|
|
* @param array $arguments |
116
|
|
|
* |
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
6 |
|
public function __call($method, array $arguments) |
120
|
|
|
{ |
121
|
6 |
|
array_unshift($arguments, $this->path); |
122
|
6 |
|
$callback = array($this->filesystem, $method); |
123
|
|
|
|
124
|
|
|
try { |
125
|
6 |
|
return call_user_func_array($callback, $arguments); |
126
|
3 |
|
} catch (BadMethodCallException $e) { |
127
|
3 |
|
throw new BadMethodCallException( |
128
|
|
|
'Call to undefined method ' |
129
|
3 |
|
. get_called_class() |
130
|
3 |
|
. '::' . $method |
131
|
3 |
|
); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|