diff --git a/src/Command/InstallPluginCommand.php b/src/Command/InstallPluginCommand.php index 0f961c4..d33880a 100644 --- a/src/Command/InstallPluginCommand.php +++ b/src/Command/InstallPluginCommand.php @@ -19,8 +19,8 @@ use Symfony\Component\Finder\Finder; use Ymir\Cli\ApiClient; use Ymir\Cli\CliConfiguration; +use Ymir\Cli\Executable\ComposerExecutable; use Ymir\Cli\GitHubClient; -use Ymir\Cli\Process\Process; use Ymir\Cli\ProjectConfiguration\ProjectConfiguration; use Ymir\Cli\Support\Arr; @@ -33,6 +33,13 @@ class InstallPluginCommand extends AbstractProjectCommand */ public const NAME = 'install-plugin'; + /** + * The Composer executable. + * + * @var ComposerExecutable + */ + private $composerExecutable; + /** * The file system. * @@ -57,10 +64,11 @@ class InstallPluginCommand extends AbstractProjectCommand /** * Constructor. */ - public function __construct(ApiClient $apiClient, CliConfiguration $cliConfiguration, Filesystem $filesystem, GitHubClient $gitHubClient, ProjectConfiguration $projectConfiguration, string $projectDirectory) + public function __construct(ApiClient $apiClient, CliConfiguration $cliConfiguration, ComposerExecutable $composerExecutable, Filesystem $filesystem, GitHubClient $gitHubClient, ProjectConfiguration $projectConfiguration, string $projectDirectory) { parent::__construct($apiClient, $cliConfiguration, $projectConfiguration); + $this->composerExecutable = $composerExecutable; $this->filesystem = $filesystem; $this->gitHubClient = $gitHubClient; $this->projectDirectory = rtrim($projectDirectory, '/'); @@ -90,7 +98,7 @@ protected function perform() if ('bedrock' === $projectType) { $this->output->info($message.' using Composer'); - Process::runShellCommandline('composer require ymirapp/wordpress-plugin'); + $this->composerExecutable->require('ymirapp/wordpress-plugin'); } elseif ('wordpress' === $projectType) { $this->output->info($message.' from GitHub'); $this->installFromGitHub(); diff --git a/src/Command/Project/InitializeProjectCommand.php b/src/Command/Project/InitializeProjectCommand.php index e958200..1a56683 100644 --- a/src/Command/Project/InitializeProjectCommand.php +++ b/src/Command/Project/InitializeProjectCommand.php @@ -24,9 +24,9 @@ use Ymir\Cli\Command\Docker\CreateDockerfileCommand; use Ymir\Cli\Command\InstallPluginCommand; use Ymir\Cli\Command\Provider\ConnectProviderCommand; +use Ymir\Cli\Executable\ComposerExecutable; use Ymir\Cli\Executable\DockerExecutable; use Ymir\Cli\Executable\WpCliExecutable; -use Ymir\Cli\Process\Process; use Ymir\Cli\ProjectConfiguration\ProjectConfiguration; use Ymir\Cli\Support\Arr; @@ -46,6 +46,13 @@ class InitializeProjectCommand extends AbstractCommand */ public const NAME = 'project:init'; + /** + * The Composer executable. + * + * @var ComposerExecutable + */ + private $composerExecutable; + /** * Docker executable. * @@ -77,10 +84,11 @@ class InitializeProjectCommand extends AbstractCommand /** * Constructor. */ - public function __construct(ApiClient $apiClient, CliConfiguration $cliConfiguration, DockerExecutable $dockerExecutable, Filesystem $filesystem, ProjectConfiguration $projectConfiguration, string $projectDirectory, WpCliExecutable $wpCliExecutable) + public function __construct(ApiClient $apiClient, CliConfiguration $cliConfiguration, ComposerExecutable $composerExecutable, DockerExecutable $dockerExecutable, Filesystem $filesystem, ProjectConfiguration $projectConfiguration, string $projectDirectory, WpCliExecutable $wpCliExecutable) { parent::__construct($apiClient, $cliConfiguration, $projectConfiguration); + $this->composerExecutable = $composerExecutable; $this->dockerExecutable = $dockerExecutable; $this->filesystem = $filesystem; $this->projectDirectory = rtrim($projectDirectory, '/'); @@ -213,7 +221,7 @@ private function checkForWordPress(string $projectType) if ('bedrock' === $projectType) { $this->output->info('Creating new Bedrock project'); - Process::runShellCommandline('composer create-project roots/bedrock .'); + $this->composerExecutable->createProject('roots/bedrock'); } elseif ('wordpress' === $projectType) { $this->output->info('Downloading WordPress using WP-CLI'); $this->wpCliExecutable->downloadWordPress(); diff --git a/src/Executable/ComposerExecutable.php b/src/Executable/ComposerExecutable.php new file mode 100644 index 0000000..df1b322 --- /dev/null +++ b/src/Executable/ComposerExecutable.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Ymir\Cli\Executable; + +class ComposerExecutable extends AbstractExecutable +{ + /** + * Create a new project from the given package into the given directory. + */ + public function createProject(string $package, string $directory = '.') + { + $this->run(sprintf('create-project %s %s', $package, $directory)); + } + + /** + * {@inheritdoc} + */ + public function getDisplayName(): string + { + return 'Composer'; + } + + /** + * {@inheritdoc} + */ + public function getExecutable(): string + { + return 'composer'; + } + + /** + * Add the given package to the project's "composer.json" file and install it. + */ + public function require(string $package) + { + $this->run(sprintf('require %s', $package)); + } +}