Package Data | |
---|---|
Maintainer Username: | paolooo |
Maintainer Contact: | oo70vd@gmail.com (Nino Paolo Amarillento) |
Package Create Date: | 2015-02-13 |
Package Last Update: | 2015-04-30 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:08:04 |
Package Statistics | |
---|---|
Total Downloads: | 57 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
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. :)
$ 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>
<?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();
$em = \App::make('Doctrine\ORM\EntityManager');
...
$em->on('read')->persist($user);
$em->on('read')->flush();
$em->on('eventStore')->persist($user);
$em->on('eventStore')->flush();
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
See examples/
directory.
.env
and phpunit.xml
files.User
entity class, see Acme/Domain/Model/Entity/User.php
file.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