Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpFoundation] MakeSessionHandlerProxy implementSessionIdInterface#50626

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@MatTheCat
Copy link
Contributor

QA
Branch?6.4
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#45186 and#50583
LicenseMIT
Doc PRNot yet

Supersedes#47071

It is currently not easy to provide its own session ids because even if your handler implementsSessionIdInterface, it will be wrapped in aSessionHandlerProxy which does not, so yourcreate_sid method won’t be called.

@deepsidhu1313
Copy link

Does this suppose to help setting the a custom session id usingsetId($some_id) function ofSymfony\Component\HttpFoundation\Session\Session ??

@nicolas-grekas
Copy link
Member

I think all decorators should implement this, isn't it?

nicolas-grekas
nicolas-grekas previously approved these changesJun 27, 2023
@MatTheCat
Copy link
ContributorAuthor

Woops missed your comment.

I think all decorators should implement this, isn't it?

I guess they could 🤔 else you’re required to put yourSessionIdInterface on top of the stack. I guess this isn’t an issue since you approved this PR?

@MatTheCat
Copy link
ContributorAuthor

Eeer after readinghttps://symfony.com/doc/current/session.html#session-proxies I wonder if this PR makes sense as you’re supposed to extendSessionHandlerProxy rather than decorate the inner handler.

@MatTheCat
Copy link
ContributorAuthor

MatTheCat commentedJun 28, 2023
edited
Loading

Okay, just tried to do that and I got aServiceCircularReferenceException… Does the issue come from Symfony or the documentation?

@nicolas-grekas
Copy link
Member

I'm a bit lost between the handler, the proxy, etc. I'll let you investigate if you don't mind :)

@MatTheCat
Copy link
ContributorAuthor

I’m still lost but I have some leads: session proxies purpose was originally to ease the migration from PHP 5.3 whereSessionHandlerInterface did not exist. They weredeprecated thenremoved, butAbstractProxy andSessionHandlerProxy escaped death thanks to#24523 because the latter wouldturns any handler into an instance ofAbstractSessionHandler. As it doesn’t seem to be the case maybe I’m misunderstanding something 🤔

TheSessionHandlerProxy always has been documented as an extension point (like inhttps://symfony.com/doc/current/session.html#session-proxies). I don’t know if it used to work at some point, but now doing as documented results in aServiceCircularReferenceException because theframework.session.handler_id service is aliased bysession.handler, which is aliased bySessionHandlerInterface (you can fix this issue by wiring your wrapped handler yourself though). Also by doing this you couldn’t use decorators like theMarshallingSessionHandler.

That’s why I thought you were supposed to decoratesession.handler instead, which requires less configuration but more boilerplate code to proxy all ofSessionHandlerInterface,SessionUpdateTimestampHandlerInterface (andSessionIdInterface?) methods.

@nicolas-grekasnicolas-grekas added ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" and removed ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelsOct 16, 2023
@nicolas-grekasnicolas-grekas dismissed theirstale reviewOctober 20, 2023 07:14

discussion still open

@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
@MatTheCat
Copy link
ContributorAuthor

Closing, since there already is a way to configure aSessionIdInterface handler.

@MatTheCatMatTheCat deleted the session_id_interface branchFebruary 2, 2024 18:32
@jdevinemt
Copy link

I have been struggling for most of the day trying to figure out why the create_sid() method was never being called from my custom session handler. I finally found it was because even though I am specifying a class that implements\SessionHandlerInterface, \SessionIdInterface, \SessionUpdateTimestampHandlerInterface as theframework.session.handler_id value, it is being replaced/proxied by the\Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy class. Which, as mentioned in this PR does not implement the\SessionIdInterface.

I think it would be beneficial to reconsider implementing this.

@MatTheCat Is right that you can decorate theSessionHandlerProxy to implement\SessionIdInterface. But I think it is more straightforward to have the\SessionIdInterface implemented inSessionHandlerProxy as initially submitted in this PR. Then we have an implementation ofSessionHandlerProxy that handles all possible PHP session interfaces, which could help prevent the assumptions that having a handler with\SessionIdInterface being wrong.

If it is decided that it's best not to implement this, we may want to consider deprecating passing a service that does not extendSessionHandlerProxy as a value toframework.session.handler_id , or at least update the documentation to discourage using a handler that isn't an instance of that class.

@jdevinemt
Copy link

The SessionHandlerProxy always has been documented as an extension point (like inhttps://symfony.com/doc/current/session.html#session-proxies). I don’t know if it used to work at some point, but now doing as documented results in a ServiceCircularReferenceException because the framework.session.handler_id service is aliased by session.handler, which is aliased by SessionHandlerInterface (you can fix this issue by wiring your wrapped handler yourself though). Also by doing this you couldn’t use decorators like the MarshallingSessionHandler.

This is another big reason that this PR should be reconsidered. It's awkward to work around the current implementation due to the circular dependency@MatTheCat mentioned above. You have to either have two classes, one for the majority of the custom handler implementation that implements\SessionHandlerInterface and\SessionUpdateTimestampHandlerInterface. And another class that extendsSessionHandlerProxy and implements\SessionIdInterface. Then you have to explicitly wire the main handler to the proxied handler doing something like this:

framework:session:enabled:truestorage_factory_id:session.storage.factory.nativehandler_id:App\SessionHandlerProxyservices:App\SessionHandlerProxy:arguments:$handler:App\SessionHandler

You could implement all the handler functionality to theApp\SessionHandlerProxy, but it still needs a\SessionHandlerInterface in it's constructor. You could pass something like the native handler, but then if you forget to override on of the session handler methods, it would defer to that handler, which just adds confusion and may cause unexpected behavior.

@MatTheCat
Copy link
ContributorAuthor

Hey@jdevinemt 👋

Glad to see you concerned, but closed PRs don't usually generate traction; opening an issue may be better.

@jdevinemt
Copy link

Thanks@MatTheCat. I had a feeling that might be the case. I just finished my implementation to work around this restriction in my current project. I'm working through writing tests to cover my handler and handler proxy services. Once I'm done with that I'll open a new issue and create a PR if I can figure out the best way to implement this interface.

MatTheCat reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees

No one assigned

Projects

None yet

Milestone

7.1

Development

Successfully merging this pull request may close these issues.

Symfony Session Handlers should implement SessionIdInterface interface

6 participants

@MatTheCat@deepsidhu1313@nicolas-grekas@jdevinemt@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp