This repository has been archived by the owner on Aug 17, 2022. It is now read-only.
/
AbstractDriver.php
235 lines (210 loc) · 6.66 KB
/
AbstractDriver.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/**
* Copyright 2009-2010 Zikula Foundation - Zikula Application Framework
*
* This work is contributed to the Zikula Foundation under one or more
* Contributor Agreements and licensed to You under the following license:
*
* @license GNU/LGPLv3 (or at your option, any later version).
* @package FileSystem
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/
namespace Zikula\Component\FileSystem;
use Zikula\Component\FileSystem\Configuration\ConfigurationInterface;
/**
* Driver Abstract.
*/
abstract class AbstractDriver
{
/**
* Configuration object.
*
* @var Configuration
*/
protected $configuration;
/**
* The Driver object (facade).
*
* @var object
*/
protected $driver;
/**
* The error handler.
*
* @var object
*/
protected $errorHandler;
/**
* Construct the driver with the configuration.
*
* @param ConfigurationInterface $configuration The configuration to be used.
*
* @throws \InvalidArgumentException If wrong configuration class received.
*/
public function __construct(ConfigurationInterface $configuration)
{
// validate we get correct configuration class type.
$type = (string)preg_filter('/Zikula\\\Component\\\FileSystem\\\(\w+)$/', '$1', get_class($this));
$validName = "Zikula\\Component\\FileSystem\\Configuration\\{$type}Configuration";
if ($validName != get_class($configuration)) {
throw new \InvalidArgumentException(
sprintf('Invalid configuration class for %1$s. Expected %2$s but got %3$s instead. ::%4$s',
get_class($this), $validName, get_class($configuration), $type));
}
$this->configuration = $configuration;
$facade = "Zikula\\Component\\FileSystem\\Facade\\{$type}Facade";
$this->driver = new $facade();
$this->errorHandler = new Error();
}
/**
* Setter for facade driver.
*
* @param object $driver The facade driver.
*
* @return void
*/
public function setDriver($driver)
{
$this->driver = $driver;
}
/**
* Getter for errorHanler.
*
* @return object ErrorHandler class.
*/
public function getErrorHandler()
{
return $this->errorHandler;
}
/**
* Interface connect function.
*
* For most functions errors will be regesterd on fail, See FileSystem/Error class
* for more details.
*
* @return boolean True on connect, false on failure.
*/
abstract public function connect();
/**
* Interface get function.
*
* @param string $local The pathname to the desired local file.
* @param string $remote The pathname to the remote file to get.
*
* @return boolean True on success false on failure.
*/
abstract public function get($local, $remote);
/**
* Interface fget function.
*
* @param string $remote The path to the remote file.
*
* @return resource|bool The resource on success false on fail.
*/
abstract public function fget($remote);
/**
* Interface put function.
*
* @param string $local The pathname to the local file.
* @param string $remote The pathname to the desired remote file.
*
* @return boolean True on success false on failure.
*/
abstract public function put($local, $remote);
/**
* Interface fput function.
*
* @param stream|resource $stream The resource to put remotely, probably the resource returned from a fget.
* @param string $remote The pathname to the desired remote pathname.
*
* @return boolean|integer Number of bytes written on success, false on failure.
*/
abstract public function fput($stream, $remote);
/**
* Interface file_put_contents function.
*
* @param string $contents The contents to put remotely.
* @param string $remote The pathname to the desired remote pathname.
*
* @return boolean|integer Number of bytes written on success, false on failure.
*/
abstract public function putContents($contents, $remote);
/**
* Interface file_get_contents function.
*
* @param string $remote The pathname to the desired remote file.
*
* @return string|boolean The string containing file contents on success false on fail.
*/
abstract public function getContents($remote);
/**
* Interface chmod function.
*
* @param integer $perm The permission to assign to the file, unix style (example: 777 for full permission).
* @param string $file The pathname to the remote file to chmod.
*
* @return boolean|integer The new permission or false if failed.
*/
abstract public function chmod($perm, $file);
/**
* Interface ls function.
*
* @param string $dir The directory to get the contents of, blank for current directory, start with / for absolute path.
*
* @return array|boolean An array of the contents of $dir or false if fail.
*/
abstract public function ls($dir = '');
/**
* Interface cd function.
*
* @param string $dir The directory on the remote machine to enter, start with '/' for absolute path.
*
* @return boolean True on success false on failure.
*/
abstract public function cd($dir = '');
/**
* Interface cp function.
*
* @param string $sourcepath The path to the original source file.
* @param string $destpath The path to where you want to copy the source file.
*
* @return boolean True on success false on failure.
*/
abstract public function cp($sourcepath, $destpath);
/**
* Interface mf function.
*
* @param string $sourcepath The path to the original source file.
* @param string $destpath The path to where you want to move the source file.
*
* @return boolean True on success false on failure.
*/
abstract public function mv($sourcepath, $destpath);
/**
* Interface rm function.
*
* @param string $sourcepath The path to the remote file to remove.
*
* @return boolean
*/
abstract public function rm($sourcepath);
/**
* Check if a file is writable.
*
* @param string $sourcepath The path to the file to check if is writable.
*
* @return boolean True if is writable False if not.
*/
abstract public function isWritable($remote_file);
/**
* Interface available function.
*
* @return boolean
*/
public static function isAvailable()
{
return true;
}
}