使用REST API坚持实体 [英] Persisting entities using a REST API

查看:159
本文介绍了使用REST API坚持实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关在Symfony2的一个项目,我需要能够坚持/检索而不是数据库使用的是外部的RESTful API实体。自从主义实体映射到一个数据库表中的行,我想这应该很容易创建从实体映射到外部API为好。然而,这是新的,我和我似乎无法找到这方面有任何的说明/教程。 (也许我失去了我的谷歌福正确的话)

For a project in Symfony2 I need to be able to persist / retrieve entities using an external RESTful API, instead of the database. Since Doctrine maps the entity to a row of a database table, I thought it should be easy to create a mapping from the entity to an external API as well. However, this is new for me and I can't seem to find any descriptions / tutorials about this. (perhaps I'm missing the right words for my Google-fu)

我希望有类似于主义的解决方案。我宁可不使用基于ActiveRecord的模式的东西,因为我想要的持久性逻辑,从实体分隔。实体不应该知道它是如何坚持着。

I was hoping there is a solution similar to Doctrine. I'd rather not use something based on the ActiveRecord pattern, because I want the persistance logic to be seperated from the Entities. The Entity shouldn't know how it is persisted.

我希望能够做同样的事情到这一点:

I want to be able to do something similar to this:

$entity = new Entity();

$em = $this->getREST()->getManager(); // get REST Entity Manager
$em->persist($entity); // save the entity using a POST request
$em->flush();

和这样的:

$em = $this->getREST()->getManager(); // get REST Entity Manager

// retrieve the entity using a GET request
$entity = $em->getRepository('AcmeDemoBundle:Entity')->find($id);

和这样的:

$em = $this->getREST()->getManager(); // get REST Entity Manager

// retrieve all entities using a GET request
$entities = $em->getRepository('AcmeDemoBundle:Entity')->findAll();

在换句话说,这将是很好,如果语法是几乎相同的原则的。

In other words, it would be nice if the syntax could be almost identical to Doctrine's.

此外,我想用在实体注释来配置映射在外部文件(YAML例如)代替。 (正如我所说的,实体不应该知道他们是如何坚持)

Furthermore, I'd like to configure the mapping in an external file (YAML for instance) instead of by annotations in the entity. (As I said, the entities shouldn't know how they are persisted)

Forgottenbas 已经提到了几个解决方案,但他们并不能完全满足我的要求,我会期望将有更多的解决方案,我敢肯定,我不是第一个谁也解决这个问题。

Forgottenbas has already mentioned a couple solutions, but they don't completely satisfy my requirements, and I'd expect there would be more solutions, as I'm sure I'm not the first one who has to tackle this problem.

任何人都可以点我在正确的方向?

Can anybody point me in the right direction?

推荐答案

大约一​​年前我试图找到答案同样的问题,没有运气,并创建自己的包。不幸的是,我不能分享它,因为它是专有的,不打算成为开源(量低的设置,专门为我们的企业API等制成)。但我可以给你一些链接

About one year ago I am trying to find the answer to same question with no luck and create own bundle. Unfortunately, I can not share it, because it's proprietary and not intended to be open-source (low amount of settings, made ​​specifically for our corporate API etc). But I can give you some links


  1. 目前开始有一个 JMS串行获得deserializtion +的为HTTP查询嗡嗡声。你可以用一些服务和作品进行包裹。

  1. At start there is a jms serializer for deserializtion + buzz for http queries. You can wrap it with some service and works done.

学说有些失落的解决方案称为缀满(教义休息)。

Doctrine has some lost solution called drest(doctrine rest).

此外,我发现了一些有趣的解决方案也被称为缀满。我不尝试使用它,因为它是相对比较新。 文档看起来pretty很好。

Also i found some interesting solution also called drest. I dont try to use it, since it is relatively newly. Documentation looks pretty well.

这篇关于使用REST API坚持实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆