hacfi / object-bridge-bundle
Hacfi 对象桥接包
dev-master
2013-08-09 20:14 UTC
Requires
- php: >=5.3.3
- symfony/framework-bundle: ~2.2
This package is not auto-updated.
Last update: 2024-09-23 15:12:51 UTC
README
此包允许不同 Doctrine ORMs 和 ODMs 之间的关联。
此项目目前处于实验阶段,功能有限。它应该适用于 Doctrine ORM 到 Doctrine PHPCR ODM,反之亦然(不过不是 ORM 到 ORM 或 PHPCR ODM 到 PHPCR ODM)。
如果相关对象尚未由对象管理器加载,则会懒加载这些对象。
待办事项
- 通过注解进行映射
- 与 Doctrine ORM 实体之间的桥接
- 与 Doctrine PHPCR ODM 文档之间的桥接
- 在 composer.json 中指定正确的依赖项
- 使用 loadClassMetadata 事件来正确映射字段(这样您就不必自己添加字符串映射了)
- 添加对 XML 和/或 YAML 映射的支持
- 为 Doctrine 映射器创建一个注册表以使其可扩展(MongoDB ODM & CouchDB ODM)
- 验证映射并确保通过
type
指定的映射器可用
请注意,注解的使用声明必须是 "use Hacfi\Bundle\ObjectBridgeBundle\Mapping\ObjectBridge;",并且不允许别名,因为 Doctrine 的 SimpleAnnotationReader 不支持它。这可能在将来发生变化。
安装
app/AppKernel.php
new Hacfi\Bundle\ObjectBridgeBundle\HacfiObjectBridgeBundle(),
app/autoload.php
AnnotationRegistry::registerFile(__DIR__.'/../vendor/hacfi/object-bridge-bundle/Hacfi/Bundle/ObjectBridgeBundle/Mapping/ObjectBridge/Reference.php');
示例
/src/Hacfi/AppBundle/Entity/Product.php
<?php namespace Hacfi\AppBundle\Entity; use Hacfi\AppBundle\Document\ProductProperties; use Doctrine\ORM\Mapping as ORM; use Hacfi\Bundle\ObjectBridgeBundle\Mapping\ObjectBridge; /** * Product * * @ORM\Table(name="ecommerce_product") * @ORM\Entity() * @ORM\HasLifecycleCallbacks */ class Product implements ProductInterface { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; ... /** * @ORM\Column(name="properties", type="string", length=255, nullable=false) * * @ObjectBridge\Reference(type="phpcr", name="HacfiAppBundle:ProductProperties", manager="default") */ private $properties; }
/src/Hacfi/AppBundle/Document/ProductProperties.php
<?php namespace Hacfi\AppBundle\Document; use Hacfi\AppBundle\Entity\Product; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; use Hacfi\Bundle\ObjectBridgeBundle\Mapping\ObjectBridge; /** * ProductProperties * * @PHPCRODM\Document(referenceable=true) */ class ProductProperties { /** @PHPCRODM\Id(strategy="parent") */ protected $id; ... /** * @PHPCRODM\String * * @ObjectBridge\Reference(type="orm", name="HacfiAppBundle:Product", manager="default") */ protected $product; }