Skip to content

Commit

Permalink
Improved plugin scanning.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jan 12, 2015
1 parent 555ae71 commit f32ab7c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 70 deletions.
8 changes: 5 additions & 3 deletions application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
'categories' => 'vardump', // show in firebug/console
'showInFireBug' => true,
'enabled' => defined('YII_DEBUG') && YII_DEBUG
)
),
'profile' => [
'class' => CProfileLogRoute::class
]
)
),
'cache'=>array(
Expand All @@ -99,8 +102,7 @@
),
'pluginManager' => [
'class' => "\\ls\\pluginmanager\\PluginManager",
'api' => "\\ls\\pluginmanager\\LimesurveyApi",
'plugins' => require_once(__DIR__ . '/plugins.php')
'api' => "\\ls\\pluginmanager\\LimesurveyApi"
]
),

Expand Down
21 changes: 0 additions & 21 deletions application/config/plugins.php

This file was deleted.

7 changes: 0 additions & 7 deletions application/core/WebApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ public function __construct($config = null)
$this->loader = new Psr4AutoloaderClass();
$this->loader->register();
$this->loader->addNamespace('ls\\pluginmanager', __DIR__ . '/../libraries/PluginManager');
foreach($config['modules'] as $module) {
if (isset($module['namespace'], $module['dir'])) {
$this->loader->addNamespace($module['namespace'], $module['dir']);
}
class_exists($module['class']);
}

parent::__construct($config);
Yii::setPathOfAlias('bootstrap' , Yii::getPathOfAlias('ext.bootstrap'));
// Load the default and environmental settings from different files into self.
Expand Down
57 changes: 27 additions & 30 deletions application/libraries/PluginManager/PluginManager.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
namespace ls\pluginmanager;
use Yii;
use \Yii;
use Plugin;
/**
* Factory for limesurvey plugin objects.
Expand Down Expand Up @@ -179,34 +179,31 @@ public function dispatchEvent(PluginEvent $event, $target = array())
* This function is not efficient so should only be used in the admin interface
* that specifically deals with enabling / disabling plugins.
*/
public function scanPlugins()
public function scanPlugins($forceReload = false)
{
$result = array();
$modules = [];
foreach ($this->pluginDirs as $pluginDir) {
$currentDir = Yii::getPathOfAlias($pluginDir);
if (is_dir($currentDir)) {
Yii::beginProfile('scanPlugins');
$cacheKey = 'scanPlugins';
if (false === $plugins = \Yii::app()->cache->get($cacheKey)) {
$plugins = [];
foreach ($this->pluginDirs as $pluginDir) {
$currentDir = Yii::getPathOfAlias($pluginDir);
foreach(\CFileHelper::findFiles($currentDir, [
'fileTypes' => ['php']
'fileTypes' => ['json']
]) as $file) {
$pluginName = basename($file, '.php');
$relativeName = strtr($file, [$currentDir => '']);

// Old style plugin.
if (file_exists($currentDir . "/$pluginName/$pluginName.php")) {
$result[$pluginName] = $this->getPluginInfo($pluginName, $pluginDir);
} elseif ($pluginName == 'config') {
$config = require($file);
if (basename($file) == 'config.json') {
$config = json_decode(file_get_contents($file), true);
$config['dir'] = dirname($file);
$config['class'] = $config['namespace'] . '\\' . $config['name'];
$modules[$config['name']] = $config;
$plugins[$config['name']] = $config;

}

}
}
\Yii::app()->cache->set($cacheKey, $plugins, 3600);
}
$this->createAutoloader($modules);
return $result;
Yii::endProfile('scanPlugins');
return $plugins;

}

/**
Expand Down Expand Up @@ -377,15 +374,15 @@ private function createAutoloader($modules) {

public function setPlugins($plugins)
{
$defaults = [];
$app = \Yii::app();
foreach($plugins as $name => $plugin) {
$config = \CMap::mergeArray($defaults, $plugin);
if($config['type'] == 'module') {
$app->setModules([$name => $config]);
}
}
// $defaults = [];
// $app = \Yii::app();
// foreach($plugins as $name => $plugin) {
// $config = \CMap::mergeArray($defaults, $plugin);
// if($config['type'] == 'module') {
//
// $app->setModules([$name => $config]);
// }
// }
}

}
Expand Down
6 changes: 6 additions & 0 deletions plugins/befound/ls/ModulePlugin/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name" : "ModulePlugin",
"namespace" : "\\befound\\ls\\ModulePlugin",
"description" : "Example plugin that uses a Yii module.",
"type" : "module"
}
9 changes: 0 additions & 9 deletions plugins/befound/ls/ModulePlugin/config.php

This file was deleted.

0 comments on commit f32ab7c

Please sign in to comment.