Removed plugin page
This commit is contained in:
parent
8c355bba8c
commit
5ffcc5a832
8 changed files with 0 additions and 536 deletions
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Controller;
|
||||
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Plugin\Util\ComposerPluginInformation;
|
||||
use PHPCensor\Plugin\Util\FilesPluginInformation;
|
||||
use PHPCensor\Plugin\Util\PluginInformationCollection;
|
||||
use PHPCensor\Controller;
|
||||
|
||||
/**
|
||||
* Plugin Controller - Provides support for installing Composer packages.
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class PluginController extends Controller
|
||||
{
|
||||
/**
|
||||
* List all enabled plugins, installed and recommend packages.
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->requireAdmin();
|
||||
|
||||
$json = $this->getComposerJson();
|
||||
$this->view->installedPackages = $json['require'];
|
||||
|
||||
$pluginInfo = new PluginInformationCollection();
|
||||
$pluginInfo->add(FilesPluginInformation::newFromDir(SRC_DIR . "Plugin" . DIRECTORY_SEPARATOR));
|
||||
$pluginInfo->add(ComposerPluginInformation::buildFromYaml(
|
||||
ROOT_DIR . "vendor" . DIRECTORY_SEPARATOR . "composer" . DIRECTORY_SEPARATOR . "installed.json"
|
||||
));
|
||||
|
||||
$this->view->plugins = $pluginInfo->getInstalledPlugins();
|
||||
|
||||
$this->layout->title = Lang::get('plugins');
|
||||
|
||||
return $this->view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the json-decoded contents of the composer.json file.
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getComposerJson()
|
||||
{
|
||||
$json = file_get_contents(ROOT_DIR . 'composer.json');
|
||||
return json_decode($json, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Plugin\Util;
|
||||
|
||||
use PHPCensor\Plugin;
|
||||
|
||||
/**
|
||||
* Class ComposerPluginInformation
|
||||
* @package PHPCensor\Plugin\Util
|
||||
*/
|
||||
class ComposerPluginInformation implements InstalledPluginInformation
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $composerPackages;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $pluginInfo = null;
|
||||
|
||||
/**
|
||||
* @param string $filePath The path of installed.json created by composer.
|
||||
* @return ComposerPluginInformation
|
||||
*/
|
||||
public static function buildFromYaml($filePath)
|
||||
{
|
||||
if (file_exists($filePath)) {
|
||||
$installed = json_decode(file_get_contents($filePath));
|
||||
} else {
|
||||
$installed = [];
|
||||
}
|
||||
return new self($installed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass[] $composerPackages This should be the contents of the
|
||||
* installed.json file created by composer
|
||||
*/
|
||||
public function __construct(array $composerPackages)
|
||||
{
|
||||
$this->composerPackages = $composerPackages;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$this->loadPluginInfo();
|
||||
return $this->pluginInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the class names of plugins that have been
|
||||
* loaded.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPluginClasses()
|
||||
{
|
||||
return array_map(
|
||||
function (Plugin $plugin) {
|
||||
return $plugin->class;
|
||||
},
|
||||
$this->getInstalledPlugins()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a list of available plugins from the installed composer packages.
|
||||
*/
|
||||
protected function loadPluginInfo()
|
||||
{
|
||||
if ($this->pluginInfo !== null) {
|
||||
return;
|
||||
}
|
||||
$this->pluginInfo = [];
|
||||
foreach ($this->composerPackages as $package) {
|
||||
$this->addPluginsFromPackage($package);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass $package
|
||||
*/
|
||||
protected function addPluginsFromPackage($package)
|
||||
{
|
||||
if (isset($package->extra->phpci)) {
|
||||
$phpciData = $package->extra->phpci;
|
||||
|
||||
if (isset($phpciData->pluginNamespace)) {
|
||||
$rootNamespace = $phpciData->pluginNamespace;
|
||||
} else {
|
||||
$rootNamespace = "";
|
||||
}
|
||||
|
||||
if (is_array($phpciData->suppliedPlugins)) {
|
||||
$this->addPlugins(
|
||||
$phpciData->suppliedPlugins,
|
||||
$package->name,
|
||||
$rootNamespace
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass[] $plugins
|
||||
* @param string $sourcePackageName
|
||||
* @param string $rootNamespace
|
||||
*/
|
||||
protected function addPlugins(
|
||||
array $plugins,
|
||||
$sourcePackageName,
|
||||
$rootNamespace = ""
|
||||
) {
|
||||
foreach ($plugins as $plugin) {
|
||||
if (!isset($plugin->class)) {
|
||||
continue;
|
||||
}
|
||||
$this->addPlugin($plugin, $sourcePackageName, $rootNamespace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass $plugin
|
||||
* @param string $sourcePackageName
|
||||
* @param string $rootNamespace
|
||||
*/
|
||||
protected function addPlugin(
|
||||
$plugin,
|
||||
$sourcePackageName,
|
||||
$rootNamespace = ""
|
||||
) {
|
||||
$newPlugin = clone $plugin;
|
||||
|
||||
$newPlugin->class = $rootNamespace . $newPlugin->class;
|
||||
|
||||
if (!isset($newPlugin->name)) {
|
||||
$newPlugin->name = "";
|
||||
}
|
||||
|
||||
$newPlugin->source = $sourcePackageName;
|
||||
|
||||
$this->pluginInfo[] = $newPlugin;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Plugin\Util;
|
||||
|
||||
use PHPCensor\Plugin;
|
||||
|
||||
/**
|
||||
* Class FilesPluginInformation
|
||||
* @package PHPCensor\Plugin\Util
|
||||
*/
|
||||
class FilesPluginInformation implements InstalledPluginInformation
|
||||
{
|
||||
|
||||
/**
|
||||
* A collection of all the file path information for
|
||||
* the installed plugins.
|
||||
*
|
||||
* @var \SplFileInfo[]
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* Each item in the array contains the information for
|
||||
* a single plugin.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pluginInfo = null;
|
||||
|
||||
/**
|
||||
* @param $dirPath
|
||||
* @return FilesPluginInformation
|
||||
*/
|
||||
public static function newFromDir($dirPath)
|
||||
{
|
||||
return new self(new \DirectoryIterator($dirPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Iterator $files
|
||||
*/
|
||||
public function __construct(\Iterator $files)
|
||||
{
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
if ($this->pluginInfo === null) {
|
||||
$this->loadPluginInfo();
|
||||
}
|
||||
|
||||
return $this->pluginInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the class names of plugins that have been
|
||||
* loaded.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPluginClasses()
|
||||
{
|
||||
return array_map(
|
||||
function (\stdClass $plugin) {
|
||||
return $plugin->class;
|
||||
},
|
||||
$this->getInstalledPlugins()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load plugin information from a given list of files.
|
||||
*/
|
||||
protected function loadPluginInfo()
|
||||
{
|
||||
$this->pluginInfo = [];
|
||||
foreach ($this->files as $fileInfo) {
|
||||
if ($fileInfo instanceof \SplFileInfo) {
|
||||
if ($fileInfo->isFile() && $fileInfo->getExtension() == 'php') {
|
||||
$this->addPluginFromFile($fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plugin to the list from a given file.
|
||||
* @param \SplFileInfo $fileInfo
|
||||
*/
|
||||
protected function addPluginFromFile(\SplFileInfo $fileInfo)
|
||||
{
|
||||
$class = $this->getFullClassFromFile($fileInfo);
|
||||
|
||||
if (!is_null($class)) {
|
||||
$newPlugin = new \stdClass();
|
||||
$newPlugin->class = $class;
|
||||
$newPlugin->source = "core";
|
||||
$parts = explode('\\', $newPlugin->class);
|
||||
$newPlugin->name = end($parts);
|
||||
|
||||
$this->pluginInfo[] = $newPlugin;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine plugin class name for a given file.
|
||||
* @param \SplFileInfo $fileInfo
|
||||
* @return null|string
|
||||
*/
|
||||
protected function getFullClassFromFile(\SplFileInfo $fileInfo)
|
||||
{
|
||||
$contents = file_get_contents($fileInfo->getRealPath());
|
||||
$matches = [];
|
||||
|
||||
preg_match('#class +([A-Za-z]+) +implements#i', $contents, $matches);
|
||||
|
||||
if (isset($matches[1])) {
|
||||
$className = $matches[1];
|
||||
|
||||
$matches = [];
|
||||
preg_match('#namespace +([A-Za-z\\\\]+);#i', $contents, $matches);
|
||||
$namespace = $matches[1];
|
||||
|
||||
return $namespace . '\\' . $className;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
namespace PHPCensor\Plugin\Util;
|
||||
|
||||
/**
|
||||
* Interface InstalledPluginInformation
|
||||
* @package PHPCensor\Plugin\Util
|
||||
*/
|
||||
interface InstalledPluginInformation
|
||||
{
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Returns an array of all the class names of plugins that have been
|
||||
* loaded.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPluginClasses();
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Plugin\Util;
|
||||
|
||||
/**
|
||||
* Class PluginInformationCollection
|
||||
* @package PHPCensor\Plugin\Util
|
||||
*/
|
||||
class PluginInformationCollection implements InstalledPluginInformation
|
||||
{
|
||||
/**
|
||||
* @var InstalledPluginInformation[]
|
||||
*/
|
||||
protected $pluginInformations = [];
|
||||
|
||||
/**
|
||||
* Add a plugin to the collection.
|
||||
* @param InstalledPluginInformation $information
|
||||
*/
|
||||
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 = [];
|
||||
|
||||
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 = [];
|
||||
|
||||
foreach ($this->pluginInformations as $single) {
|
||||
$arr = array_merge($arr, $single->getPluginClasses());
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
|
@ -169,12 +169,6 @@
|
|||
<i class="fa fa-angle-double-right"></i> <?php Lang::out('manage_users'); ?>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="<?php print APP_URL; ?>plugin">
|
||||
<i class="fa fa-angle-double-right"></i> <?php Lang::out('plugins'); ?>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace Tests\PHPCensor\Plugin\Util;
|
||||
|
||||
use PHPCensor\Plugin\Util\ComposerPluginInformation;
|
||||
|
||||
class ComposerPluginInformationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ComposerPluginInformation
|
||||
*/
|
||||
protected $testedInformation;
|
||||
|
||||
protected function setUpFromFile($file)
|
||||
{
|
||||
$this->testedInformation = ComposerPluginInformation::buildFromYaml($file);
|
||||
}
|
||||
|
||||
protected function setup()
|
||||
{
|
||||
$this->setUpFromFile(
|
||||
__DIR__ . "/../../../../vendor/composer/installed.json"
|
||||
);
|
||||
}
|
||||
|
||||
public function testBuildFromYaml_ReturnsInstance()
|
||||
{
|
||||
$this->setup();
|
||||
$this->assertInstanceOf(
|
||||
'\PHPCensor\Plugin\Util\ComposerPluginInformation',
|
||||
$this->testedInformation
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetInstalledPlugins_ReturnsStdClassArray()
|
||||
{
|
||||
$this->setup();
|
||||
$plugins = $this->testedInformation->getInstalledPlugins();
|
||||
$this->assertInternalType("array", $plugins);
|
||||
$this->assertContainsOnly("stdClass", $plugins);
|
||||
}
|
||||
|
||||
public function testGetPluginClasses_ReturnsStringArray()
|
||||
{
|
||||
$this->setup();
|
||||
$classes = $this->testedInformation->getPluginClasses();
|
||||
$this->assertInternalType("array", $classes);
|
||||
$this->assertContainsOnly("string", $classes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace Tests\PHPCensor\Plugin\Util;
|
||||
|
||||
use PHPCensor\Plugin\Util\FilesPluginInformation;
|
||||
|
||||
class FilesPluginInformationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testGetInstalledPlugins_returnsObjects()
|
||||
{
|
||||
$pluginDirPath = dirname(dirname(dirname(dirname(__DIR__)))) . "/src/PHPCensor/Plugin/";
|
||||
$test = FilesPluginInformation::newFromDir($pluginDirPath);
|
||||
$pluginInfos = $test->getInstalledPlugins();
|
||||
|
||||
$this->assertContainsOnlyInstancesOf('stdClass', $pluginInfos);
|
||||
}
|
||||
|
||||
public function testGetPluginClasses_returnsStrings()
|
||||
{
|
||||
$pluginDirPath = dirname(dirname(dirname(dirname(__DIR__)))) . "/src/PHPCensor/Plugin";
|
||||
$test = FilesPluginInformation::newFromDir($pluginDirPath);
|
||||
$pluginInfos = $test->getPluginClasses();
|
||||
|
||||
$this->assertContainsOnly('string', $pluginInfos);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue