-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
unserializing objects with dependencies #12222
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
Comments
I understand the idea, but you shouldn't do this. If your namespace, classname or property names change, your object cannot be unserialized. Next to that, it will be a hell of a job to create this possibility in the DIC. If you want to have users create their own forms, store the setup and build form types based on that setup when the form is needed. This means that over time, your custom layer between the FormBuilder and form setup will be a lot more sturdy. A nice side effect is that you can hook into the building process. It also means that if the symfony forms chance, you just have to place a new bridge in between (or update the old). It also means you could use other frameworks if you please. |
Thanks for your input on my concrete use case .. it is helpful. However i would like to set to topic to whether symfony should be able to do dependency injection on runtime too. (of course also keep the compile time DI !!) The thing is that a lot of symfony and user create objects can have both state and dependencies. And the problem is how to keep the state and have the dependencies at the same time. Because objects are no C structs with data only!! Now i belief that an object should be able to independently offer different state representations of itself or it's parts (properties). For example i value the Of course This is also apperent by the fact that symfony dictates your application architecture for you rather then give you the freedom to choose which architecture you prefer. I noticed this when trying to move to Domain Driven Design and to do domain logging i had to grab the kernel/container from global scope. This was because the models are also not injected with dependencies at runtime. |
I don't know about your application setup, but models having dependencies sounds like code smell to me, especially when serializing. |
This is a nice example of how a functionality of the application can be serialized and unserialized #12329 this one doesn't seem to have dependencies though |
Closing. |
In my opinion the introduction to the service container is ambigious.
Then to continue: By all means if anyone thinks i'm pulling things out of context from each other, please elaborate on the correct context of how this is supposed to read. The documentation points to a wikipedia page that says: Two things stand out here in my opinion. First that it talks about Second that typically this kind of architecture is used over network (as supposed to classes "communicating" to each other on the same machine). For me the wikipedia page relates more to for example the trend of micro-services that are becomming more popular lately. I saw people in #symonfy @ freenode put every piece of functionality in a service class and prevents the data-objects from modifying themselves. Some sources say this is bad practice "(OOP) Writing lots of "xxxxxManager" classes that contain all of the methods for manipulating the fields of objects that have little or no methods of their own" -- of course i don't want to be a bad programmer (refering to the article title) I'm going a stretch on my intuition here. What i would like to know the following:
I realise any discussion on architecture would be more difficult then let's say an implementation detail of a method. I'm sad the issue was closed so early as i don't see many issues covering the bigger picture of the symfony framework...which is also important for a community driven framework, no? |
@flip111 Do you mind opening an issue on the docs repository if you think that the documentation should be improved/clarified in a way? |
Hi,
I was thinking about creating a Form Builder UI. The user could specify the fields and then a
FormBuilder
class would be created at runtime. Great !Just then i noticed the FormBuilder can be feeded some classes that can be services too, like the
EventDispatcher
. So in case you need that one you need theEventDispatcher
which was already instantiated by the DIC and not a new one.After looking around a litlte bit the following resource showed up:
https://www.drupal.org/node/2004282
where @stof points to
#7230
I would like to know if it's feasible to add support for this to the DI component or if it's left to the developer to request services for the unserialized component and figure out how to inject them.
There are some problems with doing it this way. Please consider the general question of injected services into unserialized objects, not just in the context of the FormBuilder, but also as in the linked PR of assetic and other use cases.
Code could look like this:
DIC would then do the following:
wakeup()
methodIn addition to my question if this would be a good suggestion to the DIC component in specific, i would like to ask if this would be a good attribute to the symfony code wether or not it will be placed in the DIC component.
In conclusion: it's not that hard to make the ugly way when all the services are available from the DIC, but it might be worthwhile to have this functionality available to everyone.
Thoughts?
The text was updated successfully, but these errors were encountered: