Reputation: 43
Is it possible to use a REST API as Doctrine database?
Regarding the configuration on http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/configuration.html I can change the "driver" property.
But in the list of allowed drivers there is no one to use a REST API.
What I would like to do is:
<?php
$config = new \Doctrine\DBAL\Configuration();
//..
$connectionParams = array(
'dbname' => 'my_rest_api',
'user' => 'user',
'password' => 'secret',
'host' => 'localhost:3000',
'driver' => 'rest',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
$entityManager = EntityManager::create($conn, $config);
// Sends a GET request to localhost:3000/myentity/1 and maps it properly to my configured entity
$entity = $entityManager->find("MyNamespace\Entity\MyEntity", 1);
// Sends a POST request to localhost:3000/myentity
$entity = new MyEntity();
$entityManager->persist($entity);
$entityManager->flush();
// and so on
Thank you for your answers!!
Upvotes: 3
Views: 3652
Reputation: 954
DoctrineRestDriver is exactly doing what you are looking for!
https://github.com/CircleOfNice/DoctrineRestDriver
Have fun!
Upvotes: 5