2013-05-03 17:02:53 +02:00
|
|
|
<?php
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
2014-05-12 18:26:17 +02:00
|
|
|
* 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/
|
|
|
|
*/
|
2013-05-03 17:02:53 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Plugin;
|
|
|
|
|
2014-04-25 11:17:39 +02:00
|
|
|
use PHPCI;
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Builder;
|
|
|
|
use PHPCI\Model\Build;
|
|
|
|
|
2013-05-16 03:30:48 +02:00
|
|
|
/**
|
|
|
|
* Composer Plugin - Provides access to Composer functionality.
|
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
2014-04-25 11:17:39 +02:00
|
|
|
class Composer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
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;
|
2013-05-16 16:50:19 +02:00
|
|
|
protected $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
protected $build;
|
2013-05-03 17:02:53 +02:00
|
|
|
|
2014-04-25 11:17:39 +02:00
|
|
|
public static function canExecute($stage, Builder $builder, Build $build)
|
|
|
|
{
|
|
|
|
$path = $builder->buildPath . '/composer.json';
|
|
|
|
|
|
|
|
if (file_exists($path) && $stage == 'setup') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-05-16 16:50:19 +02:00
|
|
|
{
|
2014-05-12 12:58:43 +02:00
|
|
|
$path = $phpci->buildPath;
|
|
|
|
$this->phpci = $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
$this->build = $build;
|
2014-05-12 12:58:43 +02:00
|
|
|
$this->directory = $path;
|
|
|
|
$this->action = 'install';
|
|
|
|
$this->preferDist = false;
|
|
|
|
|
|
|
|
if (array_key_exists('directory', $options)) {
|
|
|
|
$this->directory = $path . '/' . $options['directory'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('action', $options)) {
|
|
|
|
$this->action = $options['action'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('prefer_dist', $options)) {
|
|
|
|
$this->preferDist = (bool)$options['prefer_dist'];
|
|
|
|
}
|
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()
|
|
|
|
{
|
2013-10-08 09:50:10 +02:00
|
|
|
$composerLocation = $this->phpci->findBinary(array('composer', 'composer.phar'));
|
2013-10-08 09:30:15 +02:00
|
|
|
|
|
|
|
if (!$composerLocation) {
|
|
|
|
$this->phpci->logFailure('Could not find Composer.');
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-12 12:58:43 +02:00
|
|
|
|
2014-03-08 18:30:32 +01:00
|
|
|
$cmd = '';
|
2014-05-12 12:58:43 +02:00
|
|
|
|
2014-03-12 18:37:57 +01:00
|
|
|
if (IS_WIN) {
|
2014-03-08 18:30:32 +01:00
|
|
|
$cmd = 'php ';
|
|
|
|
}
|
2014-05-12 12:58:43 +02:00
|
|
|
|
2014-03-08 18:30:32 +01:00
|
|
|
$cmd .= $composerLocation . ' --no-ansi --no-interaction ';
|
2014-05-12 12:58:43 +02:00
|
|
|
|
|
|
|
if ($this->preferDist) {
|
|
|
|
$this->phpci->log('Using --prefer-dist flag');
|
|
|
|
$cmd .= '--prefer-dist';
|
|
|
|
} else {
|
|
|
|
$this->phpci->log('Using --prefer-source flag');
|
|
|
|
$cmd .= '--prefer-source';
|
|
|
|
}
|
|
|
|
|
|
|
|
$cmd .= ' --working-dir="%s" %s';
|
2013-10-08 09:30:15 +02:00
|
|
|
|
2013-05-16 16:50:19 +02:00
|
|
|
return $this->phpci->executeCommand($cmd, $this->directory, $this->action);
|
|
|
|
}
|
|
|
|
}
|