diff --git a/bin-stub/phparkitect b/bin-stub/phparkitect index ea1c8321..6c09133c 100755 --- a/bin-stub/phparkitect +++ b/bin-stub/phparkitect @@ -4,16 +4,30 @@ declare(strict_types=1); use Arkitect\CLI\PhpArkitectApplication; -foreach (array(__DIR__ . '/../../../autoload.php', __DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) { - if (file_exists($file)) { - define('PHPARKITECT_COMPOSER_INSTALL', $file); - - break; +// $_composer_autoload_path is set by composer (available from composer 2.2) +// https://getcomposer.org/doc/articles/vendor-binaries.md#finding-the-composer-autoloader-from-a-binary +if (isset($_composer_autoload_path)) { + + define('PHPARKITECT_COMPOSER_INSTALL', $_composer_autoload_path); + +} else { +// if $_composer_autoload_path is not set, we will try to find the autoload.php file +// guessing the location of the phparkitect binary +// ps: e2e tests are run from the bin-stub dir and needs that + $possible_autoload_locations = [ + __DIR__ . '/../../autoload.php', // inside vendor dir like "vendor/phparkitect/bin" + __DIR__ . '/../vendor/autoload.php', // first level project dir like "bin" + __DIR__ . '/vendor/autoload.php' // project root + ]; + + foreach ($possible_autoload_locations as $path) { + if (file_exists($path)) { + define('PHPARKITECT_COMPOSER_INSTALL', $path); + break; + } } } -unset($file); - if (!defined('PHPARKITECT_COMPOSER_INSTALL')) { fwrite( STDERR,