nuevephp / laravel-session

Laravel Session driver middleware for SlimPHP 3
MIT License
0 stars 1 forks source link

use in database laravel session - issue with containers #5

Open nbsoftware opened 8 years ago

nbsoftware commented 8 years ago

Hello, So I'm trying to use this package and configure it so that the session lives in the database as this was my original intent selecting it. Seems like this is harder than I thought it would be - and/or should be. I'm puzzled with an error in Illuminate/Session/DatabaseSessionHandler's _construct where the last parameter is receiving a Slim\Container rather than a Illuminate\Container\Container and this because the Illuminate\Session\SessionManager->createDatabaseDriver would pass $this->app as the third parameter.

    protected function createDatabaseDriver()
    {
        $connection = $this->getDatabaseConnection();
        $table = $this->app['config']['session.table'];
        return $this->buildSession(new DatabaseSessionHandler($connection, $table, $this->app));
    }

As I'm pretty new to all these "container" enabled frameworks, I am not sure if this is easily fixable nor how. I've made many attempts but none of them are working. Those two containers (Pimple and Illuminate) don't seem to be interoperable. Would you be kind enough to put me on the correct path on how to do that? Thanks

nbsoftware commented 8 years ago

Ok, so after some further trials I have a working version, which I think is clean. Basically it involves using a Illuminate\Container\Container throughout all Session configuration and setup, and setting this container as a parameter in Slim's default container. And finally, slightly modifying the PimpleSessionServiceProvider to create the SessionManager from the Illuminate Container extracted from Slim's container rather than directly from it. I guess this better separates the usage of the two containers and I bet this is still working with the FileSystem driver. I will verify this latter assertion, clean out things to show both usage (file & database) and then commit the changes on my repo. When done you could then review those.

nbsoftware commented 8 years ago

There you go. I've committed the changes in a new "database" branch.

silentworks commented 8 years ago

I will need to look into this, I have not worked with the session library for a while now and not that familiar with Laravel 5+ version of the library, not sure why this change would have broken it. I looked at your branch and it looks good, just don't like the idea of two containers, but if it works, it works.

nbsoftware commented 8 years ago

I agree. Not fond of two containers either but didn't find a prettier way to make it work. Should Laravel's container have implemented the container-interop interface, it would have been easier I suppose.