flint / flint

Enhancements to Silex with structure and conventions.
http://flint.rtfd.org
MIT License
123 stars 15 forks source link

logout, login routes with SecurityServiceProvider + Flint #6

Closed jmontoyaa closed 11 years ago

jmontoyaa commented 11 years ago

Hey!

I found a bug when using Silex with the SecurityServiceProvider it happens because the SecurityServiceProvider creates routes on the fly with:

SecurityServiceProvider:addFakeRoute()

https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/SecurityServiceProvider.php#L548

For some reason in the ProjectUrlGenerator file the routes are not well generated and I have a fatal error.

'admin_logout' => array (
    0 => array (  ),
    1 => array (
 // line with fatal error 
   '_controller' => Silex\Provider\SecurityServiceProvider::__set_state(
                    array(
                        'fakeRoutes' => array (
                        0 =>
                            array(
                                0 => 'get',
                                1 => '/admin/logout',
                                2 => 'admin_logout',
                            ),
                        1 =>         array (
                            0 => 'match',
                            1 => '/admin/login_check',
                            2 => 'admin_login_check',
                        ),
                    ),
                )
               ),
        ),

So, the question is did you had any problems integrating SecurityServiceProvider with Flint?

I followed this tutorial http://henrik.bjrnskov.dk/silex-router

I think I will open an issue in silex because we should had a possibility to write our own routes, like Symfony2:

http://symfony.com/doc/current/book/security.html#logging-out

Finally, Flint is really great!

henrikbjorn commented 11 years ago

Hey @jmontoyaa

I dont remember having any problems, but that might have been in dev mode only. I will see if i get a bit of time to research this the coming days :)

henrikbjorn commented 11 years ago

A quick work around is to subclass the SecurityServiceProvider::addFakeRoute and have it be empty like:

<?php

class SecurityServiceProvider extends \Silex\Provider\SecurityServiceProvider
{
    public function addFakeRoute($method, $pattern, $name)
    {
        // Dont do anything otherwise the closures will be dumped and that leads to fatal errors.
     }
}

Also it is indeed a bit weird it adds thoose fake routes. But makes sense from a usability point of view, otherwise people would have to add empty closures to their application if they are only relying on Silex.

jmontoyaa commented 11 years ago

Thanks for your fast answer! I commented the addFakeRoute body so it was working so far. So I think I will go with your solution. I think that is not Flint fault, is the "magic" that creates the routes automatically:

https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/SecurityServiceProvider.php#L544

henrikbjorn commented 11 years ago

It have been fixed i Silex master. Closing :)

jmontoyaa commented 11 years ago

I confirm, the fix works, great!