Skip to content

refactored cookie jar to make it easier to store the cookie jar elsewhere #69

Open
wants to merge 1 commit into from

2 participants

@lsmith77

In our case we needed to persist the cookie jar inside the session.

<?php

namespace Liip\AuthenticationBundle\Security;

use Symfony\Component\HttpFoundation\Session;
use Buzz\Cookie\Cookie;
use Buzz\Cookie\Jar;
use Buzz\Message;

class SessionCookieJar extends Jar
{
    protected $session;

    public function __construct(Session $session)
    {
        $this->session = $session;
    }

    public function setCookies($cookies)
    {
        $this->session->set('buzz_authentication_cookies', $cookies);
    }

    public function getCookies()
    {
        return $this->session->get('buzz_authentication_cookies', array());
    }
}
@kriswallsmith
Owner

Can you say more about this case? If swapping out the storage mechanism is a legit use case I would like to also look at other implementation options.

@lsmith77

we are storing the cookies to send in requests inside the session

@kriswallsmith
Owner

Thanks, Captain Obvious… In your opinion, should we create a storage interface and inject that into the cookie jar? Designing for inheritance doesn't seem right here.

@lsmith77

dunno ... i don't think that many people will need to do something like this .. but this didn't feel like all that bad to do with inheritance and the changes are not all that drastic.

of course for example for sessions in Symfony2 core we have this separation, but it seems a bit like overkill for this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.