2013-05-03 17:02:53 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Plugin;
|
2013-05-03 17:02:53 +02:00
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
use PHPCensor;
|
|
|
|
use PHPCensor\Builder;
|
|
|
|
use PHPCensor\Model\Build;
|
2016-07-11 18:00:04 +02:00
|
|
|
use PHPCensor\Plugin;
|
2017-01-13 16:35:41 +01:00
|
|
|
use PHPCensor\ZeroConfigPluginInterface;
|
2013-10-10 02:01:06 +02:00
|
|
|
|
2013-05-16 03:30:48 +02:00
|
|
|
/**
|
2017-01-10 18:46:19 +01:00
|
|
|
* Composer Plugin - Provides access to Composer functionality.
|
|
|
|
*
|
2017-03-04 16:39:56 +01:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
2017-01-10 18:46:19 +01:00
|
|
|
*/
|
2017-01-13 16:35:41 +01:00
|
|
|
class Composer extends Plugin implements ZeroConfigPluginInterface
|
2013-05-03 17:02:53 +02:00
|
|
|
{
|
2013-05-16 16:50:19 +02:00
|
|
|
protected $directory;
|
|
|
|
protected $action;
|
2013-07-18 15:10:55 +02:00
|
|
|
protected $preferDist;
|
2015-05-21 14:23:06 +02:00
|
|
|
protected $nodev;
|
2016-04-25 19:30:23 +02:00
|
|
|
protected $ignorePlatformReqs;
|
|
|
|
protected $preferSource;
|
2013-05-03 17:02:53 +02:00
|
|
|
|
2017-01-11 16:15:54 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function pluginName()
|
|
|
|
{
|
|
|
|
return 'composer';
|
|
|
|
}
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
2016-07-11 18:00:04 +02:00
|
|
|
* {@inheritdoc}
|
2014-12-08 12:25:33 +01:00
|
|
|
*/
|
2016-07-22 09:05:34 +02:00
|
|
|
public function __construct(Builder $builder, Build $build, array $options = [])
|
2013-05-16 16:50:19 +02:00
|
|
|
{
|
2016-07-22 09:05:34 +02:00
|
|
|
parent::__construct($builder, $build, $options);
|
2016-07-11 18:00:04 +02:00
|
|
|
|
2016-07-22 09:05:34 +02:00
|
|
|
$path = $this->builder->buildPath;
|
2016-04-25 19:30:23 +02:00
|
|
|
$this->directory = $path;
|
|
|
|
$this->action = 'install';
|
|
|
|
$this->preferDist = false;
|
|
|
|
$this->preferSource = false;
|
|
|
|
$this->nodev = false;
|
|
|
|
$this->ignorePlatformReqs = false;
|
2014-05-12 12:58:43 +02:00
|
|
|
|
|
|
|
if (array_key_exists('directory', $options)) {
|
2015-10-23 05:18:22 +02:00
|
|
|
$this->directory = $path . DIRECTORY_SEPARATOR . $options['directory'];
|
2014-05-12 12:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('action', $options)) {
|
|
|
|
$this->action = $options['action'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('prefer_dist', $options)) {
|
|
|
|
$this->preferDist = (bool)$options['prefer_dist'];
|
|
|
|
}
|
2015-05-21 14:23:06 +02:00
|
|
|
|
2016-04-27 16:20:20 +02:00
|
|
|
if (array_key_exists('prefer_source', $options)) {
|
2016-06-23 17:35:51 +02:00
|
|
|
$this->preferDist = false;
|
2016-04-27 16:20:20 +02:00
|
|
|
$this->preferSource = (bool)$options['prefer_source'];
|
|
|
|
}
|
|
|
|
|
2015-05-21 14:23:06 +02:00
|
|
|
if (array_key_exists('no_dev', $options)) {
|
|
|
|
$this->nodev = (bool)$options['no_dev'];
|
|
|
|
}
|
2016-04-25 19:30:23 +02:00
|
|
|
|
|
|
|
if (array_key_exists('ignore_platform_reqs', $options)) {
|
|
|
|
$this->ignorePlatformReqs = (bool)$options['ignore_platform_reqs'];
|
|
|
|
}
|
2016-07-11 18:00:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this plugin can be executed.
|
|
|
|
* @param $stage
|
|
|
|
* @param Builder $builder
|
|
|
|
* @param Build $build
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function canExecute($stage, Builder $builder, Build $build)
|
|
|
|
{
|
|
|
|
$path = $builder->buildPath . DIRECTORY_SEPARATOR . 'composer.json';
|
|
|
|
|
|
|
|
if (file_exists($path) && $stage == 'setup') {
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-10 10:05:10 +02:00
|
|
|
|
2016-07-11 18:00:04 +02:00
|
|
|
return false;
|
2013-05-16 16:50:19 +02:00
|
|
|
}
|
2013-05-03 17:02:53 +02:00
|
|
|
|
2013-05-16 18:17:29 +02:00
|
|
|
/**
|
|
|
|
* Executes Composer and runs a specified command (e.g. install / update)
|
|
|
|
*/
|
2013-05-16 16:50:19 +02:00
|
|
|
public function execute()
|
|
|
|
{
|
2016-07-22 09:05:34 +02:00
|
|
|
$composerLocation = $this->builder->findBinary(['composer', 'composer.phar']);
|
2017-02-01 16:27:47 +01:00
|
|
|
$cmd = $composerLocation . ' --no-ansi --no-interaction ';
|
2014-05-12 12:58:43 +02:00
|
|
|
|
|
|
|
if ($this->preferDist) {
|
2016-07-22 09:05:34 +02:00
|
|
|
$this->builder->log('Using --prefer-dist flag');
|
2016-04-27 16:20:20 +02:00
|
|
|
$cmd .= ' --prefer-dist';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->preferSource) {
|
2016-07-22 09:05:34 +02:00
|
|
|
$this->builder->log('Using --prefer-source flag');
|
2016-04-27 16:20:20 +02:00
|
|
|
$cmd .= ' --prefer-source';
|
2014-05-12 12:58:43 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 14:23:06 +02:00
|
|
|
if ($this->nodev) {
|
2016-07-22 09:05:34 +02:00
|
|
|
$this->builder->log('Using --no-dev flag');
|
2015-05-21 14:23:06 +02:00
|
|
|
$cmd .= ' --no-dev';
|
|
|
|
}
|
|
|
|
|
2016-04-25 19:30:23 +02:00
|
|
|
if ($this->ignorePlatformReqs) {
|
2016-07-22 09:05:34 +02:00
|
|
|
$this->builder->log('Using --ignore-platform-reqs flag');
|
2016-04-25 19:30:23 +02:00
|
|
|
$cmd .= ' --ignore-platform-reqs';
|
|
|
|
}
|
|
|
|
|
2014-05-12 12:58:43 +02:00
|
|
|
$cmd .= ' --working-dir="%s" %s';
|
2013-10-08 09:30:15 +02:00
|
|
|
|
2016-07-22 09:05:34 +02:00
|
|
|
return $this->builder->executeCommand($cmd, $this->directory, $this->action);
|
2013-05-16 16:50:19 +02:00
|
|
|
}
|
|
|
|
}
|