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.4] Fix gatherMiddleware() only unique #16173

Closed
wants to merge 3 commits into from
Closed

[5.4] Fix gatherMiddleware() only unique #16173

wants to merge 3 commits into from

Conversation

actionm
Copy link
Contributor

@actionm actionm commented Oct 29, 2016

For example:

I have a route group with middleware 'auth' and controller with middleware 'auth'.

Maybe framework/src/Illuminate/Routing/Route.php gatherMiddleware() must return only unique values ?

class MainController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }
}


Route::group(['middleware' => ['auth']], function () {

    Route::get('/first', 'MainController@index');
}

Route::get('/second', 'MainController@index');

php artisan route:list

before:

| Domain | Method   | URI    | Name  | Action                                      | Middleware |

|        | GET|HEAD | first  |       | App\Http\Controllers\MainController@index   | web,auth,auth
|        | GET|HEAD | second |       | App\Http\Controllers\MainController@index   | web,auth

after fix:

| Domain | Method   | URI    | Name  | Action                                      | Middleware |

|        | GET|HEAD | first  |       | App\Http\Controllers\MainController@index   | web,auth
|        | GET|HEAD | second |       | App\Http\Controllers\MainController@index   | web,auth

Would it be more preferable if artisan route:list displayed middleware from route and controller separately?

For example:

| Domain | Method   | URI    | Name  | Action                                      | Middleware |

|        | GET|HEAD | first  |       | App\Http\Controllers\MainController@index   | [r]web,auth [c]auth
|        | GET|HEAD | second |       | App\Http\Controllers\MainController@index   | [r]web [c]auth

Fix: "Fatal error: Object of class Closure could not be converted to string" to pass tests/Routing/RoutingRouteTest.php:187
@GrahamCampbell GrahamCampbell changed the title [5.3] Fix gatherMiddleware() only unique [5.4] Fix gatherMiddleware() only unique Oct 30, 2016
@GrahamCampbell
Copy link
Member

GrahamCampbell commented Oct 30, 2016

Just use array_unique. Collections are too slow.

@taylorotwell
Copy link
Member

Wrong branch. Would go to 5.3.

@vlakoff
Copy link
Contributor

vlakoff commented Oct 30, 2016

@actionm Just discovered that array_unique() is much faster with the SORT_REGULAR flag. Thank you!!

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