-
Notifications
You must be signed in to change notification settings - Fork 62
/
stub.php
61 lines (44 loc) · 1.93 KB
/
stub.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
51
52
53
54
55
56
57
58
59
60
61
<?php
use Drutiny\Kernel;
use Symfony\Component\Console\Input\ArgvInput;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}
list($major, $minor, ) = explode('.', phpversion());
// Identify PHP versions lower than PHP 7.4.
if ($major < 7 || ($major == 7 && $minor < 4)) {
echo "ERROR: Application requires PHP 7.4 or later. Currently running: ".phpversion()."\n";
exit;
}
set_time_limit(0);
$project_dir = Phar::running() ?: getcwd();
// Drutiny is installed as a composer dependency and the project directory
// is further up.
if (preg_match('#^(.*)/vendor/drutiny/drutiny$#', __DIR__, $matches)) {
$project_dir = $matches[1];
}
define('DRUTINY_LIB', $project_dir);
require DRUTINY_LIB.'/vendor/autoload.php';
$version_files = [DRUTINY_LIB.'/VERSION', dirname(__DIR__).'/VERSION'];
// Load in the version if it can be found.
$versions = array_filter(array_map(function($file) {
return file_exists($file) ? file_get_contents($file) : FALSE;
}, $version_files));
// Load from git.
if (empty($versions) && file_exists(DRUTINY_LIB . '/.git') && $git_bin = exec('which git')) {
$versions[] = exec(sprintf('%s -C %s branch --show-current', $git_bin, DRUTINY_LIB)) . '-dev';
}
// Fallback option.
$versions[] = 'dev';
$suffix = '';
if (file_exists(DRUTINY_LIB.'/BUILD_DATETIME')) {
$date = unserialize(file_get_contents(DRUTINY_LIB.'/BUILD_DATETIME'));
$suffix = $date->format(' (Y-m-d H:i:s T)');
}
$installed = require DRUTINY_LIB . '/vendor/composer/installed.php';
$environment = $installed['root']['dev'] || Phar::running() ? 'dev' : 'production';
$kernel = new Kernel($environment, reset($versions).$suffix);
$kernel->getApplication()->run(
// If this is a phar file, then run the extraction command. Otherwise behave as normal.
Phar::running() ? new ArgvInput([$_SERVER['argv'][0], 'phar-extract', '-vvv']) : null
);