Filesystem::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * @link https://github.com/acidwave/yii2-flysystem
4
 * @copyright Copyright (c) 2021 Acid Wave
5
 * @license http://opensource.org/licenses/BSD-3-Clause
6
 */
7
8
namespace Acidwave\Flysystem;
9
10
use League\Flysystem\FilesystemAdapter;
11
use League\Flysystem\Filesystem as NativeFilesystem;
12
use Yii;
13
use yii\base\Component;
14
15
/**
16
 * Filesystem
17
 *
18
 * @method \League\Flysystem\FilesystemInterface addPlugin(\League\Flysystem\PluginInterface $plugin)
19
 * @method void assertAbsent(string $path)
20
 * @method void assertPresent(string $path)
21
 * @method void copy(string $path, string $newpath, array $config = null)
22
 * @method void createDirectory(string $dirname, array $config = null)
23
 * @method boolean delete(string $path)
24
 * @method boolean deleteDirectory(string $dirname)
25
 * @method \League\Flysystem\Handler get(string $path, \League\Flysystem\Handler $handler = null)
26
 * @method \League\Flysystem\FilesystemAdapter getAdapter()
27
 * @method \League\Flysystem\Config getConfig()
28
 * @method string mimeType(string $path)
29
 * @method integer fileSize(string $path)
30
 * @method integer lastModified(string $path)
31
 * @method string visibility(string $path)
32
 * @method array getWithMetadata(string $path, array $metadata)
33
 * @method boolean fileExists(string $path)
34
 * @method \League\Flysystem\DirectoryListing listContents(string $directory = '', boolean $recursive = false)
35
 * @method array listFiles(string $path = '', boolean $recursive = false)
36
 * @method array listPaths(string $path = '', boolean $recursive = false)
37
 * @method array listWith(array $keys = [], $directory = '', $recursive = false)
38
 * @method string read(string $path)
39
 * @method resource readStream(string $path)
40
 * @method void move(string $path, string $newpath, array $config = null)
41
 * @method void setVisibility(string $path, string $visibility)
42
 * @method boolean write(string $path, string $contents, array $config = [])
43
 * @method boolean writeStream(string $path, resource $resource, array $config = [])
44
 *
45
 * @author Acid Wave <[email protected]>
46
 */
47
abstract class Filesystem extends Component
48
{
49
    /**
50
     * @var \League\Flysystem\Config|array|string|null
51
     */
52
    public $config;
53
    /**
54
     * @var \League\Flysystem\Filesystem
55
     */
56
    protected $filesystem;
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function init()
62
    {
63
        $adapter = $this->prepareAdapter();
64
        $this->filesystem = new NativeFilesystem($adapter, $this->config);
65
    }
66
67
    /**
68
     * @return FilesystemAdapter
69
     */
70
    abstract protected function prepareAdapter();
71
72
    /**
73
     * @param string $method
74
     * @param array $parameters
75
     * @return mixed
76
     */
77
    public function __call($method, $parameters)
78
    {
79
        return call_user_func_array([$this->filesystem, $method], $parameters);
80
    }
81
82
    /**
83
     * @return \League\Flysystem\Filesystem
84
     */
85
    public function getFilesystem()
86
    {
87
        return $this->filesystem;
88
    }
89
}
90