-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLocal.php
More file actions
72 lines (60 loc) · 1.55 KB
/
Local.php
File metadata and controls
72 lines (60 loc) · 1.55 KB
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
<?php
/**
* @author Ioannis Botis
* @date 24/1/2017
* @version: Local.php 11:47 pm
* @since 24/1/2017
*/
namespace Backup\Destination;
use Backup\Destination\AbstractBase;
use Backup\FileSystem\Folder;
use League\Flysystem\Adapter\Local as FlyLocal;
use League\Flysystem\Filesystem;
class Local extends AbstractBase
{
protected $folder;
private $adapter;
private $filesystem;
public function __construct(array $settings)
{
parent::__construct($settings);
$this->adapter = new FlyLocal($settings['path']);
$this->filesystem = new Filesystem($this->adapter);
$this->folder = new Folder($settings['path']);
}
public function getType()
{
return self::LOCAL_FOLDER_TYPE;
}
public function getPath()
{
return $this->folder->getPath();
}
public function isEmpty()
{
return $this->folder->isEmpty();
}
public function canAccess()
{
return $this->folder->isReadable();
}
public function read($file)
{
try {
return $this->filesystem->read($file);
} catch (\League\Flysystem\FileNotFoundException $e) {
return false;
}
}
public function listContents($dir = '', $recursive = false)
{
return $this->filesystem->listContents($dir, $recursive);
}
public function write($filename, $contents)
{
if ($contents === null) {
return $this->filesystem->createDir($filename);
}
return $this->filesystem->put($filename, $contents);
}
}