alex-patterson-webdev/arp-orm-specification

There is no license information available for the latest version (v0.9) of this package.

v0.9 2015-06-15 22:28 UTC

README

An implementation of the Specification Pattern to create reusable DQL queries for Doctrine ORM.

Introduction

The specification pattern is an alternative approch to creating database queries using Doctrine ORM. The pattern decouples and hides the ORM's query builder implementation details from client code and reduces the need for numerious and repetative findBy* repository methods. Each specfification is a self contained and reusable object that can be chained with other specifications to easily produce complex DQL queries with a fluid, testable and easy to understand API.

Installation

Installtion via Composer package manager. Simply add the package name to your composer.json

php composer.phar require alex-patterson-webdev/arp-orm-specification : 0.9

Requirements

Standard Specifications

The standard specifications, which closley resemble the QueryBuilder's expression classes classes, represent the smallest possible components needed to creating a DQL query.

There are two main types of specifications

  • Comparison

Is used to compare one value with another.

  • CompositeSpecification

Two or more specifications combined together to form one single specification.

Theory

@todo

Specification Factory

Although all specifications are able to be created in line, the module also ships with a specification factory, ArpOrmSpecification\Service\OrmSpecificationFactory, which provides a simple API to create new specifications.

$sf = new \ArpOrmSpecification\Service\OrmSpecificationFactory();

$spec1 = $sf->isEqual('foo', 'bar');
$spec2 = new \ArpOrmSpecification\Entity\Spec\IsEqual('foo', 'bar');

Both $spec1 and $spec2 are both instances of the comparion specification IsEqual. When filtered both specifications produce identical DQL foo = 'bar'.

The factory reduces the boilerplate code needed when composing different specifications together.

$sf = new \ArpOrmSpecification\Service\OrmSpecificationFactory();

$spec = $sf->andX(
    $sf->orX(
        $sf->isNotNull('foo'),
        $sf->isGreaterThanOrEqualTo('bar', 123)
    ),
    $this->isEqual('name', 'bob')
);

Executing Queries

@todo

Binding Query Parameters

@todo

Debuging DQL

@todo

Custom Specifications

@todo

Complex dependancies

@todo