No, there is no Session Contract available yet.
##If you want to resolve a Session Store Using Ioc Container
When we use Session Facade proxy it returns an instance of a SessionManager class which dynamically calls the methods on the underlying Session Store
. If we take a look at the Session Store
class we can see that it implements the Illuminate\Session\SessionInterface
which is actually extended from the Symfony\Component\HttpFoundation\Session\SessionInterface
. So, if you want to resolve a Store
instance through IoC container you can inject a dependency like this:
use Symfony\Component\HttpFoundation\Session\SessionInterface as SessionContract;
Route::get('/session',function(SessionContract $session) // Injection using type hinting.
{
//example put call on Store.
$session->put('name','usman');
//getting the stored value.
return $session->get('name');
});
Of course you can use a similar approach with Controller actions. Regards,
it is safer to use
HttpFoundation/Session/SessionInterface
which extends the symfony interface
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community