Defining an Api Layer as a Service? Using a Factory?

122 views
Skip to first unread message

Ulrich Lichtenegger

unread,
Oct 20, 2014, 10:12:18 AM10/20/14
to resting-wi...@googlegroups.com
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

Lukas Kahwe Smith

unread,
Oct 22, 2014, 9:18:24 AM10/22/14
to Ulrich Lichtenegger, resting-wi...@googlegroups.com
you could have custom handlers inside JMS that have access to the services that can do the necessary work.

regards,
Lukas Kahwe Smith
sm...@pooteeweet.org



signature.asc
Reply all
Reply to author
Forward
0 new messages