Commit 43013486 authored by Taylor Otwell's avatar Taylor Otwell

Large refactor of HTTP and Console stack.

parent 834cb753
<?php namespace App\Console;
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
......
<?php namespace App\Console;
use Exception;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel {
/**
* The bootstrap classes for the application.
*
* @return void
*/
protected $bootstrappers = [
'Illuminate\Foundation\Bootstrap\LoadEnvironment',
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
'Illuminate\Foundation\Bootstrap\RegisterProviders',
'Illuminate\Foundation\Bootstrap\BootProviders',
];
/**
* Run the console application.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return int
*/
public function handle($input, $output = null)
{
try
{
return parent::handle($input, $output);
}
catch (Exception $e)
{
$output->writeln((string) $e);
return 1;
}
}
}
<?php namespace App\Providers;
<?php namespace App\Http;
use Illuminate\Routing\Router;
use Illuminate\Routing\Stack\Builder as Stack;
use Illuminate\Foundation\Support\Providers\AppServiceProvider as ServiceProvider;
use Exception;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class AppServiceProvider extends ServiceProvider {
class Kernel extends HttpKernel {
/**
* All of the application's route middleware keys.
* The bootstrap classes for the application.
*
* @var array
* @return void
*/
protected $middleware = [
'auth' => 'App\Http\Middleware\AuthMiddleware',
'auth.basic' => 'App\Http\Middleware\BasicAuthMiddleware',
'csrf' => 'App\Http\Middleware\CsrfMiddleware',
'guest' => 'App\Http\Middleware\GuestMiddleware',
protected $bootstrappers = [
'Illuminate\Foundation\Bootstrap\LoadEnvironment',
'Illuminate\Foundation\Bootstrap\HandleExceptions',
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
'Illuminate\Foundation\Bootstrap\RegisterProviders',
'Illuminate\Foundation\Bootstrap\BootProviders',
];
/**
* The application's middleware stack.
* The application's HTTP middleware stack.
*
* @var array
*/
......@@ -34,20 +34,21 @@ class AppServiceProvider extends ServiceProvider {
];
/**
* Build the application stack based on the provider properties.
* Handle an incoming HTTP request.
*
* @return void
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function stack()
public function handle($request)
{
$this->app->stack(function(Stack $stack, Router $router)
try
{
return $stack
->middleware($this->stack)->then(function($request) use ($router)
return parent::handle($request);
}
catch (Exception $e)
{
return $router->dispatch($request);
});
});
throw $e;
}
}
}
......@@ -19,7 +19,7 @@ class ArtisanServiceProvider extends ServiceProvider {
*/
public function register()
{
$this->commands('App\Console\InspireCommand');
$this->commands('App\Console\Commands\InspireCommand');
}
/**
......@@ -29,7 +29,7 @@ class ArtisanServiceProvider extends ServiceProvider {
*/
public function provides()
{
return ['App\Console\InspireCommand'];
return ['App\Console\Commands\InspireCommand'];
}
}
<?php namespace App\Providers;
use Exception;
use Illuminate\Contracts\Logging\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Exception\Handler;
class ErrorServiceProvider extends ServiceProvider {
/**
* Register any error handlers.
*
* @param Handler $handler
* @param Log $log
* @return void
*/
public function boot(Handler $handler, Log $log)
{
// Here you may handle any errors that occur in your application, including
// logging them or displaying custom views for specific errors. You may
// even register several error handlers to handle different types of
// exceptions. If nothing is returned, the default error view is
// shown, which includes a detailed stack trace during debug.
$handler->error(function(Exception $e) use ($log)
{
$log->error($e);
});
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}
......@@ -5,13 +5,6 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi
class RouteServiceProvider extends ServiceProvider {
/**
* The root namespace to assume when generating URLs to actions.
*
* @var string
*/
protected $rootUrlNamespace = 'App\Http\Controllers';
/**
* The controllers to scan for route annotations.
*
......@@ -23,6 +16,18 @@ class RouteServiceProvider extends ServiceProvider {
'App\Http\Controllers\Auth\PasswordController',
];
/**
* All of the application's route middleware keys.
*
* @var array
*/
protected $middleware = [
'auth' => 'App\Http\Middleware\AuthMiddleware',
'auth.basic' => 'App\Http\Middleware\BasicAuthMiddleware',
'csrf' => 'App\Http\Middleware\CsrfMiddleware',
'guest' => 'App\Http\Middleware\GuestMiddleware',
];
/**
* Called before routes are registered.
*
......
......@@ -27,23 +27,7 @@ require __DIR__.'/bootstrap/autoload.php';
|
*/
$app = require_once __DIR__.'/bootstrap/start.php';
/*
|--------------------------------------------------------------------------
| Load The Artisan Console Application
|--------------------------------------------------------------------------
|
| We'll need to run the script to load and return the Artisan console
| application. We keep this in its own script so that we will load
| the console application independent of running commands which
| will allow us to fire commands from Routes when we want to.
|
*/
$app->setRequestForConsoleEnvironment();
$artisan = Illuminate\Console\Application::start($app);
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
......@@ -56,7 +40,10 @@ $artisan = Illuminate\Console\Application::start($app);
|
*/
$status = $artisan->run();
$status = $app->make('Illuminate\Contracts\Console\Kernel')->handle(
new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
/*
|--------------------------------------------------------------------------
......@@ -69,6 +56,4 @@ $status = $artisan->run();
|
*/
$app->shutdown();
exit($status);
......@@ -11,49 +11,30 @@
|
*/
$app = new Illuminate\Foundation\Application;
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/..')
);
/*
|--------------------------------------------------------------------------
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name for the host that matches a
| given environment, then we will automatically detect it for you.
|
*/
require __DIR__.'/environment.php';
/*
|--------------------------------------------------------------------------
| Bind Paths
|--------------------------------------------------------------------------
|
| Here we are binding the paths configured in paths.php to the app. You
| should not be changing these here. If you need to change these you
| may do so within the paths.php file and they will be bound here.
|
*/
$app->bindInstallPaths(require __DIR__.'/paths.php');
/*
|--------------------------------------------------------------------------
| Load The Application
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load this Illuminate application. We will keep this in a
| separate location so we can isolate the creation of an application
| from the actual running of the application with a given request.
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$framework = $app['path.base'].
'/vendor/laravel/framework/src';
$app->bind(
'Illuminate\Contracts\Http\Kernel',
'App\Http\Kernel'
);
require $framework.'/Illuminate/Foundation/start.php';
$app->bind(
'Illuminate\Contracts\Console\Kernel',
'App\Console\Kernel'
);
/*
|--------------------------------------------------------------------------
......
......@@ -33,19 +33,3 @@ if (file_exists($compiledPath))
{
require $compiledPath;
}
/*
|--------------------------------------------------------------------------
| Register The Workbench Loaders
|--------------------------------------------------------------------------
|
| The Laravel workbench provides a convenient place to develop packages
| when working locally. However we will need to load in the Composer
| auto-load files for the packages so that these can be used here.
|
*/
if (is_dir($workbench = __DIR__.'/../workbench'))
{
Illuminate\Workbench\Starter::start($workbench);
}
<?php
/*
|--------------------------------------------------------------------------
| Load Environment Variables
|--------------------------------------------------------------------------
|
| Next we will load the environment variables for the application which
| are stored in the ".env" file. These variables will be loaded into
| the $_ENV and "putenv" facilities of PHP so they stay available.
|
*/
if (file_exists(__DIR__.'/../.env'))
{
Dotenv::load(__DIR__.'/../');
//Dotenv::required('APP_ENV');
}
/*
|--------------------------------------------------------------------------
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you may simply return the environment from the Closure. We will
| assume we are using the "APP_ENV" variable for this environment.
|
*/
$env = $app->detectEnvironment(function()
{
return getenv('APP_ENV') ?: 'production';
});
<?php
return [
/*
|--------------------------------------------------------------------------
| Application Path
|--------------------------------------------------------------------------
|
| Here we just defined the path to the application directory. Most likely
| you will never need to change this value as the default setup should
| work perfectly fine for the vast majority of all our applications.
|
*/
'app' => __DIR__.'/../app',
/*
|--------------------------------------------------------------------------
| Base Path
|--------------------------------------------------------------------------
|
| The base path is the root of the Laravel installation. Most likely you
| will not need to change this value. But, if for some wild reason it
| is necessary you will do so here, just proceed with some caution.
|
*/
'base' => __DIR__.'/..',
/*
|--------------------------------------------------------------------------
| Configuration Path
|--------------------------------------------------------------------------
|
| This path is used by the configuration loader to load the application
| configuration files. In general, you should'nt need to change this
| value; however, you can theoretically change the path from here.
|
*/
'config' => __DIR__.'/../config',
/*
|--------------------------------------------------------------------------
| Database Path
|--------------------------------------------------------------------------
|
| This path is used by the migration generator and migration runner to
| know where to place your fresh database migration classes. You're
| free to modify the path but you probably will not ever need to.
|
*/
'database' => __DIR__.'/../database',
/*
|--------------------------------------------------------------------------
| Language Path
|--------------------------------------------------------------------------
|
| This path is used by the language file loader to load your application
| language files. The purpose of these files is to store your strings
| that are translated into other languages for views, e-mails, etc.
|
*/
'lang' => __DIR__.'/../resources/lang',
/*
|--------------------------------------------------------------------------
| Public Path
|--------------------------------------------------------------------------
|
| The public path contains the assets for your web application, such as
| your JavaScript and CSS files, and also contains the primary entry
| point for web requests into these applications from the outside.
|
*/
'public' => __DIR__.'/../public',
/*
|--------------------------------------------------------------------------
| Storage Path
|--------------------------------------------------------------------------
|
| The storage path is used by Laravel to store cached Blade views, logs
| and other pieces of information. You may modify the path here when
| you want to change the location of this directory for your apps.
|
*/
'storage' => __DIR__.'/../storage',
];
......@@ -98,9 +98,7 @@ return [
/*
* Application Service Providers...
*/
'App\Providers\AppServiceProvider',
'App\Providers\ArtisanServiceProvider',
'App\Providers\ErrorServiceProvider',
'App\Providers\EventServiceProvider',
'App\Providers\LogServiceProvider',
'App\Providers\RouteServiceProvider',
......
......@@ -15,9 +15,7 @@ return [
'files' => [
__DIR__.'/../app/Providers/AppServiceProvider.php',
__DIR__.'/../app/Providers/ArtisanServiceProvider.php',
__DIR__.'/../app/Providers/ErrorServiceProvider.php',
__DIR__.'/../app/Providers/EventServiceProvider.php',
__DIR__.'/../app/Providers/LogServiceProvider.php',
__DIR__.'/../app/Providers/RouteServiceProvider.php',
......
......@@ -8,11 +8,13 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
</php>
</phpunit>
......@@ -32,7 +32,7 @@ require __DIR__.'/../bootstrap/autoload.php';
|
*/
$app = require_once __DIR__.'/../bootstrap/start.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
......@@ -46,4 +46,8 @@ $app = require_once __DIR__.'/../bootstrap/start.php';
|
*/
$app->run();
$response = $app->make('Illuminate\Contracts\Http\Kernel')->handle(
Illuminate\Http\Request::capture()
);
$response->send();
......@@ -9,9 +9,9 @@ class ExampleTest extends TestCase {
*/
public function testBasicExample()
{
$crawler = $this->client->request('GET', '/');
$response = $this->call('GET', '/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals(200, $response->getStatusCode());
}
}
......@@ -5,15 +5,11 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase {
/**
* Creates the application.
*
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../bootstrap/start.php';
return require __DIR__.'/../bootstrap/app.php';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment