phpci/PHPCI/Plugin/Composer.php
2013-10-10 01:01:06 +01:00

55 lines
1.6 KiB
PHP

<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2013, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
*/
namespace PHPCI\Plugin;
use PHPCI\Builder;
use PHPCI\Model\Build;
/**
* Composer Plugin - Provides access to Composer functionality.
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Plugins
*/
class Composer implements \PHPCI\Plugin
{
protected $directory;
protected $action;
protected $preferDist;
protected $phpci;
public function __construct(Builder $phpci, Build $build, array $options = array())
{
$path = $phpci->buildPath;
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $path . '/' . $options['directory'] : $path;
$this->action = isset($options['action']) ? $options['action'] : 'update';
$this->preferDist = isset($options['prefer_dist']) ? $options['prefer_dist'] : true;
}
/**
* Executes Composer and runs a specified command (e.g. install / update)
*/
public function execute()
{
$composerLocation = $this->phpci->findBinary(array('composer', 'composer.phar'));
if (!$composerLocation) {
$this->phpci->logFailure('Could not find Composer.');
return false;
}
$cmd = $composerLocation . ' --no-ansi --no-interaction ';
$cmd .= ($this->preferDist ? '--prefer-dist' : null) . ' --working-dir="%s" %s';
return $this->phpci->executeCommand($cmd, $this->directory, $this->action);
}
}