From 5ffcc5a832909f669e9d99e1d657cbcfb32a8469 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 10 Jan 2017 23:14:26 +0700 Subject: [PATCH] Removed plugin page --- src/PHPCensor/Controller/PluginController.php | 60 ------- .../Plugin/Util/ComposerPluginInformation.php | 153 ------------------ .../Plugin/Util/FilesPluginInformation.php | 137 ---------------- .../Util/InstalledPluginInformation.php | 26 --- .../Util/PluginInformationCollection.php | 59 ------- src/PHPCensor/View/layout.phtml | 6 - .../Util/ComposerPluginInformationTest.php | 59 ------- .../Util/FilesPluginInformationTest.php | 36 ----- 8 files changed, 536 deletions(-) delete mode 100644 src/PHPCensor/Controller/PluginController.php delete mode 100644 src/PHPCensor/Plugin/Util/ComposerPluginInformation.php delete mode 100644 src/PHPCensor/Plugin/Util/FilesPluginInformation.php delete mode 100644 src/PHPCensor/Plugin/Util/InstalledPluginInformation.php delete mode 100644 src/PHPCensor/Plugin/Util/PluginInformationCollection.php delete mode 100644 tests/PHPCensor/Plugin/Util/ComposerPluginInformationTest.php delete mode 100644 tests/PHPCensor/Plugin/Util/FilesPluginInformationTest.php diff --git a/src/PHPCensor/Controller/PluginController.php b/src/PHPCensor/Controller/PluginController.php deleted file mode 100644 index e4d1a81a..00000000 --- a/src/PHPCensor/Controller/PluginController.php +++ /dev/null @@ -1,60 +0,0 @@ - - * @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); - } -} diff --git a/src/PHPCensor/Plugin/Util/ComposerPluginInformation.php b/src/PHPCensor/Plugin/Util/ComposerPluginInformation.php deleted file mode 100644 index 7202ade0..00000000 --- a/src/PHPCensor/Plugin/Util/ComposerPluginInformation.php +++ /dev/null @@ -1,153 +0,0 @@ -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; - } -} diff --git a/src/PHPCensor/Plugin/Util/FilesPluginInformation.php b/src/PHPCensor/Plugin/Util/FilesPluginInformation.php deleted file mode 100644 index 02e96f5d..00000000 --- a/src/PHPCensor/Plugin/Util/FilesPluginInformation.php +++ /dev/null @@ -1,137 +0,0 @@ -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; - } - } -} diff --git a/src/PHPCensor/Plugin/Util/InstalledPluginInformation.php b/src/PHPCensor/Plugin/Util/InstalledPluginInformation.php deleted file mode 100644 index 957bf9ed..00000000 --- a/src/PHPCensor/Plugin/Util/InstalledPluginInformation.php +++ /dev/null @@ -1,26 +0,0 @@ -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; - } -} diff --git a/src/PHPCensor/View/layout.phtml b/src/PHPCensor/View/layout.phtml index a144c76d..94416f05 100644 --- a/src/PHPCensor/View/layout.phtml +++ b/src/PHPCensor/View/layout.phtml @@ -169,12 +169,6 @@ - -
  • - - - -
  • diff --git a/tests/PHPCensor/Plugin/Util/ComposerPluginInformationTest.php b/tests/PHPCensor/Plugin/Util/ComposerPluginInformationTest.php deleted file mode 100644 index cb5b65e1..00000000 --- a/tests/PHPCensor/Plugin/Util/ComposerPluginInformationTest.php +++ /dev/null @@ -1,59 +0,0 @@ -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); - } -} - diff --git a/tests/PHPCensor/Plugin/Util/FilesPluginInformationTest.php b/tests/PHPCensor/Plugin/Util/FilesPluginInformationTest.php deleted file mode 100644 index 6d692b55..00000000 --- a/tests/PHPCensor/Plugin/Util/FilesPluginInformationTest.php +++ /dev/null @@ -1,36 +0,0 @@ -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); - } -} -