Magento 2 has, infamously, two
index.php files. The first is in the root folder
the second is in a
A Magento developer needs to chose which file they're going to point to as their webroot. This creates some problems related to file paths and URL paths. Magento solves this by bootstrapping index.php like this
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
pub/index.php like this
$params = $_SERVER; $params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [ DirectoryList::PUB => [DirectoryList::URL_PATH => ''], DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'], DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'], DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'], ]; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
i.e. -- Magento adds values to the array that's the second argument to
This solution, however, creates another problem. The Magento CLI also need to bootstrap an enviornment. It seems to do so here
#File: vendor/magento/framework/Console/Cli.php $bootstrapParam = new ComplexParameter(self::INPUT_KEY_BOOTSTRAP); $params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER); $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; $bootstrap = Bootstrap::create(BP, $params);
There's (Seemingly?) no opportunity to add additional parameters, which means the CLI console will always think you're running from the main index file, and any code that needs the
DirectoryList params may not function correctly.
Is there any way (short of editing
Cli.php directly or replacing it via a composer autoload) to inject these parameters into the CLI bootstrap? Looking for known solutions, not theories on what might work. Thank you!