Skip to content

Commit

Permalink
Working on middle wares.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 6, 2014
1 parent 43e8c60 commit b8f3dd6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/Http/Middleware/AuthMiddleware.php
Expand Up @@ -39,9 +39,9 @@ public function __construct(Authenticator $auth,
/**
* Handle an incoming request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
* @return mixed
*/
public function handle($request, Closure $next)
{
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Middleware/BasicAuthMiddleware.php
Expand Up @@ -27,9 +27,9 @@ public function __construct(Authenticator $auth)
/**
* Handle an incoming request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
* @return mixed
*/
public function handle($request, Closure $next)
{
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Middleware/CsrfMiddleware.php
Expand Up @@ -9,13 +9,13 @@ class CsrfMiddleware implements Middleware {
/**
* Handle an incoming request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->getSession()->token() != $request->input('_token'))
if ($request->session()->token() != $request->input('_token'))
{
throw new TokenMismatchException;
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Middleware/GuestMiddleware.php
Expand Up @@ -28,9 +28,9 @@ public function __construct(Authenticator $auth)
/**
* Handle an incoming request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
* @return mixed
*/
public function handle($request, Closure $next)
{
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Middleware/MaintenanceMiddleware.php
Expand Up @@ -28,9 +28,9 @@ public function __construct(Application $app)
/**
* Handle an incoming request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
* @return mixed
*/
public function handle($request, Closure $next)
{
Expand Down
17 changes: 17 additions & 0 deletions app/Providers/AppServiceProvider.php
Expand Up @@ -31,4 +31,21 @@ class AppServiceProvider extends ServiceProvider {
'Illuminate\Session\Middleware\Writer',
];

/**
* 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);
});
});
}

}

13 comments on commit b8f3dd6

@rspahni
Copy link
Contributor

@rspahni rspahni commented on b8f3dd6 Oct 7, 2014

Choose a reason for hiding this comment

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

Taylor - at this point, the AppServiceProvider "route middlewares" ($middleware) property is not functional yet, correct? Trying to anticipate the upcoming port of filters to middlewares (yeah I know, L5 alpha stage yet, apologies) and my experimental route middleware classes don't seem to get instantiated.

@taylorotwell
Copy link
Member Author

@taylorotwell taylorotwell commented on b8f3dd6 Oct 7, 2014 via email

Choose a reason for hiding this comment

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

@rspahni
Copy link
Contributor

@rspahni rspahni commented on b8f3dd6 Oct 7, 2014

Choose a reason for hiding this comment

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

:) I don't suppose members were easy to impress with uninstantiated classes. I.e. will give things another shot tm, must have missed something. Many thx for letting me know.

@rspahni
Copy link
Contributor

@rspahni rspahni commented on b8f3dd6 Oct 8, 2014

Choose a reason for hiding this comment

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

Works :) Actually, for "alpha" stage L5's robustness is simply amazing. One of the reasons why people can't resist the L5 temptation. My trouble, if any, is always for a lack of understanding/documentation. Suggestion: What if you asked Jeff to add soonest a couple of videos to his "What's New in Laravel 5.0" series that examine arising L5 concepts such as middleware or annotations (that I'm sure are fully firmed up in your mind and can be featured at Laracasts at this point) in before/after style. This might save you many unproductive dialogues with mavericks like me.

@brayniverse
Copy link
Contributor

Choose a reason for hiding this comment

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

@rspahni I would be surprised if @JeffreyWay didn't cover these features as soon as they are stable. If you're interested, the forums at Laracasts normally discuss new features in L5 while they're being developed :).

Middleware
Annotations

@rspahni
Copy link
Contributor

@rspahni rspahni commented on b8f3dd6 Oct 8, 2014

Choose a reason for hiding this comment

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

@brayniverse - re Laracasts forum, pretty active there myself (incl. the threads you referred to) but things could be slightly more productive with some high-level guidance in typical @JeffreyWay intro style. On timing, my experience to date has been, L5 features are conceptually robust and technically stable when they make a first appearance on GitHub. But never mind if @taylorotwell wants to hold back for a few weeks still.

@brayniverse
Copy link
Contributor

Choose a reason for hiding this comment

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

@rspahni Assumed you were an active user of Laracasts but thought I'd share nonetheless; incase I assumed wrong.

@JeffreyWay
Copy link
Contributor

Choose a reason for hiding this comment

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

Of course I'll cover this eventually, but I want to hold off until I have the go-ahead on this new stuff from Taylor.

@slakbal
Copy link

@slakbal slakbal commented on b8f3dd6 Oct 8, 2014

Choose a reason for hiding this comment

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

Cool... Thanks Jeffrey... I am wondering just now where the FilterServiceProvider went to.... and how to I bootstrap my custom filters now? I am riding bleeding edge on this one project now so that when it is released I'm already way ahead. Or did I miss something... where is one's custom filter now bootstrapped...

@rspahni
Copy link
Contributor

@rspahni rspahni commented on b8f3dd6 Oct 8, 2014

Choose a reason for hiding this comment

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

@slakbal - have a look here, that's what I know: https://laracasts.com/discuss/channels/requests/how-to-use-middleware-as-filters. @JeffreyWay - of course - my thought was, you might be able to get Taylor's go-ahead now for a high-level intro (I understand he has been demoing those new L5 features in user groups lately, plus might be slightly fed up with people like me approaching him with "not working" shouts :)).

@slakbal
Copy link

@slakbal slakbal commented on b8f3dd6 Oct 8, 2014

Choose a reason for hiding this comment

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

Just a small side note... I know a lot of these changes are really for the greater good and good use of patterns. I've been working solely with Laravel over the past 3+ years. But I would kindly recommend Taylor not to deviate to far from where Laravel comes from, which is: Laravel was easy, quick to pick-up and you made it easy through simplifying things and that even for developer newbies.

Maybe I need to just get used to a lot of new stuff... but I get the feeling that is is not easy as it was before. And that the barrier to entry might be already be to steep for starters in comparison with earlier versions. Usage patterns are changing and in my opinion too fast. If you have too many big changes, people could move away and products will be built on other platforms. But I'm sure and trust you guys are thinking and debating a lot about this. Thanks anyway for an amazing platform which I enjoy and follow meticulously.

@JeffreyWay
Copy link
Contributor

Choose a reason for hiding this comment

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

@rspahni - Maybe. For "just pushed" stuff, I'm making it entirely his call now. If Laracasts covers things too soon, then it can create unnecessary support tickets and tweets. The code isn't even to beta yet. So he shouldn't have to worry about reading issues, or providing support for code that's still in development.

@slakbal - It may feel that way at first, but, don't worry, L5 simplifies so many of the tedious things that we had to do in v4. It's better in every possible way. Just like I couldn't imagine going back to v3 from 4, the same is true for this new release.

@slakbal
Copy link

@slakbal slakbal commented on b8f3dd6 Oct 8, 2014

Choose a reason for hiding this comment

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

@JeffreyWay Thanks Jeff, I trust it is definitely going to be that way. I'm really hungry to see the new stuff in action, can't wait to get a peek at the documentation! Again amazing job and kudos to Taylor for this amazing framework and you for everything you do in the community!

Please sign in to comment.