Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Add PassThroughTrait for middleware #9311

Closed
wants to merge 4 commits into from
Closed

[5.2] Add PassThroughTrait for middleware #9311

wants to merge 4 commits into from

Conversation

overtrue
Copy link
Contributor

Let all the middleware supports exclude some URI.


trait PassThroughTrait
{
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

So maybe add an empty array property protected $except = []; ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

http://php.net/manual/en/language.oop5.traits.php

If a trait defines a property then a class can not define a property with the same name, otherwise an error is issued. It is an E_STRICT if the class definition is compatible (same visibility and initial value) or fatal error otherwise.

Example #12 Conflict Resolution

<?php
trait PropertiesTrait {
    public $same = true;
    public $different = false;
}

class PropertiesExample {
    use PropertiesTrait;
    public $same = true; // Strict Standards
    public $different = true; // Fatal error
}
?>

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure @overtrue , maybe I misexplained.
The $except property should be moved from VerifyCsrfToken to PassThroughTrait

Copy link
Member

Choose a reason for hiding this comment

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

@overtrue is right on this one, it just going to throw exception by defining the property in both place.

@lucasmichot
Copy link
Contributor

👍 @overtrue
Would love to see this merged !

ATM I have to extend \Illuminate\Session\Middleware\StartSession in my app as I don't want session to be created for my api/* routes.

This trait would really ease up things


class VerifyCsrfToken
{
use PassThroughTrait;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also include it to the others middleware, so that we let this passthrough choice for the other ones, especially the \Illuminate\Session\Middleware\StartSession one ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will do it.

@overtrue
Copy link
Contributor Author

@lucasmichot Yes, almost all my middleware need the trait.

@GrahamCampbell GrahamCampbell changed the title Add PassThroughTrait for middleware. [5.2] Add PassThroughTrait for middleware Jun 18, 2015
@overtrue
Copy link
Contributor Author

@lucasmichot 😞

@lucasmichot
Copy link
Contributor

Indeed @overtrue

Is there something we can do for that - maybe do it a different way - let us know @taylorotwell ?
This PR would really have lots of value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants