forked from 2amigos/yii2-google-maps-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPluginManager.php
103 lines (93 loc) · 2.17 KB
/
PluginManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/*
*
* @copyright Copyright (c) 2013-2019 2amigos
* @link http://2amigos.us
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*
*/
namespace dosamigos\google\maps;
use yii\base\BaseObject;
use yii\helpers\ArrayHelper;
/**
* PluginManager
*
* Manages installed plugins.
*
* @author Antonio Ramirez <[email protected]>
*
* @link http://www.2amigos.us/
* @package dosamigos\google\maps
*/
class PluginManager extends BaseObject
{
/**
* @var array stores the managed plugins
*/
private $_plugins = [];
/**
* Check whether we have a plugin installed with that name previous firing up the call
*
* @param string $name
*
* @return mixed|void
*/
public function __get($name)
{
if (ArrayHelper::keyExists($name, $this->getInstalledPlugins())) {
return $this->getPlugin($name);
}
return parent::__get($name);
}
/**
* Installs a plugin
*
* @param PluginAbstract $plugin
*
* @return void
*/
public function install(PluginAbstract $plugin)
{
$this->_plugins[$plugin->getPluginName()] = $plugin;
}
/**
* Removes a plugin
*
* @param PluginAbstract $plugin
*
* @return mixed|null the value of the element if found, default value otherwise
*/
public function remove(PluginAbstract $plugin)
{
return ArrayHelper::remove($this->_plugins, $plugin->getPluginName());
}
/**
* @param \yii\web\View $view
* Registers plugin bundles
*/
public function registerAssetBundles($view)
{
foreach ($this->_plugins as $plugin) {
/** @var PluginAbstract $plugin */
$plugin->registerAssetBundle($view);
}
}
/**
* @return array of installed plugins
*/
public function getInstalledPlugins()
{
return $this->_plugins;
}
/**
* Returns an installed plugin by name
*
* @param string $name
*
* @return PluginAbstract|null
*/
public function getPlugin($name)
{
return isset($this->_plugins[$name]) ? $this->_plugins[$name] : null;
}
}