Passed
Push — main ( 2456f4...ce01ad )
by Sugeng
04:03
created

LocalComponent::getPresignedUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace diecoding\flysystem;
4
5
use League\Flysystem\Local\LocalFilesystemAdapter;
6
use Yii;
7
use yii\base\InvalidConfigException;
8
9
/**
10
 * Class LocalComponent
11
 * 
12
 * ```php
13
 * 'components' => [
14
 *     'fs' => [
15
 *         'class' => \diecoding\flysystem\LocalComponent::class,
16
 *         'path' => dirname(dirname(__DIR__)) . '/storage', // or you can use @alias
17
 *         'prefix' => '',
18
 *     ],
19
 * ],
20
 * ```
21
 * 
22
 * @package diecoding\flysystem
23
 * 
24
 * @link      https://sugengsulistiyawan.my.id/
25
 * @author    Sugeng Sulistiyawan <[email protected]>
26
 * @copyright Copyright (c) 2023
27
 */
28
class LocalComponent extends AbstractComponent
29
{
30
    /**
31
     * @var string
32
     */
33
    public $path;
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function init()
39
    {
40
        if (empty($this->path)) {
41
            throw new InvalidConfigException('The "path" property must be set.');
42
        }
43
44
        if (empty($this->secret)) {
0 ignored issues
show
Bug Best Practice introduced by
The property secret does not exist on diecoding\flysystem\LocalComponent. Since you implemented __get, consider adding a @property annotation.
Loading history...
45
            throw new InvalidConfigException('The "secret" property must be set.');
46
        }
47
48
        parent::init();
49
    }
50
51
    /**
52
     * @return LocalFilesystemAdapter
53
     */
54
    protected function initAdapter()
55
    {
56
        $location = $this->normalizePath(Yii::getAlias($this->path) . '/' . $this->prefix);
0 ignored issues
show
Bug introduced by
Are you sure Yii::getAlias($this->path) of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $location = $this->normalizePath(/** @scrutinizer ignore-type */ Yii::getAlias($this->path) . '/' . $this->prefix);
Loading history...
57
58
        return new LocalFilesystemAdapter($location);
59
    }
60
}
61