2013-10-08 17:28:46 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
2014-05-12 18:26:17 +02:00
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
2013-10-08 17:28:46 +02:00
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
2014-05-12 18:26:17 +02:00
|
|
|
* @link https://www.phptesting.org/
|
2013-10-08 17:28:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PHPCI\Controller;
|
|
|
|
|
|
|
|
use b8;
|
|
|
|
use PHPCI\Model\Build;
|
2014-02-25 20:33:00 +01:00
|
|
|
use PHPCI\Plugin\Util\ComposerPluginInformation;
|
2014-02-25 23:22:32 +01:00
|
|
|
use PHPCI\Plugin\Util\FilesPluginInformation;
|
|
|
|
use PHPCI\Plugin\Util\PluginInformationCollection;
|
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
|
|
|
|
*/
|
|
|
|
class PluginController extends \PHPCI\Controller
|
|
|
|
{
|
|
|
|
protected $required = array(
|
2014-12-02 17:26:55 +01:00
|
|
|
'php',
|
|
|
|
'ext-mcrypt',
|
|
|
|
'ext-pdo',
|
|
|
|
'ext-pdo_mysql',
|
2013-10-08 17:28:46 +02:00
|
|
|
'block8/b8framework',
|
|
|
|
'ircmaxell/password-compat',
|
|
|
|
'swiftmailer/swiftmailer',
|
|
|
|
'symfony/yaml',
|
2013-12-13 16:00:05 +01:00
|
|
|
'symfony/console',
|
|
|
|
'psr/log',
|
|
|
|
'monolog/monolog',
|
2014-12-02 17:26:55 +01:00
|
|
|
'pimple/pimple',
|
|
|
|
'robmorgan/phinx',
|
2013-10-08 17:28:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
protected $canInstall;
|
|
|
|
protected $composerPath;
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2014-12-03 11:28:44 +01:00
|
|
|
$this->requireAdmin();
|
2013-10-11 22:51:23 +02:00
|
|
|
|
2013-10-08 17:28:46 +02:00
|
|
|
$this->view->canWrite = is_writable(APPLICATION_PATH . 'composer.json');
|
|
|
|
$this->view->required = $this->required;
|
|
|
|
|
|
|
|
$json = $this->getComposerJson();
|
2013-12-29 18:35:33 +01:00
|
|
|
$this->view->installedPackages = $json['require'];
|
|
|
|
$this->view->suggestedPackages = $json['suggest'];
|
|
|
|
|
2014-02-25 23:22:32 +01:00
|
|
|
$pluginInfo = new PluginInformationCollection();
|
|
|
|
$pluginInfo->add(FilesPluginInformation::newFromDir(
|
|
|
|
PHPCI_DIR . "PHPCI/Plugin/"
|
|
|
|
));
|
|
|
|
$pluginInfo->add(ComposerPluginInformation::buildFromYaml(
|
2013-12-29 18:35:33 +01:00
|
|
|
PHPCI_DIR . "vendor/composer/installed.json"
|
2014-02-25 23:22:32 +01:00
|
|
|
));
|
|
|
|
|
2013-12-29 18:35:33 +01:00
|
|
|
$this->view->plugins = $pluginInfo->getInstalledPlugins();
|
2013-10-08 17:28:46 +02:00
|
|
|
|
2014-12-02 17:26:55 +01:00
|
|
|
$this->layout->title = 'Plugins';
|
2014-04-24 17:25:24 +02:00
|
|
|
|
2013-10-08 17:28:46 +02:00
|
|
|
return $this->view->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove()
|
|
|
|
{
|
2014-12-03 11:28:44 +01:00
|
|
|
$this->requireAdmin();
|
2013-10-11 22:51:23 +02:00
|
|
|
|
2013-10-08 17:28:46 +02:00
|
|
|
$package = $this->getParam('package', null);
|
|
|
|
$json = $this->getComposerJson();
|
|
|
|
|
|
|
|
if (!in_array($package, $this->required)) {
|
|
|
|
unset($json['require'][$package]);
|
|
|
|
$this->setComposerJson($json);
|
|
|
|
|
|
|
|
header('Location: ' . PHPCI_URL . 'plugin?r=' . $package);
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Location: ' . PHPCI_URL);
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function install()
|
|
|
|
{
|
2014-12-03 11:28:44 +01:00
|
|
|
$this->requireAdmin();
|
2013-10-11 22:51:23 +02:00
|
|
|
|
2013-10-08 17:28:46 +02:00
|
|
|
$package = $this->getParam('package', null);
|
|
|
|
$version = $this->getParam('version', '*');
|
|
|
|
|
|
|
|
$json = $this->getComposerJson();
|
|
|
|
$json['require'][$package] = $version;
|
|
|
|
$this->setComposerJson($json);
|
|
|
|
|
|
|
|
header('Location: ' . PHPCI_URL . 'plugin?w=' . $package);
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getComposerJson()
|
|
|
|
{
|
|
|
|
$json = file_get_contents(APPLICATION_PATH . 'composer.json');
|
|
|
|
return json_decode($json, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setComposerJson($array)
|
|
|
|
{
|
|
|
|
$json = json_encode($array);
|
|
|
|
file_put_contents(APPLICATION_PATH . 'composer.json', $json);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function findBinary($binary)
|
|
|
|
{
|
|
|
|
if (is_string($binary)) {
|
|
|
|
$binary = array($binary);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($binary as $bin) {
|
|
|
|
// Check project root directory:
|
|
|
|
if (is_file(APPLICATION_PATH . $bin)) {
|
|
|
|
return APPLICATION_PATH . $bin;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check Composer bin dir:
|
|
|
|
if (is_file(APPLICATION_PATH . 'vendor/bin/' . $bin)) {
|
|
|
|
return APPLICATION_PATH . 'vendor/bin/' . $bin;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use "which"
|
|
|
|
$which = trim(shell_exec('which ' . $bin));
|
|
|
|
|
|
|
|
if (!empty($which)) {
|
|
|
|
return $which;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function packagistSearch()
|
|
|
|
{
|
2013-10-10 02:01:06 +02:00
|
|
|
$searchQuery = $this->getParam('q', '');
|
2013-10-08 17:28:46 +02:00
|
|
|
$http = new \b8\HttpClient();
|
2014-05-12 19:26:44 +02:00
|
|
|
$http->setHeaders(array('User-Agent: PHPCI/1.0 (+https://www.phptesting.org)'));
|
2013-10-10 02:01:06 +02:00
|
|
|
$res = $http->get('https://packagist.org/search.json', array('q' => $searchQuery));
|
2013-10-08 17:28:46 +02:00
|
|
|
|
|
|
|
die(json_encode($res['body']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function packagistVersions()
|
|
|
|
{
|
|
|
|
$name = $this->getParam('p', '');
|
|
|
|
$http = new \b8\HttpClient();
|
2014-05-12 19:26:44 +02:00
|
|
|
$http->setHeaders(array('User-Agent: PHPCI/1.0 (+https://www.phptesting.org)'));
|
2013-10-08 17:28:46 +02:00
|
|
|
$res = $http->get('https://packagist.org/packages/'.$name.'.json');
|
|
|
|
|
|
|
|
die(json_encode($res['body']));
|
|
|
|
}
|
|
|
|
}
|