SetRequestForConsole.php
TLDR
This file contains the SetRequestForConsole
class, which is responsible for bootstrapping the given application by creating a new request object with the necessary server settings for a console application.
Classes
SetRequestForConsole
This class is responsible for bootstrapping the given application by creating a new request object with the necessary server settings for a console application. It has the following method:
bootstrap
This method takes an instance of the Application
class as a parameter and initializes the server settings for the console request. It extracts the URI from the configuration and parses it to get the components. It then updates the $_SERVER
array with the necessary path settings if provided in the URI components. Finally, it creates a new Request
object with the updated server settings and stores it in the application instance.
<?php
namespace Illuminate\Foundation\Bootstrap;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
class SetRequestForConsole
{
/**
* Bootstrap the given application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function bootstrap(Application $app)
{
$uri = $app->make('config')->get('app.url', 'http://localhost');
$components = parse_url($uri);
$server = $_SERVER;
if (isset($components['path'])) {
$server = array_merge($server, [
'SCRIPT_FILENAME' => $components['path'],
'SCRIPT_NAME' => $components['path'],
]);
}
$app->instance('request', Request::create(
$uri, 'GET', [], [], [], $server
));
}
}