-
Notifications
You must be signed in to change notification settings - Fork 34
/
web
executable file
·51 lines (40 loc) · 1.71 KB
/
web
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
#!/usr/bin/env php
<?php
if (php_sapi_name() != 'cli') {
throw new RuntimeException("This script can only be called from the command line.");
}
// make sure we are in the correct directory
chdir(__DIR__);
require 'bootstrap.php';
use Laminas\Cli\ApplicationProvisioner;
use Laminas\Cli\ApplicationFactory;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
$app = (new ApplicationFactory())();
$definition = $app->getDefinition();
$output = new ConsoleOutput();
$containerNotFoundMessage = '';
$input = new ArgvInput();
try {
$input->bind($definition);
} catch (\Symfony\Component\Console\Exception\RuntimeException $exception) {
// Ignore validation issues as we did not yet have the commands definition
// As we only need the `--container` option, we are good to go until it is passed *before* the first command argument
// Symfony parses the `argv` in its direct order and raises an error when more arguments or options are passed
// than described by the default definition.
}
try {
$serviceManager = ConsoleRunner::getServiceManager();
$app = (new ApplicationProvisioner())($app, $serviceManager);
} catch (RuntimeException | InvalidArgumentException $exception) {
// Usage information provided by the `ContainerResolver` should be passed to the CLI output
$containerNotFoundMessage = sprintf('<error>%s</error>', $exception->getMessage());
}
// By running the app even if its not provisioned allows symfony/console to report problems
// and/or display available options (like `--container`)
$exitCode = $app->run(null, $output);
if ($containerNotFoundMessage) {
$output->writeln($containerNotFoundMessage);
$exitCode = 255;
}
exit($exitCode);