|
1
|
|
|
<?php /** MicroFileSystem */ |
|
2
|
|
|
|
|
3
|
|
|
namespace Micro\File; |
|
4
|
|
|
|
|
5
|
|
|
use Micro\Base\Exception; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Filesystem is a abstraction access for filesystems |
|
9
|
|
|
* |
|
10
|
|
|
* This wrapper is a thin layer to work with files in the difference file repositories, |
|
11
|
|
|
* by the removal common methods in this wrapper, and the implementation of specific storage |
|
12
|
|
|
* in separate classes driver. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Oleg Lunegov <[email protected]> |
|
15
|
|
|
* @link https://github.com/linpax/microphp-framework |
|
16
|
|
|
* @copyright Copyright (c) 2013 Oleg Lunegov |
|
17
|
|
|
* @license https://github.com/linpax/microphp-framework/blob/master/LICENSE |
|
18
|
|
|
* @package Micro |
|
19
|
|
|
* @subpackage File |
|
20
|
|
|
* @version 1.0 |
|
21
|
|
|
* @since 1.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class Filesystem |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var \Micro\File\Drivers\File $driver Current file driver */ |
|
26
|
|
|
protected $driver; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructor make a connection to driver |
|
31
|
|
|
* |
|
32
|
|
|
* @access public |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $params Parameters for driver and 'driver' name |
|
35
|
|
|
* |
|
36
|
|
|
* @result void |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(array $params = []) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->setDriver($params); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Set driver usage driver params |
|
45
|
|
|
* |
|
46
|
|
|
* @access public |
|
47
|
|
|
* |
|
48
|
|
|
* @param array $params Driver params |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
public function setDriver(array $params = []) |
|
53
|
|
|
{ |
|
54
|
|
|
$driverName = !empty($params['driver']) ? $params['driver'] : 'local'; |
|
55
|
|
|
|
|
56
|
|
|
$this->driver = new $driverName($params); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Call driver function with Filesystem object |
|
61
|
|
|
* |
|
62
|
|
|
* @access public |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $methodName Method name to call |
|
65
|
|
|
* @param array $arguments Arguments for method |
|
66
|
|
|
* |
|
67
|
|
|
* @return mixed |
|
68
|
|
|
* @throws \Micro\Base\Exception |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __call($methodName, array $arguments = []) |
|
71
|
|
|
{ |
|
72
|
|
|
if (!method_exists($this->driver, $methodName)) { |
|
73
|
|
|
throw new Exception('Method `'.$methodName.'` not defined in `'.get_class($this->driver).'` driver.'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return call_user_func_array([$this->driver, $methodName], $arguments); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|