paolooo / laravel-doctrine by paolooo

Doctrine 2 for Laravel 5 Artisans
56
3
2
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: 2019-05-14 15:30:26
Package Statistics
Total Downloads: 56
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 3
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Doctrine 2 Service for Laravel 5+

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

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 .env and phpunit.xml files.
  • Sample User entity class, see Acme/Domain/Model/Entity/User.php file.
  • 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