radnan/rdn-doctrine
Composer 安装命令:
composer require radnan/rdn-doctrine
包简介
Zend Framework 2 Doctrine ORM bridge
README 文档
README
The RdnDoctrine ZF2 module is a simple bridge to the Doctrine ORM library.
How to install
-
Use
composerto require theradnan/rdn-doctrinepackage:$ composer require radnan/rdn-doctrine:1.* -
Activate the module by including it in your
application.config.phpfile:<?php return array( 'modules' => array( 'RdnDoctrine', // ... ), );
Dependencies
This module relies on the modules: RdnConsole, RdnDatabase, and RdnFactory.
How to use
Entity managers can be registered with the RdnDoctrine\EntityManagerManager service locator using the rdn_entity_managers configuration option.
<?php return array( 'rdn_entity_managers' => array( 'factories' => array(), 'invokables' => array(), ), );
You can also use the managers key to quickly generate an entity manager using simple configuration options:
<?php return array( 'rdn_entity_managers' => array( 'managers' => array( 'App' => array( /* configuration options */ ), ), ), );
Configuring an entity manager is as simple as that! Here we've configured an entity manager with the name App. Assuming our module name is also App the library will set you up with some sane defaults, all of which you can override.
By default, the manager will expect your entities to live inside the App\Entity namespace (or more generally <MANAGER-NAME>\Entity).
Controller plugin
Once an entity manager has been configured, you can access both the entity manager or entity repositories from your controller using the entity() plugin.
Since you can register multiple entity managers with different names, by default the plugin will fetch the entity manager with the same name as the module name:
namespace App\Controller; use App\Entity; class User { public function createAction() { $user = new Entity\User; $user->setEmail('pot@example.com'); $this->entity()->persist($user); $this->entity()->flush(); } }
In order to access an entity repository we call the same entity($name) plugin, only this time we provide an entity name:
namespace App\Controller; use App\Entity; class User { public function editAction() { $id = $this->params('user-id'); $user = $this->entity('User')->find($id); /** * Alternatively we can be more explicit and request the * User entity within the App module */ $user = $this->entity('App:User')->find($id); } }
The RdnDoctrine\EntityManager\AliasResolver service is used to resolve aliases when one is not provided. For example, if User is given instead of App:User.
Code completion
If you'd like to have code completion for this plugin, include the following in your AbstractController class:
namespace App\Controller; use Zend\Mvc\Controller\AbstractActionController; /** * @method \Doctrine\ORM\EntityRepository|\Doctrine\ORM\EntityManager entity(\string $name = null) Get the entity manager or a repository for given entity name. */ abstract class AbstractController extends AbstractActionController { }
Then, simply extend your controllers off of this abstract controller.
Console commands
The module also comes with a set of console commands to manage the database schema and generate proxies.
You can run vendor/bin/console to run and get help on the console commands in the doctrine: namespace.
Shared entities
Usually you will have one module that will contain all your common entities such as User entities etc. You will also register a single entity manager for your application with the same name as this module.
You will then create separate modules for each section of your site. Each module will depend on the entities provided by the common module in addition to providing its own. But all of the modules will use the single shared entity manager.
Let's say our common module is called App and we have another module called Foo. In this case the configuration for the Foo module would look like this:
<?php return array( 'rdn_entity_managers' => array( 'managers' => array( 'App' => array( 'table_prefixes' => array( 'Foo' => 'foo__', ), ), ), 'modules' => array( 'Foo' => 'App', ), ), );
This will add the entities provided by Foo (in the Foo\Entity namespace) to the App entity manager and instruct all plugins to use the App entity manager from within the Foo module.
namespace Foo\Controller; class Bar { public function editAction() { // We can now access the Foo entity repositories $bar = $this->entity('Bar')->find($id); // - OR - more explicitly $bar = $this->entity('Foo:Bar')->find($id); // We can also access the App entity repositories $user = $this->entity('User')->find($id); // - OR - more explicitly $user = $this->entity('App:User')->find($id); // We have access to the shared entity manager $this->entity()->flush(); } }
radnan/rdn-doctrine 适用场景与选型建议
radnan/rdn-doctrine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 59 次下载、GitHub Stars 达 0, 最近一次更新时间为 2013 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「zend」 「zf2」 「doctrine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 radnan/rdn-doctrine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 radnan/rdn-doctrine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 radnan/rdn-doctrine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LosLog provides some log utility
Kinikit - PHP Application development framework MVC component
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
EdpModuleLayouts is very simple Laminas module for making module-specific layouts insanely easy.
Polyfill for mb_ereg(), mb_eregi(), mb_ereg_match(), and mb_ereg_replace*() functions; primary use case is for mbstring on Windows 7.4+
Zend Framework module to leverage the symfony dependency injection container
统计信息
- 总下载量: 59
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-12-28