php-censor/src/PHPCensor/Controller/PluginController.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2013-10-08 17:28:46 +02:00
<?php
2013-10-08 17:28:46 +02:00
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
2013-10-08 17:28:46 +02:00
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
2013-10-08 17:28:46 +02:00
*/
2016-07-19 20:28:11 +02:00
namespace PHPCensor\Controller;
2013-10-08 17:28:46 +02:00
2016-07-19 20:28:11 +02:00
use PHPCensor\Helper\Lang;
use PHPCensor\Plugin\Util\ComposerPluginInformation;
use PHPCensor\Plugin\Util\FilesPluginInformation;
use PHPCensor\Plugin\Util\PluginInformationCollection;
use PHPCensor\Controller;
2013-10-08 17:28:46 +02:00
/**
* Plugin Controller - Provides support for installing Composer packages.
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Web
*/
2016-05-09 08:20:26 +02:00
class PluginController extends Controller
2013-10-08 17:28:46 +02:00
{
/**
* List all enabled plugins, installed and recommend packages.
* @return string
*/
2013-10-08 17:28:46 +02:00
public function index()
{
$this->requireAdmin();
2013-10-08 17:28:46 +02:00
$json = $this->getComposerJson();
$this->view->installedPackages = $json['require'];
$pluginInfo = new PluginInformationCollection();
2016-07-21 17:20:34 +02:00
$pluginInfo->add(FilesPluginInformation::newFromDir(SRC_DIR . "Plugin" . DIRECTORY_SEPARATOR));
$pluginInfo->add(ComposerPluginInformation::buildFromYaml(
2016-04-21 19:05:32 +02:00
ROOT_DIR . "vendor" . DIRECTORY_SEPARATOR . "composer" . DIRECTORY_SEPARATOR . "installed.json"
));
$this->view->plugins = $pluginInfo->getInstalledPlugins();
2013-10-08 17:28:46 +02:00
2014-12-04 15:40:28 +01:00
$this->layout->title = Lang::get('plugins');
2013-10-08 17:28:46 +02:00
return $this->view->render();
}
/**
* Get the json-decoded contents of the composer.json file.
* @return mixed
*/
2013-10-08 17:28:46 +02:00
protected function getComposerJson()
{
2016-04-21 19:05:32 +02:00
$json = file_get_contents(ROOT_DIR . 'composer.json');
2013-10-08 17:28:46 +02:00
return json_decode($json, true);
}
}