1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\components; |
4
|
|
|
|
5
|
|
|
use hiqdev\hiart\Connection; |
|
|
|
|
6
|
|
|
use yii\base\Component; |
7
|
|
|
use yii\di\Instance; |
8
|
|
|
|
9
|
|
|
class SettingsStorage extends Component implements SettingsStorageInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var Connection |
13
|
|
|
*/ |
14
|
|
|
private $connection; |
15
|
|
|
|
16
|
|
|
public function init() |
17
|
|
|
{ |
18
|
|
|
$this->connection = Instance::ensure('hiart', Connection::class); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @inheritdoc |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function setGlobal($key, $value) |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$this->perform('clientSetSettingsStorage', array_merge([ |
27
|
|
|
'key' => $key, |
28
|
|
|
'data' => json_encode($value), |
29
|
|
|
'oauthClientBound' => false |
30
|
|
|
])); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function setBounded($key, $value) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$this->perform('clientSetSettingsStorage', array_merge([ |
39
|
|
|
'key' => $key, |
40
|
|
|
'data' => json_encode($value), |
41
|
|
|
'oauthClientBound' => true |
42
|
|
|
])); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritdoc |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function getGlobal($key) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$response = $this->perform('clientGetSettingsStorage', array_merge([ |
51
|
|
|
'key' => $key, |
52
|
|
|
'oauthClientBound' => false |
53
|
|
|
])); |
54
|
|
|
|
55
|
|
|
return json_decode($response['data'], true); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function getBounded($key) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$response = $this->perform('clientGetSettingsStorage', array_merge([ |
64
|
|
|
'key' => $key, |
65
|
|
|
'oauthClientBound' => true |
66
|
|
|
])); |
67
|
|
|
|
68
|
|
|
return json_decode($response['data'], true); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Performs request to the API |
73
|
|
|
* |
74
|
|
|
* @param string $key |
75
|
|
|
* @param array $value |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
private function perform($key, $value) |
79
|
|
|
{ |
80
|
|
|
return $this->connection->createCommand()->perform($key, $value); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: