|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Quantum PHP Framework |
|
5
|
|
|
* |
|
6
|
|
|
* An open source software development framework for PHP |
|
7
|
|
|
* |
|
8
|
|
|
* @package Quantum |
|
9
|
|
|
* @author Arman Ag. <[email protected]> |
|
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
|
11
|
|
|
* @link http://quantum.softberg.org/ |
|
12
|
|
|
* @since 2.6.0 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Storage; |
|
16
|
|
|
|
|
17
|
|
|
use Quantum\Exceptions\FileSystemException; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class FileSystem |
|
21
|
|
|
* @package Quantum\Libraries\Storage |
|
22
|
|
|
* @method void makeDirectory(string $dirname) |
|
23
|
|
|
* @method void removeDirectory(string $dirname) |
|
24
|
|
|
* @method string get(string $filename) |
|
25
|
|
|
* @method void put(string $filename, string $content) |
|
26
|
|
|
* @method void append(string $filename, string $content) |
|
27
|
|
|
* @method void rename(string $oldName, string $newName) |
|
28
|
|
|
* @method void copy(string $source, string $dest) |
|
29
|
|
|
* @method bool exists(string $filename) |
|
30
|
|
|
* @method int|false size(string $filename) |
|
31
|
|
|
* @method int|false lastModified(string $filename) |
|
32
|
|
|
* @method void remove(string $filename) |
|
33
|
|
|
* @method bool isFile(string $filename) |
|
34
|
|
|
* @method bool isDirectory(string $dirname) |
|
35
|
|
|
*/ |
|
36
|
|
|
class FileSystem |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var \Quantum\Libraries\Storage\FilesystemAdapterInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
private $adapter; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* FileSystem constructor |
|
46
|
|
|
* @param \Quantum\Libraries\Storage\FilesystemAdapterInterface|null $filesystemAdapter |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(FilesystemAdapterInterface $filesystemAdapter = null) |
|
49
|
|
|
{ |
|
50
|
|
|
if ($filesystemAdapter) { |
|
51
|
|
|
$this->adapter = $filesystemAdapter; |
|
52
|
|
|
} else { |
|
53
|
|
|
$this->adapter = LocalFileSystemAdapter::getInstance(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Gets the current adapter |
|
59
|
|
|
* @return \Quantum\Libraries\Storage\FilesystemAdapterInterface |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getAdapter(): FilesystemAdapterInterface |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->adapter; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $method |
|
68
|
|
|
* @param array|null $arguments |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
* @throws \Quantum\Exceptions\FileSystemException |
|
71
|
|
|
*/ |
|
72
|
|
|
public function __call(string $method, ?array $arguments) |
|
73
|
|
|
{ |
|
74
|
|
|
if (!method_exists($this->adapter, $method)) { |
|
75
|
|
|
throw FileSystemException::methodNotSupported($method, get_class($this->adapter)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->adapter->$method(...$arguments); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|