After reading a lot about Symfony2 DIC and Semantic Configuration, I've asked myself: "So, now how do have I to procede for reach what I'm trying to reach!?"
Scenario
Imagine you want to create a service that is pretty like a "admin dashboard dispatcher".
This means that I have some entities that I want to do CRUD on. What I don't want to do is a combination of route->action->logic for every entity in my project; that's because, in that way, I'll have to write for each object something like:
- /add/entity
- addEntityAction
- entityLogic
where "entity", of course, is the name of entity in object.
I'm building up a service (like a dispatcher) that will respond on action (add-delete-edit) but that is parameterized: I'll write onto address bar something like /add/entityA
or /add/entityB
and that routes will lead me at the same action (of course) were I recall my service with entity name.
At this point, my service, should be smart to know what is EntityClass, FormTypeClass and template file for the entity in object.
And here comes my mental chaos
I have to do something preliminaries configurations like following php array (this is only an example)
array(
'EntityA'=>array(
'class'=>'BundleName/Entity/EntityA',
'form'=>'BundleName/Form/entityAType',
'template'=>'EntityATemplate'),
'EntityB'=>array(
'class'=>'BundleName/Entity/EntityB',
'form'=>'BundleName/Form/entityBType',
'template'=>'EntityBTemplate'),
[...]
);
or something equivalent.
BUT ....
What is the best practice, for this scenario, taking into account that only me and my team will use this bundle (so isn't a third-part bundle)?
First solution
Use a parameters.php
file were I define some constant or static members
Second solution
Use a map (like previous array) directly into my service
Third solution
Use semantic configuration for my bundle, defining an Extension class and so on
If I have to be honest, I can't say what is better. Obviously first one and third one are better that second one.
First solution broke up symfony2 philosophy but seems the only way because the second one, seems to be useful only if I have to trigger up creation of some services (in cascad fashion) that are handled directly my DIC, or for have configuration hierarchy, or for merge more that one configuration file, or (maybe the most importat for third party bundle) for make some kind of validation on config. file
What's your opinion? Do you see some other methods for do this, or do you simply prefer third solution? I want to know your opinions.
Edit: Obviously I can use builder injection or setter injection, but I consider it into "DIC" section (so, third solution)