We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Fallback DI Dependency Feedback and Shared Deps with Session and FlashSession

During my "Lets Code" live stream last night I had a little issue dealing with the dependency chain between Flash/Session and its required Session adapter. That said the issue was I was trying to register Flash/Session's DI container without an existing Session adapter to inject into it. You can see what I am talking about here at the specific point in my video: https://www.youtube.com/watch?v=-dCB3pCn_WM&t=13045

Under further inspection of Flash/Session I noticed that in this instance Flash/Session calls out to DI to get a shared copy of the Session dependency but does not seem to return any kind of logging or error message in the event that the dependency cannot be met. https://github.com/phalcon/cphalcon/blob/107b6f0197b0464d9f6b11ff390a560c000bf448/phalcon/flash/session.zep#L39-L44

I dug a little deeper into DI and found: https://github.com/phalcon/cphalcon/blob/107b6f0197b0464d9f6b11ff390a560c000bf448/phalcon/di.zep#L225-L245 Which definitley shows an error message could be raised through an execption as a possibility but public function get(string! name, parameters = null) also acts as a builder in the case that the dependency has not been registered. This leads me to the assumption that either this fallback builder isn't working or it has created a new session adapter on each request leaving me unable to share my state over a persistent session.

Ultimately, I would be happy to create a PR for this issue but I wanted to make sure I was observing a design "oversight" and not my own ignorance.

Proposal

Provide feedback to PHP error logger when a fallback dependency container is created as a warning with a link to the documentation for that service. For DI dependencies that require explicit shared state it should somehow be enforced.

Let me know what you all think and I will get to work.

My Phalcon Init from the video https://github.com/ninjapanzer/phalcon_php_fullcalendar/blob/master/public/index.php

edited Jun '17

If you use Phalcon\Di\FactoryDefault then you already have session service. But the problem with it is that it's not started by default so it's pretty much useless and best just add it yourself.

https://github.com/phalcon/cphalcon/issues/12921 check this issue

Fix the video link :)

Updated https://www.youtube.com/watch?v=-dCB3pCn_WM&t=13045

Fix the video link :)