To run the Commerce application, the following actions are implemented in pub/index.php:
The bootstrap object uses the following algorithm to run the Commerce application:
Initializes the error handler.
Creates the object manager and basic shared services that are used everywhere and are affected by the environment. The environment parameters are injected properly into these objects.
Asserts that maintenance mode is not enabled; otherwise, terminates.
Asserts that the Commerce application is installed; otherwise, terminates.
Starts the Commerce application.
Any uncaught exception during application launch is automatically passed back to Commerce in the catchException()
method which you can use to handle the exception. The latter must return either true
or false
:
true
: Commerce handled exception successfully. No need to do anything else.false
: (or any other empty result) Commerce did not handle the exception. The bootstrap object performs the default exception-handling subroutine.Sends the response provided by the application object.
The assertions that the Commerce application is installed and not in maintenance mode is the default behavior of the \Magento\Framework\App\Bootstrap
class. You can modify it using an entry point script when creating the bootstrap object.
Sample entry point script that modifies the bootstrap object:
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = true; // default false
$params[Bootstrap::PARAM_REQUIRE_IS_INSTALLED] = false; // default true
$bootstrap = Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);
The bootstrap object specifies how the Commerce application handles uncaught exceptions as follows:
1
We have the following entry point applications (that is, applications defined by Commerce that are used by the web server as a directory index):
\Magento\Framework\App\Http operates as follows:
Determines the application area.
Starts the front controller and routing systems in order to find and execute a controller action.
Uses an HTTP response object to return result obtained from the controller action.
Error handling (in the following priority order):
\Magento\Framework\App\StaticResource is an application for retrieving static resources (for example, CSS, JavaScript, and images). It postpones any actions with a static resource until the resource is requested.
The entry point for static view files is not used in production mode to avoid potential exploits on the server. In production mode, the Commerce application expects that all necessary resources exist in the <your Commerce install dir>/pub/static
directory.
In default or developer mode, a request for a non-existent static resource is redirected to the static entry point according to the rewrite rules specified by the appropriate .htaccess
.
When the request is redirected to the entry point, the Commerce application parses the requested URL based on retrieved parameters and finds the requested resource.
In developer mode, the content of the file is returned so that every time the resource is requested, the returned content is up to date.
In default mode, the retrieved resource is published so it is accessible by the previously requested URL.
All future requests for the static resource are processed by the server the same as static files; that is, without involving the entry point. If it is necessary to synchronize published files with original ones, the pub/static
directory should be removed; as a result, files are automatically republished with the next request.
Magento\MediaStorage\App\Media retrieves media resources (that is, any files uploaded to media storage) from the database. It is used whenever the database is configured as a media storage.
\Magento\Core\App\Media
attempts to find the media file in the configured database storage and write it into the pub/static
directory, then return its contents. On error, it returns an HTTP 404 (Not Found) status code in the header with no contents.