update PluginController to use PHPCI plugin directory as well as composer to get information about installed plugins.

This commit is contained in:
meadsteve 2014-02-25 22:22:32 +00:00
parent 28fc30682b
commit aa33a8761e
3 changed files with 60 additions and 4 deletions

View file

@ -12,6 +12,8 @@ namespace PHPCI\Controller;
use b8;
use PHPCI\Model\Build;
use PHPCI\Plugin\Util\ComposerPluginInformation;
use PHPCI\Plugin\Util\FilesPluginInformation;
use PHPCI\Plugin\Util\PluginInformationCollection;
/**
* Plugin Controller - Provides support for installing Composer packages.
@ -63,9 +65,14 @@ class PluginController extends \PHPCI\Controller
$this->view->installedPackages = $json['require'];
$this->view->suggestedPackages = $json['suggest'];
$pluginInfo = ComposerPluginInformation::buildFromYaml(
$pluginInfo = new PluginInformationCollection();
$pluginInfo->add(FilesPluginInformation::newFromDir(
PHPCI_DIR . "PHPCI/Plugin/"
));
$pluginInfo->add(ComposerPluginInformation::buildFromYaml(
PHPCI_DIR . "vendor/composer/installed.json"
);
));
$this->view->plugins = $pluginInfo->getInstalledPlugins();
return $this->view->render();

View file

@ -79,7 +79,8 @@ class FilesPluginInformation implements InstalledPluginInformation
$newPlugin = new \stdClass();
$newPlugin->class = $this->getFullClassFromFile($fileInfo);
$newPlugin->source = "core";
$newPlugin->name = end(explode('\\', $newPlugin->class));
$parts = explode('\\', $newPlugin->class);
$newPlugin->name = end($parts);
$this->pluginInfo[] = $newPlugin;
}
@ -87,7 +88,7 @@ class FilesPluginInformation implements InstalledPluginInformation
protected function getFullClassFromFile(\SplFileInfo $fileInfo)
{
//TODO: Something less horrible than a regular expression
// on the conents of a file
// on the contents of a file
$contents = file_get_contents($fileInfo->getRealPath());
$matches = array();

View file

@ -0,0 +1,48 @@
<?php
namespace PHPCI\Plugin\Util;
class PluginInformationCollection implements InstalledPluginInformation
{
/**
* @var InstalledPluginInformation[]
*/
protected $pluginInformations = array();
public function add(InstalledPluginInformation $information)
{
$this->pluginInformations[] = $information;
}
/**
* Returns an array of objects. Each one represents an available plugin
* and will have the following properties:
* name - The friendly name of the plugin (may be an empty string)
* class - The class of the plugin (will include namespace)
* @return \stdClass[]
*/
public function getInstalledPlugins()
{
$arr = array();
foreach($this->pluginInformations as $single) {
$arr = array_merge($arr, $single->getInstalledPlugins());
}
return $arr;
}
/**
* Returns an array of all the class names of plugins that have been
* loaded.
*
* @return string[]
*/
public function getPluginClasses()
{
$arr = array();
foreach($this->pluginInformations as $single) {
$arr = array_merge($arr, $single->getPluginClasses());
}
return $arr;
}
}