paolooo/laravel-doctrine
最新稳定版本:0.4.0
Composer 安装命令:
composer require paolooo/laravel-doctrine
包简介
Doctrine 2 for Laravel 5 Artisans
关键字:
README 文档
README
Run all doctrine commands easily using $ php artisan doctrine <command> <options>
This service will grab your laravel's configuration (db and cache) and automatically apply it to doctrine2 configurate, no more hassle configuration needed. :)
- Supports all Doctrine's command line.
- Supports multiple DB connection.
Installation
$ composer require "paolooo/laravel-doctrine":"0.4.*@dev"
Open and edit config/app.php configuration file, and add the following service provider code to the $providers array.
'Paolooo\LaravelDoctrine\LaravelDoctrineServiceProvider',
Edit .env file. Add the following doctrine config. For more information, of doctrine configuration, see, http://doctrine-orm.readthedocs.org/en/latest/reference/advanced-configuration.html.
# .env
...
DOCTRINE_PROXY_AUTOGENERATED=false
DOCTRINE_PROXY_NAMESPACE=Acme\Domain\Model\Proxy
DOCTRINE_PROXY_DIR=app/Domain/Model/Proxy
DOCTRINE_MAPPING_DIR=app/Domain/Model
# READ
READ_DB_DATABASE=cqrs_read_db
READ_DOCTRINE_PROXY_AUTOGENERATED=false
READ_DOCTRINE_PROXY_NAMESPACE=app\Query\Model\Proxy
READ_DOCTRINE_PROXY_DIR=app/Query/Model/Proxy
READ_DOCTRINE_MAPPING_DIR=app/Query/Model
This configuration is for testing environment. Edit phpunit.xml file.
# phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit ...>
....
<php>
...
<env name="DB_DRIVER" value="pdo_sqlite"/>
<env name="DB_DATABASE" value="storage/tests/db.sqlite"/>
<env name="READ_DB_DATABASE" value="storage/tests/db_read.sqlite"/>
</php>
</phpunit>
Usage
<?php
# Create new EntityManager
$em = \App::make('Doctrine\ORM\EntityManager');
# Saving user entity to a 'default' database connection
# you can use `$em->on('default')` as well.
$em->getRepository('Paolooo\Acme\Domain\Entity\User')->persist($user);
$em->flush();
# Saving user entity to a 'read' database
$em->on('read')
->getRepository('Paolooo\Acme\Domain\Entity\User')
->persist($user);
$em->on('read')->flush();
Multiple Connection
$em = \App::make('Doctrine\ORM\EntityManager'); ... $em->on('read')->persist($user); $em->on('read')->flush(); $em->on('eventStore')->persist($user); $em->on('eventStore')->flush();
Running Doctrine Commands
Sample artisan for doctrine.
$ php artisan doctrine
$ php artisan doctrine help orm:schema-tool:create
$ php artisan doctrine orm:schema-tool:create
$ php artisan doctrine orm:schema-tool:create --dump-sql
$ php artisan doctrine orm:schema-tool:update
$ php artisan doctrine orm:schema-tool:drop
Example
See examples/ directory.
- Sample config file, see
.envandphpunit.xmlfiles. - Sample
Userentity class, seeAcme/Domain/Model/Entity/User.phpfile. - Sample
ModelTestCase. This will get the setup doctrine for you. Sets$this->entityManager. Create and drop schema as well.
Learn doctrine here http://doctrine-orm.readthedocs.org/en/latest/tutorials/getting-started.html
TODO
- Migration
统计信息
- 总下载量: 57
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-13