• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

projek-xyz / slim-flysystem / 11467873268

22 Oct 2024 08:18PM UTC coverage: 16.667% (+10.2%) from 6.452%
11467873268

push

github

feryardiant
chore: update dependencies

Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>

4 of 24 relevant lines covered (16.67%)

2.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.05
/src/Flysystem.php
1
<?php
2
namespace Projek\Slim;
3

4
use League\Flysystem\Filesystem;
5
use League\Flysystem\MountManager;
6
use League\Flysystem\Adapter;
7
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
8
use LogicException;
9

10
/**
11
 * @mixin \League\Flysystem\FilesystemInterface
12
 */
13
class Flysystem
14
{
15
    /**
16
     * @var array<string, array>
17
     */
18
    protected $settings = [
19
        'local' => [
20
            'path' => null,
21
        ],
22
    ];
23

24
    /**
25
     * @var null|\League\Flysystem\Filesystem
26
     */
27
    protected $fs = null;
28

29
    /**
30
     * @var \League\Flysystem\MountManager
31
     */
32
    protected $mounts;
33

34
    /**
35
     * Create new Projek\Slim\Flysystem instance
36
     *
37
     * @param string[] $settings
38
     */
39
    public function __construct(array $settings)
40
    {
41
        $this->settings = array_merge($this->settings, $settings);
14✔
42

43
        $mounts = [];
14✔
44

45
        if (!is_null($this->settings['local']['path'])) {
46
            $mounts['local'] = new Filesystem(new Adapter\Local($this->settings['local']['path']));
14✔
47
        }
48

49
        $this->mounts = new MountManager($mounts);
14✔
50
    }
51

52
    /**
53
     * Magic method to connect to filesystem for convenience
54
     *
55
     * @param  string $prefix Filesystem name
56
     * @return $this
57
     */
58
    public function __get($prefix)
59
    {
60
        $this->fs = $this->mounts->getFilesystem($prefix);
×
61

62
        return $this;
×
63
    }
64

65
    public function __call($method, $args)
66
    {
67
        /**
68
         * @var \League\Flysystem\FilesystemInterface
69
         */
70
        $filesystem = $this->fs ?: $this->mounts;
×
71

72
        return call_user_func_array([$filesystem, $method], $args);
×
73
    }
74

75
    /**
76
     * Get the Flysystem instance with Local adapter
77
     *
78
     * @return \League\Flysystem\Filesystem
79
     */
80
    public function getFlysystem()
81
    {
82
        return $this->mounts->getFilesystem('local');
×
83
    }
84

85
    /**
86
     * Mound local adapter with given $path
87
     *
88
     * @param  string $path
89
     * @return $this
90
     */
91
    public function mountLocal($path)
92
    {
93
        if (isset($this->settings[$path]['path'])) {
94
            $this->fs = $this->mounts->getFilesystem($path);
×
95

96
            return $this;
×
97
        }
98

99
        $this->fs = new Filesystem(new Adapter\Local($path));
×
100

101
        return $this;
×
102
    }
103

104
    /**
105
     * Mount FTP
106
     *
107
     * @param  string   $host
108
     * @param  string   $username
109
     * @param  string   $password
110
     * @param  string[] $opt
111
     * @return $this
112
     */
113
    public function mountFtp($host, $username = '', $password = '', array $opt = [])
114
    {
115
        if (isset($this->settings[$host]['host'])) {
116
            $this->fs = $this->mounts->getFilesystem($host);
×
117

118
            return $this;
×
119
        }
120

121
        $opts = array_merge($opt, [
122
            'host' => $host,
123
            'username' => $username,
124
            'password' => $password,
125
        ]);
×
126

127
        $this->fs = new Filesystem(new Adapter\Ftp($opts));
×
128

129
        return $this;
×
130
    }
131

132
    /**
133
     * Mount Archive
134
     *
135
     * @param  string $path
136
     * @throws \LogicException
137
     * @return $this
138
     */
139
    public function mountArchive($path)
140
    {
141
        if (!class_exists(ZipArchiveAdapter::class)) {
142
            throw new LogicException('No adapter found to mount Zip Archive.');
×
143
        }
144

145
        $this->fs = new Filesystem(new ZipArchiveAdapter($path));
×
146

147
        return $this;
×
148
    }
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc