2 namespace Robo\Task\Composer;
4 use Robo\Contract\CommandInterface;
5 use Robo\Exception\TaskException;
6 use Robo\Task\BaseTask;
8 abstract class Base extends BaseTask implements CommandInterface
10 use \Robo\Common\ExecOneCommand;
15 protected $command = '';
20 protected $built = false;
40 protected $nointeraction;
47 protected $action = '';
50 * @param null|string $pathToComposer
52 * @throws \Robo\Exception\TaskException
54 public function __construct($pathToComposer = null)
56 $this->command = $pathToComposer;
57 if (!$this->command) {
58 $this->command = $this->findExecutablePhar('composer');
60 if (!$this->command) {
61 throw new TaskException(__CLASS__, "Neither local composer.phar nor global composer installation could be found.");
66 * adds `prefer-dist` option to composer
70 public function preferDist($preferDist = true)
73 return $this->preferSource();
75 $this->prefer = '--prefer-dist';
80 * adds `prefer-source` option to composer
84 public function preferSource()
86 $this->prefer = '--prefer-source';
91 * adds `dev` option to composer
95 public function dev($dev = true)
98 return $this->noDev();
100 $this->dev = '--dev';
105 * adds `no-dev` option to composer
109 public function noDev()
111 $this->dev = '--no-dev';
116 * adds `ansi` option to composer
120 public function ansi($ansi = true)
123 return $this->noAnsi();
125 $this->ansi = '--ansi';
130 * adds `no-ansi` option to composer
134 public function noAnsi()
136 $this->ansi = '--no-ansi';
140 public function interaction($interaction = true)
143 return $this->noInteraction();
149 * adds `no-interaction` option to composer
153 public function noInteraction()
155 $this->nointeraction = '--no-interaction';
160 * adds `optimize-autoloader` option to composer
164 public function optimizeAutoloader($optimize = true)
167 $this->option('--optimize-autoloader');
173 * adds `ignore-platform-reqs` option to composer
177 public function ignorePlatformRequirements($ignore = true)
179 $this->option('--ignore-platform-reqs');
188 public function disablePlugins($disable = true)
191 $this->option('--no-plugins');
201 public function noScripts($disable = true)
204 $this->option('--no-scripts');
210 * adds `--working-dir $dir` option to composer
214 public function workingDir($dir)
216 $this->option("--working-dir", $dir);
221 * Copy class fields into command options as directed.
223 public function buildCommand()
225 if (!isset($this->ansi) && $this->getConfig()->get(\Robo\Config\Config::DECORATED)) {
228 if (!isset($this->nointeraction) && !$this->getConfig()->get(\Robo\Config\Config::INTERACTIVE)) {
229 $this->noInteraction();
231 $this->option($this->prefer)
233 ->option($this->nointeraction)
234 ->option($this->ansi);
240 public function getCommand()
243 $this->buildCommand();
246 return "{$this->command} {$this->action}{$this->arguments}";