承接 opensolutions/doctrine2bridge-l5 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

opensolutions/doctrine2bridge-l5

Composer 安装命令:

composer require opensolutions/doctrine2bridge-l5

包简介

Adds the the power of Doctrine2 to Laravel 5 (with support for SQL logging and authentication)

README 文档

README

Doctrine2Bridge for Laravel 5

Adds the power of Doctrine2 to Laraval 5 (including authentication and SQL query logging support).

For Laravel4, see opensolutions/doctrine2bridge

Laravel's Eloquent ORM is nice for rapid development and the active model pattern. However there's little out there that can beat Doctrine2 when you need a more full-featured ORM.

This is an integration of Doctrine 2.x to Laravel 5.x as a composer package. Doctrine's EntityManager instance is accessible through a facade named D2EM and the cache is directly available via D2Cache.

Metadata is currently obtained via the XML driver. It should be easy to add additional drivers to this.

Authentication support is also included via a Auth/Doctrine2UserProvider class. Documentation on integrating this with Laravel's own authentication system can be found here.

Installation

Installation is the usual for Laravel packages. You can find a detailed worked version of how to install and test in the wiki.

Insert the following in the packages (require) section of your composer.json file and run an update (composer update):

"opensolutions/doctrine2bridge-l5": "2.4.*",

Generally speaking, we'll try and match our minor versions (2.4.x) with Doctrine's but you should always use the latest x version of this.

Add the service providers to your Laravel application in app/config/app.php. In the 'providers' array add:

'Doctrine2Bridge\Doctrine2CacheBridgeServiceProvider',
'Doctrine2Bridge\Doctrine2BridgeServiceProvider',

You'll need to publish and edit the configuration files:

./artisan vendor:publish --provider "Doctrine2Bridge\Doctrine2CacheBridgeServiceProvider"
./artisan vendor:publish --provider "Doctrine2Bridge\Doctrine2BridgeServiceProvider"

This should get you a fresh copy of the configuration files (d2bcache.php and db2doctrine.php) in the configs directory.

Now, edit these as well as setting Laravel5's own cache.php and database.php appropriately.

The default directory for Doctrine2's xml schema is database/xml. This can be configured in config/d2bdoctrine.php.

Documentation on integrating this with Laravel's own authentication system can be found here.

Usage

Four bindings are created which can be injected via Laravel's IoC in the standard manner:

  • Doctrine\ORM\EntityManagerInterface (which is an instance of Doctrine\ORM\EntityManager)
  • Doctrine\Common\Cache\Cache (which is an instance of the appropriate cache provider)
  • Doctrine\ORM\Mapping\ClassMetadataFactory (used in this package by the console generator commands)
  • Doctrine2Bridge\Support\Repository (used by the D2R facade, see below)

Three facades are provided - for the Doctrine2 cache, the entity manager and a convenience repository generator. These can be used as follows:

D2Cache::save( $key, $value );
D2Cache::fetch( $key );

D2EM::persist( $object );
D2EM::flush();
$users = D2EM::getRepository( 'Entities\User' )->findAll();

Typically we'd create and use a repository as follows:

$sample = D2EM::getRepository( '\Entities\SampleEntity' )->find(5);

Assuming d2bdoctrine.namespaces.models => 'Entities', then we can use the D2R facade in any of the following ways to achieve the same result:

$sample = D2R::r( 'SampleEntity' )->find(5);
$sample = D2R::r( 'Entities\SampleEntity' )->find(5);
$sample = D2R::r( 'SampleEntity', 'Entities' )->find(5);

More Detailed Usage

The configuration file by default expects to find XML schema definitions under database/xml. Let's say for example we have a single schema file called database/xml/Entities.SampleEntity.dcm.xml containing:

<?xml version="1.0"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Entities\SampleEntity" repository-class="Repositories\Sample">
        <id name="id" type="integer">
            <generator strategy="AUTO"/>
        </id>
        <field name="name" type="string" length="255" nullable="true"/>
    </entity>
</doctrine-mapping>

Assuming you've configured your database connection parameters in the config file and you're positioned in the base directory of your project, we can create the entities, proxies and repositories with:

./artisan d2b:generate:entities
./artisan d2b:generate:proxies
./artisan d2b:generate:repositories

There is also a handy shortcut for this:

./artisan d2b:generate:all

Read the output of these commands as they may need to be run twice.

We also bundle a full Doctrine2 CLI utilty so the above could also be done via:

./vendor/bin/d2b-doctrine2 orm:generate-entities database/
./vendor/bin/d2b-doctrine2 orm:generate-proxies
./vendor/bin/d2b-doctrine2 orm:generate-repositories database/

You can also (drop) and create the database with:

./artisan d2b:schema:drop --commit
./artisan d2b:schema:create --commit

And you can update and validate via:

./artisan d2b:schema:update --commit
./artisan d2b:schema:validate

Now you can add some data to the database:

$se = new Entities\SampleEntity;
$se->setName( rand( 0, 100 ) );
D2EM::persist( $se );
D2EM::flush();

And query it:

echo count( D2EM::getRepository( 'Entities\SampleEntity' )->findAll() );

I use the excellent Skipper to create and manage my XML schema files.

Convenience Function for Repositories

SQL Query Logging

This package includes an implementation of Doctrine\DBAL\Logging\SQLLlogger which times the queries and calls the Laravel Log facade to log the query execution times and the SQL queries.

This logger can be enabled in the configuration file.

## License

Like the Laravel framework itself, this project is open-sourced under the MIT license.

Inspiration

Based on my original package opensolutions/doctrine2bridge for Laravel4. Some additional inspiration when porting to Laravel5 from mitchellvanw/laravel-doctrine.

opensolutions/doctrine2bridge-l5 适用场景与选型建议

opensolutions/doctrine2bridge-l5 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 266 次下载、GitHub Stars 达 9, 最近一次更新时间为 2015 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「doctrine2」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 opensolutions/doctrine2bridge-l5 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 opensolutions/doctrine2bridge-l5 我们能提供哪些服务?
定制开发 / 二次开发

基于 opensolutions/doctrine2bridge-l5 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 266
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-07