| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\common\modules\shop;
- class PluginsConfig
- {
- /**
- * @var self
- */
- static $current;
- protected $items;
- /**
- * constructor.
- */
- public function __construct()
- {
- self::$current = $this;
- }
- static public function current()
- {
- if (!isset(self::$current)) {
- return new static();
- }
- return self::$current;
- }
- protected function _getItems()
- {
- $result = [];
- $plugins = app('plugins')->getEnabledPlugins('*');
- foreach ($plugins as $plugin) {
- foreach ($plugin->app()->getPluginConfigItems() as $key => $item) {
- array_set($result, $key, $item);
- }
- }
- return $result;
- }
- protected function getItems()
- {
- if (!isset($this->items)) {
- $this->items = $this->_getItems();
- }
- return $this->items;
- }
- public function getItem($key)
- {
- return array_get($this->getItems(), $key);
- }
- public function clear()
- {
- $this->items = null;
- }
- public function get($key = null)
- {
- if (empty($key)) {
- return $this->getItems();
- }
- return $this->getItem($key);
- }
- public function set($key, $value = null)
- {
- $items = $this->getItems();
- if (is_array($key)) {
- foreach ($key as $k => $v) {
- array_set($items, $k, $v);
- }
- } else {
- array_set($items, $key, $value);
- }
- $this->items = $items;
- }
- public function push($key, $value)
- {
- $all = $this->getItems();
- $array = $this->getItem($key) ?: [];
- $array[] = $value;
- array_set($all, $key, $array);
- $this->items = $all;
- }
- }
|