This repository has been archived by the owner on Sep 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
/
box
executable file
·98 lines (81 loc) · 2.24 KB
/
box
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
#!/usr/bin/env php
<?php
/**
* The project (or Phar) base path.
*
* @var string
*/
define('BOX_PATH', dirname(__DIR__));
if (extension_loaded('phar') && ($uri = Phar::running())) {
require "$uri/src/vendors/autoload.php";
} elseif (class_exists('Extract')) {
require __DIR__ . '/../src/vendors/autoload.php';
} else {
loadComposerClassloader(realpath($_SERVER['argv'][0]));
}
$app = new KevinGH\Box\Application();
$app->run();
/**
* Finds the Composer autoloader and returns it.
*
* @param null $dir The starting directory.
* @param int $skip The number of occurrences to skip.
*
* @return Composer\Autoload\ClassLoader The class loader.
*
* @throws RuntimeException If the loader could not be loaded.
*/
function loadComposerClassloader($dir = null, $skip = 0)
{
$up = $dir;
$skips = 0;
do {
$dir = $up;
if (file_exists("$dir/composer.json")) {
if ($skip > $skips) {
$skips++;
continue;
}
$path = realpath("$dir/composer.json");
}
} while ($dir !== ($up = dirname($dir)));
if (empty($path)) {
throw new RuntimeException(
'The composer.json file could not be found.'
);
}
if (false === ($json = file_get_contents($path))) {
throw new RuntimeException(
sprintf(
'The file "%s" could not be read.',
$path
)
);
}
$json = json_decode($json);
if (JSON_ERROR_NONE !== ($code = json_last_error())) {
throw new RuntimeException(
sprintf(
'The file "%s" could not be parsed [%d].',
$path,
$code
)
);
}
$path = dirname($path);
if (isset($json->config) && isset($json->config->{'vendor-dir'})) {
$path .= DIRECTORY_SEPARATOR . $json->config->{'vendor-dir'};
} else {
$path .= DIRECTORY_SEPARATOR . 'vendor';
}
$path .= DIRECTORY_SEPARATOR . 'autoload.php';
if (false === file_exists($path)) {
throw new RuntimeException(
sprintf(
'The Composer class loader "%s" could not be found.',
$path
)
);
}
return include $path;
}