Reputation: 2891
My company keeps the database administration and development in a separate department and for my Symfony2 app I am only allowed to interact with the DB via a service API. This means I can't use Doctrine ORM or even php pdo.
I basically will have to build my own abstraction layer. I have been searching the internet all day and haven't seen anything about best practices for creating my own basic entity abastraction layer for Symfony2. I can't even find information on using anything but Doctrine.
Does anyone have any suggestions or know of any resources for best practices on doing this for symfony2?
Upvotes: 7
Views: 5618
Reputation: 1415
It seems to me that the API might be perceived as another DB driver. I suppose that doctrine can be extended to accept custom db driver, yet I'm not sure how much effort it'll take and whether your API provides all the necessary functionality. Obvious pros of such approach is that you would be able to use the same doctrine's features as you would have if you had a PDO access.
Upvotes: 0
Reputation: 716
I did it following way:
First of all I've defined Entities, but without ORM stuff in there.
Then I've created Service Container classes which were retrieving data from API. http://symfony.com/doc/current/book/service_container.html
Third I've used something like Data Transformers to transform data fetched from API to my Symfony Entities. http://symfony.com/doc/current/cookbook/form/data_transformers.html
Please feel free to contact me for more details.
Upvotes: 6
Reputation: 36191
Symfony is model independent (There's no 'M' from MVC). Notice that Doctrine or Propel are separate projects integrated with Symfony. They're not part of the framework.
I think you should just implement client library for your API which would be decoupled from the framework (you might even use it in plain php scripts or other framework).
Step 2 would be integrating you library with Symfony. It would probably include creating a bundle and appropriate service definitions. Looking at DoctrineBundle might give you some ideas.
Upvotes: 6