From 430134864642346498631ad562765d69599d6b39 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 20 Oct 2014 11:14:41 -0500 Subject: [PATCH] Large refactor of HTTP and Console stack. --- app/Console/{ => Commands}/InspireCommand.php | 2 +- app/Console/Kernel.php | 41 ++++++++ app/Http/Kernel.php | 54 +++++++++++ app/Providers/AppServiceProvider.php | 53 ---------- app/Providers/ArtisanServiceProvider.php | 4 +- app/Providers/ErrorServiceProvider.php | 40 -------- app/Providers/RouteServiceProvider.php | 19 ++-- artisan | 25 +---- bootstrap/app.php | 50 ++++++++++ bootstrap/autoload.php | 16 ---- bootstrap/environment.php | 36 ------- bootstrap/paths.php | 96 ------------------- bootstrap/start.php | 69 ------------- config/app.php | 2 - config/compile.php | 2 - phpunit.xml | 6 +- public/index.php | 8 +- tests/ExampleTest.php | 4 +- tests/TestCase.php | 8 +- 19 files changed, 179 insertions(+), 356 deletions(-) rename app/Console/{ => Commands}/InspireCommand.php (94%) create mode 100644 app/Console/Kernel.php create mode 100644 app/Http/Kernel.php delete mode 100644 app/Providers/AppServiceProvider.php delete mode 100644 app/Providers/ErrorServiceProvider.php create mode 100644 bootstrap/app.php delete mode 100644 bootstrap/environment.php delete mode 100644 bootstrap/paths.php delete mode 100644 bootstrap/start.php diff --git a/app/Console/InspireCommand.php b/app/Console/Commands/InspireCommand.php similarity index 94% rename from app/Console/InspireCommand.php rename to app/Console/Commands/InspireCommand.php index 326caa1d..2d5b09b7 100644 --- a/app/Console/InspireCommand.php +++ b/app/Console/Commands/InspireCommand.php @@ -1,4 +1,4 @@ -writeln((string) $e); + + return 1; + } + } + +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php new file mode 100644 index 00000000..796cda8c --- /dev/null +++ b/app/Http/Kernel.php @@ -0,0 +1,54 @@ + 'App\Http\Middleware\AuthMiddleware', - 'auth.basic' => 'App\Http\Middleware\BasicAuthMiddleware', - 'csrf' => 'App\Http\Middleware\CsrfMiddleware', - 'guest' => 'App\Http\Middleware\GuestMiddleware', - ]; - - /** - * The application's middleware stack. - * - * @var array - */ - protected $stack = [ - 'App\Http\Middleware\MaintenanceMiddleware', - 'Illuminate\Cookie\Middleware\Guard', - 'Illuminate\Cookie\Middleware\Queue', - 'Illuminate\Session\Middleware\Reader', - 'Illuminate\Session\Middleware\Writer', - 'Illuminate\View\Middleware\ErrorBinder', - 'App\Http\Middleware\CsrfMiddleware', - ]; - - /** - * Build the application stack based on the provider properties. - * - * @return void - */ - public function stack() - { - $this->app->stack(function(Stack $stack, Router $router) - { - return $stack - ->middleware($this->stack)->then(function($request) use ($router) - { - return $router->dispatch($request); - }); - }); - } - -} diff --git a/app/Providers/ArtisanServiceProvider.php b/app/Providers/ArtisanServiceProvider.php index 97c67f5b..6b2e39e1 100644 --- a/app/Providers/ArtisanServiceProvider.php +++ b/app/Providers/ArtisanServiceProvider.php @@ -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']; } } diff --git a/app/Providers/ErrorServiceProvider.php b/app/Providers/ErrorServiceProvider.php deleted file mode 100644 index aa83fc1d..00000000 --- a/app/Providers/ErrorServiceProvider.php +++ /dev/null @@ -1,40 +0,0 @@ -error(function(Exception $e) use ($log) - { - $log->error($e); - }); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - // - } - -} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index cb82503a..e1fa99c0 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -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. * diff --git a/artisan b/artisan index 5c408ad8..ae8bdafe 100755 --- a/artisan +++ b/artisan @@ -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); diff --git a/bootstrap/app.php b/bootstrap/app.php new file mode 100644 index 00000000..c696f3bf --- /dev/null +++ b/bootstrap/app.php @@ -0,0 +1,50 @@ +bind( + 'Illuminate\Contracts\Http\Kernel', + 'App\Http\Kernel' +); + +$app->bind( + 'Illuminate\Contracts\Console\Kernel', + 'App\Console\Kernel' +); + +/* +|-------------------------------------------------------------------------- +| Return The Application +|-------------------------------------------------------------------------- +| +| This script returns the application instance. The instance is given to +| the calling script so we can separate the building of the instances +| from the actual running of the application and sending responses. +| +*/ + +return $app; diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index f75601b2..f2a9d567 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -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); -} diff --git a/bootstrap/environment.php b/bootstrap/environment.php deleted file mode 100644 index bb77b5fd..00000000 --- a/bootstrap/environment.php +++ /dev/null @@ -1,36 +0,0 @@ -detectEnvironment(function() -{ - return getenv('APP_ENV') ?: 'production'; -}); diff --git a/bootstrap/paths.php b/bootstrap/paths.php deleted file mode 100644 index 9d9d14bc..00000000 --- a/bootstrap/paths.php +++ /dev/null @@ -1,96 +0,0 @@ - __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', - -]; diff --git a/bootstrap/start.php b/bootstrap/start.php deleted file mode 100644 index 949f2e5f..00000000 --- a/bootstrap/start.php +++ /dev/null @@ -1,69 +0,0 @@ -bindInstallPaths(require __DIR__.'/paths.php'); - -/* -|-------------------------------------------------------------------------- -| Load 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. -| -*/ - -$framework = $app['path.base']. - '/vendor/laravel/framework/src'; - -require $framework.'/Illuminate/Foundation/start.php'; - -/* -|-------------------------------------------------------------------------- -| Return The Application -|-------------------------------------------------------------------------- -| -| This script returns the application instance. The instance is given to -| the calling script so we can separate the building of the instances -| from the actual running of the application and sending responses. -| -*/ - -return $app; diff --git a/config/app.php b/config/app.php index cc17a05a..97a53115 100644 --- a/config/app.php +++ b/config/app.php @@ -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', diff --git a/config/compile.php b/config/compile.php index c922bf70..c3ef5e3b 100644 --- a/config/compile.php +++ b/config/compile.php @@ -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', diff --git a/phpunit.xml b/phpunit.xml index 8745dfab..b22af540 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,11 +8,13 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" -> + syntaxCheck="false"> ./tests/ + + + diff --git a/public/index.php b/public/index.php index f08822d9..31fd0003 100644 --- a/public/index.php +++ b/public/index.php @@ -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(); diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index 62387de1..1ea4acd2 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -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()); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 2d342939..0d377197 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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'; } }