|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace TaskRunner\Composer\TaskRunner\Commands; |
| 6 | + |
| 7 | +use OpenEuropa\TaskRunner\Commands\AbstractCommands; |
| 8 | +use Robo\Collection\CollectionBuilder; |
| 9 | +use Robo\Task\Composer\loadTasks; |
| 10 | + |
| 11 | +/** |
| 12 | + * Provides Composer commands. |
| 13 | + */ |
| 14 | +class ComposerCommands extends AbstractCommands |
| 15 | +{ |
| 16 | + use loadTasks; |
| 17 | + |
| 18 | + /** |
| 19 | + * Options to be used with most of Composer commands. |
| 20 | + * |
| 21 | + * @var array |
| 22 | + */ |
| 23 | + protected const DEFAULT_OPTIONS = [ |
| 24 | + 'prefer-source' => false, |
| 25 | + 'prefer-dist' => false, |
| 26 | + 'dev' => true, |
| 27 | + 'optimize-autoloader' => false, |
| 28 | + 'ignore-platform-reqs' => false, |
| 29 | + 'no-plugins' => false, |
| 30 | + 'no-scripts' => false, |
| 31 | + ]; |
| 32 | + |
| 33 | + /** |
| 34 | + * Install one or more modules. |
| 35 | + * |
| 36 | + * @param array $options |
| 37 | + * The command line options. |
| 38 | + * |
| 39 | + * @return \Robo\Collection\CollectionBuilder |
| 40 | + * The Robo collection builder. |
| 41 | + * |
| 42 | + * @command composer:install |
| 43 | + */ |
| 44 | + public function install(array $options = self::DEFAULT_OPTIONS): CollectionBuilder |
| 45 | + { |
| 46 | + $task = $this->taskComposerInstall( |
| 47 | + $this->getConfig()->get('composer.bin') |
| 48 | + ); |
| 49 | + $this->applyOptions($task, $options); |
| 50 | + |
| 51 | + return $this->collectionBuilder()->addTask($task); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Applies Composer options. |
| 56 | + * |
| 57 | + * @param \Robo\Collection\CollectionBuilder $task |
| 58 | + * The Composer Robo task. |
| 59 | + * @param array $options |
| 60 | + * The command line options. |
| 61 | + */ |
| 62 | + protected function applyOptions( |
| 63 | + CollectionBuilder $task, |
| 64 | + array $options |
| 65 | + ): void { |
| 66 | + /** @var \Robo\Task\Composer\Base $task */ |
| 67 | + if ($options['prefer-source']) { |
| 68 | + $task->preferSource(); |
| 69 | + } |
| 70 | + |
| 71 | + $task |
| 72 | + ->preferDist($options['prefer-dist']) |
| 73 | + ->optimizeAutoloader($options['optimize-autoloader']) |
| 74 | + ->disablePlugins($options['no-plugins']) |
| 75 | + ->noScripts($options['no-scripts']); |
| 76 | + |
| 77 | + if (!$options['dev']) { |
| 78 | + $task->noDev(); |
| 79 | + } |
| 80 | + if ($options['ignore-platform-reqs']) { |
| 81 | + $task->ignorePlatformRequirements($options['ignore-platform-reqs']); |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments