-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBeginCommand.php
50 lines (42 loc) · 1.81 KB
/
BeginCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php declare(strict_types=1);
namespace PhpTuf\ComposerStagerConsole\Console\Command;
use PhpTuf\ComposerStager\API\Core\BeginnerInterface;
use PhpTuf\ComposerStager\API\Exception\ExceptionInterface;
use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface;
use PhpTuf\ComposerStagerConsole\Console\Output\ProcessOutputCallback;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/** @internal */
final class BeginCommand extends AbstractCommand
{
private const NAME = 'begin';
public function __construct(private readonly BeginnerInterface $beginner, PathFactoryInterface $pathFactory)
{
parent::__construct(self::NAME, $pathFactory);
}
protected function configure(): void
{
$this->setDescription('Begins the staging process by copying the active directory to the staging directory');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// ---------------------------------------------------------------------
// (!) Here is the substance of the example. Invoke the Composer Stager
// API; be sure to catch the appropriate exceptions.
// ---------------------------------------------------------------------
try {
$this->beginner->begin(
$this->getActiveDir(),
$this->getStagingDir(),
null,
new ProcessOutputCallback($input, $output),
);
return self::SUCCESS;
} catch (ExceptionInterface $e) {
// Error-handling specifics may differ for your application. This
// example outputs errors to the terminal.
$output->writeln("<error>{$e->getMessage()}</error>");
return self::FAILURE;
}
}
}