Skip to content

Commit 45bd46f

Browse files
authored
refactors cli boostrap (#288)
relies on composer runtime api when possibile and provides a fallback
1 parent 5b5edfb commit 45bd46f

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

bin-stub/phparkitect

+21-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@ declare(strict_types=1);
44

55
use Arkitect\CLI\PhpArkitectApplication;
66

7-
foreach (array(__DIR__ . '/../../../autoload.php', __DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
8-
if (file_exists($file)) {
9-
define('PHPARKITECT_COMPOSER_INSTALL', $file);
10-
11-
break;
7+
// $_composer_autoload_path is set by composer (available from composer 2.2)
8+
// https://getcomposer.org/doc/articles/vendor-binaries.md#finding-the-composer-autoloader-from-a-binary
9+
if (isset($_composer_autoload_path)) {
10+
11+
define('PHPARKITECT_COMPOSER_INSTALL', $_composer_autoload_path);
12+
13+
} else {
14+
// if $_composer_autoload_path is not set, we will try to find the autoload.php file
15+
// guessing the location of the phparkitect binary
16+
// ps: e2e tests are run from the bin-stub dir and needs that
17+
$possible_autoload_locations = [
18+
__DIR__ . '/../../autoload.php', // inside vendor dir like "vendor/phparkitect/bin"
19+
__DIR__ . '/../vendor/autoload.php', // first level project dir like "bin"
20+
__DIR__ . '/vendor/autoload.php' // project root
21+
];
22+
23+
foreach ($possible_autoload_locations as $path) {
24+
if (file_exists($path)) {
25+
define('PHPARKITECT_COMPOSER_INSTALL', $path);
26+
break;
27+
}
1228
}
1329
}
1430

15-
unset($file);
16-
1731
if (!defined('PHPARKITECT_COMPOSER_INSTALL')) {
1832
fwrite(
1933
STDERR,

0 commit comments

Comments
 (0)