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

[NFR] Make Phalcon\Http\Cookie less depend on session #875

Merged
merged 1 commit into from Jul 18, 2013
Merged

[NFR] Make Phalcon\Http\Cookie less depend on session #875

merged 1 commit into from Jul 18, 2013

Conversation

ghost
Copy link

@ghost ghost commented Jul 18, 2013

This can be useful for cases where the application does not need sessions (ie, WordPress does not use sessions):

$di = new \Phalcon\DI();
$di->set('cookies', function () {
        $cookies = new Phalcon\Http\Response\Cookies();
        $cookies->useEncryption(false);
        return $cookies;
});

$di->set('response', function() { return new \Phalcon\Http\Response(); });
$di->getShared('cookies')->set('gift_order', '2221dddd', time()+86400, '/');
$di->getShared('response')->send();

If session is not added to DI, it won't be used — this can be useful in some cases, especially if sessions are stored in the database: if we don't need session, we can save some CPU ticks by not connecting to the database etc.

@phalcon
Copy link
Collaborator

phalcon commented Jul 18, 2013

If the user set additional options for the cookie, the only way to recover them in a second request is getting those details from the session or some temporal storage where we can place them. Does this disable that feature or make it optional?

@ghost
Copy link
Author

ghost commented Jul 18, 2013

Optional: if the session is not provided, it is not used. If it is provided, it will work the same way as before.

The patch tries to make the use of session optional.

There is often no need to send a cookie on every response: one setcookie() is enough for the browser to send cookies on every request until the cookie expires.

@phalcon
Copy link
Collaborator

phalcon commented Jul 18, 2013

Ok, great!

phalcon pushed a commit that referenced this pull request Jul 18, 2013
[NFR] Make Phalcon\Http\Cookie less depend on session
@phalcon phalcon merged commit b906c43 into phalcon:1.2.1 Jul 18, 2013
@ghost ghost deleted the cookie-session branch July 18, 2013 17:46
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

Successfully merging this pull request may close these issues.

2 participants