cancel
Showing results for 
Search instead for 
Did you mean: 

Altering M2 bootstrap initial parameters

Altering M2 bootstrap initial parameters

In index.php, there is a call to instantiate the Magento\Framework\App\Bootstrap object with $_SERVER as the initial parameters.

 

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

 

We had a hack in the index.php (based on this gist) so that we could use the same URL for multiple stores and show different content based on the cookie settings.

 

$params = $_SERVER;
if (isset($_COOKIE[\Magento\Store\Model\StoreCookieManager::COOKIE_NAME])) {
    $storeCode = $_COOKIE[\Magento\Store\Model\StoreCookieManager::COOKIE_NAME];
}
if (isset($_GET[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME])) {
    $storeCode = $_GET[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME];
}
if (isset($storeCode)) {
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $storeCode;
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

 

The problem is that we're now shifting to the Magento Commerce Cloud servers and the index.php is regenerated on build, so we can't rely on a change to the index.php anymore.

I've tried creating a module which adds a DI preference for my own version of the Bootstrap class (which contains the above code in the create method) instead of the Magento version, but this doesn't appear to be working - I suspect because it might be too early in the process for interceptors to be in play.

 

Does anyone have any insight into how to overcome this issue?

 

(cross-posted from https://magento.stackexchange.com/q/224441/35344)

Yoda aka indefinitedevil
5 REPLIES 5

Re: Altering M2 bootstrap initial parameters

Hello @indefinitedevil

 

you can do the same thing into app/bootstrap.php

 

It is not the good solution but i am suggesting.

 

Hope it will help you,  it will work mark as a solution or give kudos.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Altering M2 bootstrap initial parameters

How does this help with the fact it's on cloud and app/bootstrap.php is similarly generated by the build process?

 

If it were a normal Magento deployment, this would not be an issue, but all of the standard Magento files are added by the build process rather than being part of the repo.

Yoda aka indefinitedevil

Re: Altering M2 bootstrap initial parameters

Hello,

 

if you push that changes into branch i don't think it will update via the cloud.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Altering M2 bootstrap initial parameters

@Sunil Patel Having checked by trying a deployment to the Magento Commerce (Cloud) servers with an explicitly altered app/bootstrap.php I can confirm that the app/bootstrap.php is overridden by the build process so that is also not a viable solution.

Yoda aka indefinitedevil

Re: Altering M2 bootstrap initial parameters

Hello @indefinitedevil

 

what if you create patch for that

 

http://devdocs.magento.com/guides/v2.0/cloud/project/project-patch.html


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer