1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BEdita, API-first content management framework |
4
|
|
|
* Copyright 2017 ChannelWeb Srl, Chialab Srl |
5
|
|
|
* |
6
|
|
|
* This file is part of BEdita: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Lesser General Public License as published |
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace BEdita\Core\Filesystem; |
15
|
|
|
|
16
|
|
|
use Cake\Core\InstanceConfigTrait; |
17
|
|
|
use League\Flysystem\AdapterInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Filesystem adapter. |
21
|
|
|
* |
22
|
|
|
* This abstract class is a wrapper around Flysystem adapters, to ensure they can be instantiated |
23
|
|
|
* in a consistent way by delegating adapter's specific initialization logic to subclasses. |
24
|
|
|
* |
25
|
|
|
* Also, subclasses of this class are responsible for building public URLs from which files can |
26
|
|
|
* be accessed, although a generic implementation is present in this abstract class. |
27
|
|
|
* |
28
|
|
|
* @since 4.0.0 |
29
|
|
|
*/ |
30
|
|
|
abstract class FilesystemAdapter |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
use InstanceConfigTrait; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Default configuration for adapter. |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $_defaultConfig = [ |
41
|
|
|
'baseUrl' => null, |
42
|
|
|
'visibility' => 'public', |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Inner adapter instance. |
47
|
|
|
* |
48
|
|
|
* @var \League\Flysystem\AdapterInterface |
49
|
|
|
*/ |
50
|
|
|
protected $adapter; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Initialize filesystem adapter class. |
54
|
|
|
* |
55
|
|
|
* @param array $config Configuration. |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
public function initialize(array $config) |
59
|
|
|
{ |
60
|
|
|
$this->setConfig($config); |
61
|
|
|
|
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the inner adapter class. |
67
|
|
|
* |
68
|
|
|
* @return \League\Flysystem\AdapterInterface |
69
|
|
|
*/ |
70
|
|
|
public function getInnerAdapter() |
71
|
|
|
{ |
72
|
|
|
if (!empty($this->adapter)) { |
73
|
|
|
return $this->adapter; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$adapter = $this->buildAdapter($this->getConfig()); |
77
|
|
|
if (!($adapter instanceof AdapterInterface)) { |
|
|
|
|
78
|
|
|
throw new \RuntimeException( |
79
|
|
|
sprintf('Filesystem adapters must use %s as a base class.', AdapterInterface::class) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $this->adapter = $adapter; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Build the inner adapter from configuration. |
88
|
|
|
* |
89
|
|
|
* @param array $config Adapter configuration. |
90
|
|
|
* @return \League\Flysystem\AdapterInterface |
91
|
|
|
*/ |
92
|
|
|
abstract protected function buildAdapter(array $config); |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get public URL for an item. |
96
|
|
|
* |
97
|
|
|
* @param string $path Resource path. |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getPublicUrl($path) |
101
|
|
|
{ |
102
|
|
|
return sprintf( |
103
|
|
|
'%s/%s', |
104
|
|
|
rtrim($this->getConfig('baseUrl'), '/'), |
105
|
|
|
ltrim($path, '/') |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get default visibility for this adapter. |
111
|
|
|
* |
112
|
|
|
* @return string|null |
113
|
|
|
*/ |
114
|
|
|
public function getVisibility() |
115
|
|
|
{ |
116
|
|
|
return $this->getConfig('visibility'); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.