|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2013-2015 2amigOS! Consulting Group LLC |
|
4
|
|
|
* @link http://2amigos.us |
|
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace dosamigos\leaflet; |
|
8
|
|
|
|
|
9
|
|
|
use yii\base\Component; |
|
10
|
|
|
use yii\helpers\ArrayHelper; |
|
11
|
|
|
|
|
12
|
|
|
class PluginManager extends Component |
|
13
|
|
|
{ |
|
14
|
|
|
private $_plugins = []; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Check whether we have a plugin installed with that name previous firing up the call |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $name |
|
20
|
|
|
* |
|
21
|
|
|
* @return mixed|void |
|
22
|
|
|
*/ |
|
23
|
3 |
|
public function __get($name) |
|
24
|
|
|
{ |
|
25
|
3 |
|
if (ArrayHelper::keyExists($name, $this->getInstalledPlugins())) { |
|
26
|
3 |
|
return $this->getPlugin($name); |
|
27
|
|
|
} |
|
28
|
3 |
|
return parent::__get($name); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Installs a plugin |
|
33
|
|
|
* |
|
34
|
|
|
* @param Plugin $plugin |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
18 |
|
public function install(Plugin $plugin) |
|
39
|
|
|
{ |
|
40
|
18 |
|
$this->_plugins[$plugin->name] = $plugin; |
|
41
|
18 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Removes a plugin |
|
45
|
|
|
* |
|
46
|
|
|
* @param Plugin $plugin |
|
47
|
|
|
* |
|
48
|
|
|
* @return mixed|null the value of the element if found, default value otherwise |
|
49
|
|
|
*/ |
|
50
|
3 |
|
public function remove(Plugin $plugin) |
|
51
|
|
|
{ |
|
52
|
3 |
|
return ArrayHelper::remove($this->_plugins, $plugin->name); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param \yii\web\View $view |
|
57
|
|
|
* Registers plugin bundles |
|
58
|
|
|
*/ |
|
59
|
15 |
|
public function registerAssetBundles($view) |
|
60
|
|
|
{ |
|
61
|
15 |
|
foreach ($this->_plugins as $plugin) { |
|
62
|
12 |
|
$plugin->registerAssetBundle($view); |
|
63
|
15 |
|
} |
|
64
|
15 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return array of installed plugins |
|
68
|
|
|
*/ |
|
69
|
21 |
|
public function getInstalledPlugins() |
|
70
|
|
|
{ |
|
71
|
21 |
|
return $this->_plugins; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Returns an installed plugin by name |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $name |
|
78
|
|
|
* |
|
79
|
|
|
* @return Plugin|null |
|
80
|
|
|
*/ |
|
81
|
3 |
|
public function getPlugin($name) |
|
82
|
|
|
{ |
|
83
|
3 |
|
return isset($this->_plugins[$name]) ? $this->_plugins[$name] : null; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|