1 | <?php |
||
15 | class Local implements StorageInterface |
||
16 | { |
||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | 5 | public function put($sourcePath, $destPath) |
|
21 | { |
||
22 | 5 | if (!is_file($sourcePath)) { |
|
23 | 1 | throw new LocalStorageException( |
|
24 | 1 | sprintf('File %s not found', $sourcePath), |
|
25 | LocalStorageException::FILE_NOT_FOUND |
||
26 | 1 | ); |
|
27 | } |
||
28 | |||
29 | 4 | $this->ensureDirectory(dirname($destPath)); |
|
30 | |||
31 | 3 | $result = @copy($sourcePath, $destPath); |
|
32 | 3 | if (!$result) { |
|
33 | 1 | throw new LocalStorageException( |
|
34 | 1 | sprintf('Copy failed: %s', $sourcePath), |
|
35 | LocalStorageException::OPERATION_FAIL |
||
36 | 1 | ); |
|
37 | } |
||
38 | 2 | } |
|
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | 4 | public function delete($path) |
|
44 | { |
||
45 | 4 | if (!is_file($path)) { |
|
46 | 1 | throw new LocalStorageException( |
|
47 | 1 | sprintf('File %s not found', $path), |
|
48 | LocalStorageException::FILE_NOT_FOUND |
||
49 | 1 | ); |
|
50 | } |
||
51 | |||
52 | 3 | $result = unlink($path); |
|
53 | 3 | if (!$result) { |
|
54 | 1 | throw new LocalStorageException( |
|
55 | 1 | sprintf('Delete failed: %s', $path), |
|
56 | LocalStorageException::OPERATION_FAIL |
||
57 | 1 | ); |
|
58 | } |
||
59 | 2 | } |
|
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | 3 | public function listContents($directory = '') |
|
97 | |||
98 | /** |
||
99 | * Ensure the directory exists. |
||
100 | * |
||
101 | * @param string $dir Directory path |
||
102 | * |
||
103 | * @return string Real path to dir |
||
104 | */ |
||
105 | 4 | protected function ensureDirectory($dir) |
|
119 | } |
||
120 |