-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
260 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Console\Command\Composer; | ||
|
||
use Fidry\Console\Command\Command; | ||
use Fidry\Console\Command\Configuration; | ||
use Fidry\Console\ExitCode; | ||
use Fidry\Console\Input\IO; | ||
use Fidry\FileSystem\FileSystem; | ||
use KevinGH\Box\Composer\ComposerOrchestrator; | ||
use KevinGH\Box\Composer\ComposerProcessFactory; | ||
use KevinGH\Box\Console\ConfigurationLoader; | ||
use KevinGH\Box\Console\ConfigurationLocator; | ||
use Psr\Log\LogLevel; | ||
use RuntimeException; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Logger\ConsoleLogger; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @private | ||
*/ | ||
final class ComposerCheckVersion extends ComposerCommand | ||
{ | ||
public function getConfiguration(): Configuration | ||
{ | ||
$parentConfig = parent::getConfiguration(); | ||
|
||
return new Configuration( | ||
'composer:check-version', | ||
'🎵 Checks if the Composer executable used is compatible with Box', | ||
<<<'HELP' | ||
The <info>%command.name%</info> command will look for the Composer binary (in the system if not configured | ||
in the configuration file) and check if its version is compatible with Box. | ||
HELP, | ||
$parentConfig->getArguments(), | ||
$parentConfig->getOptions(), | ||
); | ||
} | ||
|
||
protected function orchestrate(ComposerOrchestrator $composerOrchestrator, IO $io): int | ||
{ | ||
$composerOrchestrator->checkVersion(); | ||
|
||
return ExitCode::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Console\Command\Composer; | ||
|
||
use Fidry\Console\Command\Command; | ||
use Fidry\Console\Command\Configuration; | ||
use Fidry\Console\ExitCode; | ||
use Fidry\Console\Input\IO; | ||
use Fidry\FileSystem\FileSystem; | ||
use KevinGH\Box\Composer\ComposerOrchestrator; | ||
use KevinGH\Box\Composer\ComposerProcessFactory; | ||
use KevinGH\Box\Console\ConfigurationLoader; | ||
use KevinGH\Box\Console\ConfigurationLocator; | ||
use Psr\Log\LogLevel; | ||
use RuntimeException; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Logger\ConsoleLogger; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @private | ||
*/ | ||
abstract class ComposerCommand implements Command | ||
{ | ||
private const FILE_ARGUMENT = 'file'; | ||
|
||
private const VERBOSITY_LEVEL_MAP = [ | ||
LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, | ||
LogLevel::INFO => OutputInterface::VERBOSITY_NORMAL, | ||
LogLevel::DEBUG => OutputInterface::VERBOSITY_VERBOSE, | ||
]; | ||
|
||
public function getConfiguration(): Configuration | ||
{ | ||
return new Configuration( | ||
'To configure.', | ||
'To configure.', | ||
'To configure.', | ||
[ | ||
new InputArgument( | ||
self::FILE_ARGUMENT, | ||
InputArgument::OPTIONAL, | ||
'The configuration file. (default: box.json, box.json.dist)', | ||
), | ||
], | ||
); | ||
} | ||
|
||
final public function execute(IO $io): int | ||
{ | ||
$composerOrchestrator = new ComposerOrchestrator( | ||
ComposerProcessFactory::create( | ||
$this->getComposerExecutable($io), | ||
$io, | ||
), | ||
new ConsoleLogger($io->getOutput(), self::VERBOSITY_LEVEL_MAP), | ||
new FileSystem(), | ||
); | ||
|
||
return $this->orchestrate($composerOrchestrator, $io); | ||
} | ||
|
||
abstract protected function orchestrate(ComposerOrchestrator $composerOrchestrator, IO $io): int; | ||
|
||
private function getComposerExecutable(IO $io): ?string | ||
{ | ||
try { | ||
$config = ConfigurationLoader::getConfig( | ||
$io->getArgument(self::FILE_ARGUMENT)->asNullableNonEmptyString() ?? ConfigurationLocator::findDefaultPath(), | ||
$io, | ||
false, | ||
); | ||
|
||
return $config->getComposerBin(); | ||
} catch (RuntimeException) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Console\Command\Composer; | ||
|
||
use Fidry\Console\Command\Command; | ||
use Fidry\Console\Command\Configuration; | ||
use Fidry\Console\ExitCode; | ||
use Fidry\Console\Input\IO; | ||
use Fidry\FileSystem\FileSystem; | ||
use KevinGH\Box\Composer\ComposerOrchestrator; | ||
use KevinGH\Box\Composer\ComposerProcessFactory; | ||
use KevinGH\Box\Console\ConfigurationLoader; | ||
use KevinGH\Box\Console\ConfigurationLocator; | ||
use Psr\Log\LogLevel; | ||
use RuntimeException; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Logger\ConsoleLogger; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @private | ||
*/ | ||
final class ComposerVendorDir extends ComposerCommand | ||
{ | ||
public function getConfiguration(): Configuration | ||
{ | ||
$parentConfig = parent::getConfiguration(); | ||
|
||
return new Configuration( | ||
'composer:vendor-dir', | ||
'🎵 Shows the Composer vendor-dir configured', | ||
<<<'HELP' | ||
The <info>%command.name%</info> command will look for the Composer binary (in the system if not configured | ||
in the configuration file) and print the vendor-dir found. | ||
HELP, | ||
$parentConfig->getArguments(), | ||
$parentConfig->getOptions(), | ||
); | ||
} | ||
|
||
protected function orchestrate(ComposerOrchestrator $composerOrchestrator, IO $io): int | ||
{ | ||
$io->writeln($composerOrchestrator->getVendorDir()); | ||
|
||
return ExitCode::SUCCESS; | ||
} | ||
} |