Hi,
I have a Symfony2 setup which uses doctrine, FOSRestBundle and JMS Serializer.
As I want to change properties before serialization, I have an API Layer. One Api wraps a Doctrine entity; (and exposes its properties using VirtualProperty)
All Api classes can be instatiated by calling the specific constructor, like $userApi = new UserApi($user); Then i just return the API in the Controller.
Now, i want to use services in my API Layer - mostly utilities for which I share code.
How would I do that? ;-)
All Api Objects extend from ApiWrapper; So ApiWrapper can have a protected variable which holds the necessary service.
I don't want to hand over the service to the API everytime I create it - this would mean that in every controller i first have to create the service on which the API Layer depends.
I thougt about making the API itself a Service, but as far as I know then I cannot specify mandatory parameters (like the entity, $user in the example above)
Would it be wise to make an ApiFactory and define this as a service? Any other recommendations?
Thanks for your help,
Uli