1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-06 13:16:54 +02:00

#431 general structure changes

This commit is contained in:
Awilum
2018-03-05 00:22:55 +03:00
parent a616757ee0
commit 0b94ad6d1e
19 changed files with 390 additions and 833 deletions

View File

@@ -1,4 +1,7 @@
<?php
namespace Monstra;
use Symfony\Component\Yaml\Yaml;
/**
* This file is part of the Monstra.
@@ -8,109 +11,53 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Plugins
{
/**
* An instance of the Plugins class
*
* @var object
* @access protected
* @var Monstra
*/
protected static $instance = null;
protected $monstra;
/**
* Protected clone method to enforce singleton behavior.
*
* @access protected
* __construct
*/
protected function __clone()
public function __construct(Monstra $c)
{
// Nothing here.
}
$this->monstra = $c;
/**
* Constructor.
*
* @access protected
*/
protected function __construct()
{
$plugins_cache_id = '';
$monstra = $this->monstra;
$plugin_manifest = [];
$plugin_settings = [];
// Get Plugins List
$plugins_list = Config::get('site.plugins');
$plugins_list = $this->monstra['config']->get('site.plugins');
// If Plugins List isnt empty then create plugin cache ID
// @TODO THIS with cache then
// If Plugins List isnt empty
if (is_array($plugins_list) && count($plugins_list) > 0) {
// Go through...
foreach ($plugins_list as $plugin) {
if (File::exists($_plugin = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
$plugins_cache_id .= filemtime($_plugin);
}
}
// Create Unique Cache ID for Plugins
$plugins_cache_id = md5('plugins' . ROOT_DIR . PLUGINS_PATH . $plugins_cache_id);
}
// Get plugins list from cache or scan plugins folder and create new plugins cache item
if (Cache::driver()->contains($plugins_cache_id)) {
Config::set('plugins', Cache::driver()->fetch($plugins_cache_id));
} else {
// If Plugins List isnt empty
if (is_array($plugins_list) && count($plugins_list) > 0) {
// Go through...
foreach ($plugins_list as $plugin) {
if (File::exists($_plugin_manifest = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
$plugin_manifest = Yaml::parseFile($_plugin_manifest);
}
if (File::exists($_plugin_settings = PLUGINS_PATH . '/' . $plugin . '/settings.yml')) {
$plugin_settings = Yaml::parseFile($_plugin_settings);
}
$_plugins_config[File::name($_plugin_manifest)] = array_merge($plugin_manifest, $plugin_settings);
if (file_exists($_plugin_manifest = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
$plugin_manifest = Yaml::parse(file_get_contents($_plugin_manifest));
}
Config::set('plugins', $_plugins_config);
Cache::driver()->save($plugins_cache_id, $_plugins_config);
$_plugins_config[basename($_plugin_manifest)] = array_merge($plugin_manifest, $plugin_settings);
}
}
// Include enabled plugins
if (is_array(Config::get('plugins')) && count(Config::get('plugins')) > 0) {
foreach (Config::get('plugins') as $plugin_name => $plugin) {
if (Config::get('plugins.'.$plugin_name.'.enabled')) {
include_once PLUGINS_PATH .'/'. $plugin_name .'/'. $plugin_name . '.php';
}
if (is_array($this->monstra['config']->get('site.plugins')) && count($this->monstra['config']->get('site.plugins')) > 0) {
foreach ($this->monstra['config']->get('site.plugins') as $plugin_id => $plugin_name) {
//echo '@@@'.$plugins;
//if ($this->monstra['config']->get('plugins.'.$plugin_name.'.enabled')) {
//echo $plugin_name;
include_once PLUGINS_PATH .'/'. $plugin_name .'/'. $plugin_name . '.php';
}
}
// Run Actions on plugins_loaded
Action::run('plugins_loaded');
}
/**
* Initialize Monstra Plugins
*
* <code>
* Plugins::init();
* </code>
*
* @access public
*/
public static function init()
{
if (! isset(self::$instance)) {
self::$instance = new Plugins();
}
return self::$instance;
public function init() {
}
}