-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApplication.php
More file actions
114 lines (99 loc) · 3.47 KB
/
Application.php
File metadata and controls
114 lines (99 loc) · 3.47 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Hypernode\Deploy;
use Composer\InstalledVersions;
use Deployer\Console\Application as ConsoleApplication;
use DI\Container;
use DI\ContainerBuilder;
use Exception;
use Hypernode\Deploy\Stdlib\ClassFinder;
use InvalidArgumentException;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use function Sentry\init as sentryInit;
class Application
{
private const APP_LOGO = <<<NAME
__ __ __ ____ __
/ / / /_ ______ ___ _________ ____ ____/ /__ / __ \___ ____ / /___ __ __
/ /_/ / / / / __ \/ _ \/ ___/ __ \/ __ \/ __ / _ \ / / / / _ \/ __ \/ / __ \/ / / /
/ __ / /_/ / /_/ / __/ / / / / / /_/ / /_/ / __/ / /_/ / __/ /_/ / / /_/ / /_/ /
/_/ /_/\__, / .___/\___/_/ /_/ /_/\____/\__,_/\___/ /_____/\___/ .___/_/\____/\__, /
/____/_/ /_/ /____/
Deployer version: %s
Deployer Recipe version: %s
NAME;
/**
* Run application
*
* @throws Exception
*/
public function run(): int
{
sentryInit([
'dsn' => 'https://85e2b396851b4fcc9cc5df626b974687@sentry.hipex.cloud/10',
'release' => $this->getVersion()
]);
$container = $this->createDiContainer();
$application = new ConsoleApplication();
$application->setName(
sprintf(
self::APP_LOGO,
InstalledVersions::getVersion('deployer/deployer'),
InstalledVersions::getVersion('deployer/recipes')
)
);
$application->setVersion('Version: ' . $this->getVersion());
$this->addCommands($container, $application);
$this->registerTwigLoader($container);
return $application->run(
$container->get(InputInterface::class),
$container->get(OutputInterface::class)
);
}
/**
* @throws InvalidArgumentException
* @throws Exception
*/
private function createDiContainer(): Container
{
$builder = new ContainerBuilder();
$builder->useAutowiring(true);
$builder->useAnnotations(true);
$builder->addDefinitions(Di\ConsoleDefinition::getDefinition());
$builder->addDefinitions([
'version' => $this->getVersion(),
]);
return $builder->build();
}
/**
* @param Container $container
*/
private function registerTwigLoader(Container $container): void
{
$loader = new FilesystemLoader(__DIR__ . '/Resource/template');
$twig = new Environment($loader);
$container->set(Environment::class, $twig);
}
private function getVersion(): string
{
return '@git_version@ @build_datetime@';
}
/**
* @throws InvalidArgumentException
*/
private function addCommands(ContainerInterface $container, ConsoleApplication $application): void
{
$finder = new ClassFinder(__NAMESPACE__ . '\\Command');
$finder->in(__DIR__ . DIRECTORY_SEPARATOR . 'Command');
$finder->subclassOff(Command::class);
foreach ($finder as $class) {
/** @var Command $command */
$command = $container->get($class);
$application->add($command);
}
}
}