Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Entities in Symfony2 without Doctrine

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?

like image 367
Clint Avatar asked Nov 17 '11 22:11

Clint


People also ask

Does Symfony use Doctrine?

Symfony provides all the tools you need to use databases in your applications thanks to Doctrine, the best set of PHP libraries to work with databases.

How should be the process to add a new entity to the app in Symfony?

With the doctrine:database:create command we create a new database from the provided URL. With the make entity command, we create a new entity called City . The command creates two files: src/Entity/City. php and src/Repository/CityRepository.

What is a entity in Symfony?

Well, entity is a type of object that is used to hold data. Each instance of entity holds exactly one row of targeted database table. As for the directories, Symfony2 has some expectations where to find classes - that goes for entities as well.

Does Symfony use eloquent?

Symfony uses Doctrine, Laravel – Eloquent. And last but not least – the speed. In Laravel speed of the application is similar to the other PHP application.


2 Answers

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.

like image 54
Jakub Zalas Avatar answered Sep 30 '22 14:09

Jakub Zalas


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.

like image 38
mikayel ghazaryan Avatar answered Sep 30 '22 13:09

mikayel ghazaryan