将Doctrine与REST API一起使用

J. *_*Doe 3 rest doctrine driver symfony dbal

是否可以将REST API用作Doctrine数据库?

关于http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/configuration.html上的配置,我可以更改“ driver”属性。

但是在允许的驱动程序列表中,没有人可以使用REST API。

我想做的是:

<?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
Run Code Online (Sandbox Code Playgroud)

谢谢您的回答!!

Tob*_*ias 5

DoctrineRestDriver正是在做您想要的!

https://github.com/CircleOfNice/DoctrineRestDriver

玩得开心!