* @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); } }