Skip to content

Commit

Permalink
Large refactor of HTTP and Console stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 20, 2014
1 parent 834cb75 commit 4301348
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 356 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace App\Console;
<?php namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
Expand Down
41 changes: 41 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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;
}
}

}
54 changes: 54 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php namespace App\Http;

use Exception;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel {

/**
* The bootstrap classes for the application.
*
* @return void
*/
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 HTTP 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',
];

/**
* Handle an incoming HTTP request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function handle($request)
{
try
{
return parent::handle($request);
}
catch (Exception $e)
{
throw $e;
}
}

}
53 changes: 0 additions & 53 deletions app/Providers/AppServiceProvider.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Providers/ArtisanServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ArtisanServiceProvider extends ServiceProvider {
*/
public function register()
{
$this->commands('App\Console\InspireCommand');
$this->commands('App\Console\Commands\InspireCommand');
}

/**
Expand All @@ -29,7 +29,7 @@ public function register()
*/
public function provides()
{
return ['App\Console\InspireCommand'];
return ['App\Console\Commands\InspireCommand'];
}

}
40 changes: 0 additions & 40 deletions app/Providers/ErrorServiceProvider.php

This file was deleted.

19 changes: 12 additions & 7 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@

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.
*
Expand All @@ -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.
*
Expand Down
25 changes: 5 additions & 20 deletions artisan
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/*
|--------------------------------------------------------------------------
Expand All @@ -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
);

/*
|--------------------------------------------------------------------------
Expand All @@ -69,6 +56,4 @@ $status = $artisan->run();
|
*/

$app->shutdown();

exit($status);
50 changes: 50 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| 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.
|
*/

$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/..')
);

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| 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.
|
*/

$app->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;
16 changes: 0 additions & 16 deletions bootstrap/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,3 @@
{
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);

This comment has been minimized.

Copy link
@lordcoste

lordcoste Oct 22, 2014

How is autoload working for workbench packages now? Am I missing something or it just not work?

This comment has been minimized.

Copy link
@mouhsinelonly

mouhsinelonly Oct 22, 2014

i use workbench in my project how can i autoload it now

This comment has been minimized.

Copy link
@khongchi

khongchi Oct 31, 2014

maybe this is a mistake ^^;

This comment has been minimized.

Copy link
@jszobody

jszobody Nov 13, 2014

My workbenches wouldn't autoload, had to add this code back in manually. Would love to know if there's a different way L5 envisions this being handled.

}

9 comments on commit 4301348

@imade-nl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help, I would like to change the path to the public directory. Will that still be possible? Or am I writing too soon. Apologies if so.

@taylorotwell
Copy link
Member Author

@taylorotwell taylorotwell commented on 4301348 Oct 22, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lies
Copy link

@lies lies commented on 4301348 Oct 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! You remove bootstrap/paths.php and app not started, because app not found this paths:(
Fatal error: require(): Failed opening required '......./bootstrap/paths.php'

@mouhsinelonly
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i need to change the public path of the app ,where can i override the App Class ?!!

@martindilling
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of interesting changes, I think I like the way it's going (still trying to actually understand the changes xD), but damn it's "interesting" to work on a project in this branch :P But learning a lot in the process ;)
Keep up the great work

@qgates
Copy link

@qgates qgates commented on 4301348 Oct 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those asking about changing public (and other) paths. A simple adjustment to bootstrap\app.php allows Application class methods containing path settings to be overridden. This includes all those defined in paths.php. Example:

class MyApplication extends Illuminate\Foundation\Application {

    /**
     * Get the path to the public / web directory.
     *
     * @return string
     */
    public function publicPath()
    {
        return $this->basePath.'/public_html';
    }

}

$app = new MyApplication(
    realpath(__DIR__.'/..')
);

The last 3 lines replace the existing $app instantiation. There might be a nicer method that allows the seamless injection of a new Application class without touching app.php, but this'll work nicely. Take a look at the Application class to get an idea of the other paths that may be overriden. The constructor accepts (and sets) the base path.

@raphaelbeckmann
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell You removed bootstrap/paths.php, but server.php still requires that file. Hence, php artisan serve is not working any longer. How to fix?

@qgates
Copy link

@qgates qgates commented on 4301348 Oct 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raphaelbeckmann This will be fixed pretty soon since L5 is in rapid development at the moment. If you need to get L5 working for the now with artisan serve, you can simply comment out the lines that refer the $paths and hardcode the public path instead. Everything in the app should work since paths are now defined inside the Application class.

Eg. server.php:

<?php

$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

$uri = urldecode($uri);

// $paths = require __DIR__.'/bootstrap/paths.php';

$requested = 'public/'.$uri;

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' and file_exists($requested))
{
    return false;
}

require_once 'public/index.php';

@efreed
Copy link

@efreed efreed commented on 4301348 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's related to this commit, but somewhere between Oct 15 and Oct 29 the Form::open() helper now requires an absolute namespace when using the 'action' param, or else it throws a php error.

Used to work:
{!! Form::open(['action']=>'FooController@save']) !!}

Now the namespace is needed:
{!! Form::open(['action']=>'App\Http\Controllers\FooController@save']) !!}

Please sign in to comment.