Skip to content

Commit

Permalink
follow Router changes in Laravel5.2�
Browse files Browse the repository at this point in the history
  • Loading branch information
scil committed Jan 22, 2016
1 parent 259f5e2 commit 59b7016
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions config/laravelfly.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
// 'currentRequest',

/* depends */
/* Uncomment it if it's not same on each requests. Its value changed by Route::middleware */
// 'middleware',
/* Uncomment them if it's not same on each requests. Its value changed by Route::middleware */
// 'middleware',
// 'middlewareGroups', // only for laravel5.2+

'__obj__' => [
'routes' => [
Expand Down
28 changes: 26 additions & 2 deletions src/LaravelFly/Greedy/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@
namespace LaravelFly\Greedy\Routing;

use Illuminate\Routing\Route as BaseRoute;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Container\Container;

class Router extends \Illuminate\Routing\Router
{

protected $beforeAppBooted = true;
protected $version;

public function __construct(Dispatcher $events, Container $container = null)
{
parent::__construct($events, $container);
$this->version = substr($container::VERSION, 0, 3);
}

public function appBooted()
{
Expand All @@ -29,10 +38,25 @@ protected function newRoute($methods, $uri, $action)
{
if ($this->beforeAppBooted) {
// before any request, routes are compiled auto.
return (new Route($methods, $uri, $action))->setContainer($this->container);

if ($this->version == '5.1') {
return (new Route($methods, $uri, $action))->setContainer($this->container);
} elseif ($this->version == '5.2') {
return (new Route($methods, $uri, $action))
->setRouter($this)
->setContainer($this->container);
}
} else {
// routes creaed during request are not compiled auto. They are compiled when match
return (new BaseRoute($methods, $uri, $action))->setContainer($this->container);

if ($this->version == '5.1') {
return (new BaseRoute($methods, $uri, $action))->setContainer($this->container);
} elseif ($this->version == '5.2') {
return (new BaseRoute($methods, $uri, $action))
->setRouter($this)
->setContainer($this->container);

}
}
}
}

0 comments on commit 59b7016

Please sign in to comment.