Skip to content

Commit

Permalink
add easy methods for handling requests and artisan commands
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 2, 2023
1 parent 7304187 commit 82067b6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Container\Container;
use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Contracts\Foundation\CachesConfiguration;
use Illuminate\Contracts\Foundation\CachesRoutes;
Expand All @@ -23,6 +24,9 @@
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use RuntimeException;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Symfony\Component\HttpKernel\Exception\HttpException;
Expand Down Expand Up @@ -1079,6 +1083,41 @@ public function handle(SymfonyRequest $request, int $type = self::MAIN_REQUEST,
return $this[HttpKernelContract::class]->handle(Request::createFromBase($request));
}

/**
* Handle the incoming HTTP request and send the response to the browser.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
public function handleRequest(Request $request)
{
$kernel = $this->make(HttpKernelContract::class);

$response = $kernel->handle($request)->send();

$kernel->terminate($request, $response);
}

/**
* Handle the incoming Artisan command.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @return int
*/
public function handleCommand(InputInterface $input)
{
$kernel = $this->make(ConsoleKernelContract::class);

$status = $kernel->handle(
$input ?: new ArgvInput,
new ConsoleOutput
);

$kernel->terminate($input, $status);

return $status;
}

/**
* Determine if middleware has been disabled for the application.
*
Expand Down

0 comments on commit 82067b6

Please sign in to comment.