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

Separate Session repository #8

Open
JoeBengalen opened this issue Mar 28, 2015 · 4 comments
Open

Separate Session repository #8

JoeBengalen opened this issue Mar 28, 2015 · 4 comments
Assignees
Milestone

Comments

@JoeBengalen
Copy link
Owner

Create wrapper class for the $_SESSION global that implements \ArrayAccess

Create ArrayAccessRepository which accepts both objects implementing ArrayAccess and real arrays.

Transform the SessionRepository to use the ArrayAccessRepository and SessionWrapper

Transform the ArrayRepository to use the ArrayAccessRepository

@JoeBengalen
Copy link
Owner Author

class Session implements ArrayAccess
{
    public function __construct()
    {
        $this->data = &$_SESSION;
    }

    public function isSessionActive()
    {
        return session_status() === PHP_SESSION_ACTIVE;
    }

    // ArrayAccess methods ...
}

@JoeBengalen
Copy link
Owner Author

class ArrayAccessRepository implements SimpleRepositoryInterface
{
    public function __construct(array $array)
    {
        $this->data = $array;
    }

    // SimpleRepositoryInterface methods
}

@JoeBengalen
Copy link
Owner Author

class SessionRepostory extends ArrayAccessRepository 
{
    public function __construct(Session $session)
    {
        if (!$this->isSessionActive()) {
            throw new CacheException('PHP session must be active.');
        }

        parent::__construct($session);
    }
}

@JoeBengalen
Copy link
Owner Author

class ArrayRepostory extends ArrayAccessRepository 
{
    public function __construct()
    {
        parent::__construct([]);
    }
}

@JoeBengalen JoeBengalen added this to the 1.1.0 milestone Mar 28, 2015
@JoeBengalen JoeBengalen self-assigned this Mar 28, 2015
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

No branches or pull requests

1 participant