2017 © Pedro Peláez
 

library active-doctrine

An active record implementation on top of the Doctrine DBAL.

image

glynnforrest/active-doctrine

An active record implementation on top of the Doctrine DBAL.

  • Saturday, December 19, 2015
  • by glynnforrest
  • Repository
  • 1 Watchers
  • 10 Stars
  • 516 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

Active Doctrine

An active record implementation on top of the Doctrine DBAL., (*1)

Build Status Packagist Software License, (*2)

Project goals

  • An active record implementation focusing on simplicity and ease of use.
  • Support for a large amount of database vendors by leveraging the DBAL.
  • A select-only query builder for selecting entities. Unlike the Doctrine query builder which is designed to cover a large amount of query possibilities, this builder has a small amount of methods that are safe from sql injection.

Installation

Add glynnforrest/active-doctrine to your composer.json file:, (*3)

{
    "require": {
        "glynnforrest/active-doctrine": "0.2.*"
    }
}

Quickstart

//create a Doctrine database connection to use
$config = [
    'driver' => 'pdo_mysql',
    'host' => 'localhost',
    'user' => 'user',
    'password' => 'password',
    'dbname' => 'app',
];

$conn = Doctrine\DBAL\DriverManager::getConnection($config);

// insert and update
$author = new App\Entity\Author($conn);

$author->name = 'Glynn';
$author->age = 102;

// insert
$author->save();

$author->age = 100;

// update
$author->save();

// selecting
// SELECT * FROM authors WHERE age > ?
$old_authors = Author::select($conn)
    ->where('age', '>', 100)
    ->execute();

foreach ($old_authors as $author) {
    echo $author->name;
    // books are loaded lazily
    // SELECT * FROM books WHERE authors_id = ?
    foreach ($author->books as $book) {
        echo $book->name;
        echo $book->page_count;
    }
}

// selecting with eager loading
// SELECT * FROM authors WHERE age > ?
// SELECT * FROM books WHERE id IN (?, ?, ?, ?) AND page_count > ?
$old_authors = Author::select($conn)
    ->where('age', '>', 100)
    ->with('books', function($s) {
        $s->where('page_count', '>', 100);
    })
    ->execute();

// deleting
$old_authors->delete();

There are many more features. Documentation and examples are in the docs/ folder., (*4)

Tests

As well as unit tests, there are functional tests which run against a real database connection. By default this uses an in-memory sqlite database, so will fail if the sqlite extension is not set up., (*5)

  • phpunit runs all tests.
  • phpunit --testsuite unit runs the unit tests only.
  • phpunit --testsuite functional runs the functional tests only.

Changing connection parameters

To change the database used in the functional tests, copy phpunit.xml.dist to a new file and set the db_* environment variables., (*6)

<phpunit>
  

  <php>
    <env name="db_driver" value="pdo_mysql" />
    <env name="db_user" value="root" />
    <env name="db_password" value="" />
    <env name="db_host" value="localhost" />
    <env name="db_name" value="active_doctrine_tests" />
    <env name="db_port" value="3306" />
  </php>

  
  <php>
    <env name="db_driver" value="pdo_sqlite" />
    <env name="db_path" value="active_doctrine_tests.db3" />
  </php>

  
  <php>
    <env name="db_driver" value="pdo_sqlite" />
    <env name="db_memory"/>
  </php>
</phpunit>

Make sure the target database exists, then run the tests with the new configuration., (*7)

phpunit -c mysql.xml, (*8)

License

MIT, see LICENSE for details., (*9)

Copyright 2014 Glynn Forrest, (*10)

The Versions

19/12 2015

dev-master

9999999-dev

An active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

13/02 2015

0.2.2

0.2.2.0

An active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

21/01 2015

0.2.1

0.2.1.0

An active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

13/12 2014

0.2.0

0.2.0.0

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

10/12 2014

dev-group-where

dev-group-where

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

04/12 2014

dev-repo

dev-repo

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

09/11 2014

dev-functional-tests

dev-functional-tests

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

08/11 2014

dev-sqlite

dev-sqlite

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

06/11 2014

0.1.4

0.1.4.0

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

03/11 2014

0.1.3

0.1.3.0

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

26/09 2014

0.1.2

0.1.2.0

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

03/09 2014

0.1.1

0.1.1.0

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest

02/09 2014

0.1.0

0.1.0.0

A minimal active record implementation on top of the Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Glynn Forrest