PHPackages                             weavora/doctrine-extensions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. weavora/doctrine-extensions

ActiveLibrary[Database &amp; ORM](/categories/database)

weavora/doctrine-extensions
===========================

Doctrine2 ORM Extensions

0.1.0(12y ago)12172MITPHPPHP &gt;=5.3.3

Since Aug 21Pushed 12y ago7 watchersCompare

[ Source](https://github.com/weavora/doctrine-extensions)[ Packagist](https://packagist.org/packages/weavora/doctrine-extensions)[ RSS](/packages/weavora-doctrine-extensions/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Doctrine2 Extensions [![Build Status](https://camo.githubusercontent.com/d09ca8351b32834fe04a8c655586b780758b38f6ed87de91e18c83957eff8bb2/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f776561766f72612f646f637472696e652d657874656e73696f6e732e706e67)](http://travis-ci.org/weavora/doctrine-extensions)
======================================================================================================================================================================================================================================================================================================================

[](#doctrine2-extensions-)

[![Total Downloads](https://camo.githubusercontent.com/12f4edff2526ea3ead8d5d87e533722da8bb6afa18e214060d7432ffb2d2da04/68747470733a2f2f706f7365722e707567782e6f72672f776561766f72612f646f637472696e652d657874656e73696f6e732f646f776e6c6f6164732e706e67)](https://packagist.org/packages/weavora/doctrine-extensions)[![Latest Stable Version](https://camo.githubusercontent.com/f9d192765cddd8de7a1b7ae39e5c335decd5cb02bf8160c8845348b1cc85b25d/68747470733a2f2f706f7365722e707567782e6f72672f776561766f72612f646f637472696e652d657874656e73696f6e732f762f737461626c652e706e67)](https://packagist.org/packages/weavora/doctrine-extensions)

This library extends Doctrine2 base classes with some useful things.

Installation
------------

[](#installation)

This library may be installed using Composer or by cloning it from its GitHub repository. These options are described below.

**Composer**

You can read more about Composer and its main repository on [http://packagist.org](http://packagist.org "Packagist"). To install these doctrine extensions using Composer, first install Composer for your project using the instructions on the Packagist home page. You can then define your development dependency on doctrine-extensions using the parameters suggested below. While every effort is made to keep the master branch stable, you may prefer to use the current stable version tag instead.

```
{
    "require-dev": {
        "weavora/doctrine-extensions": "dev-master@dev"
    }
}

```

To install, you may call:

```
composer.phar install

```

**Git / GitHub**

The git repository hosts the development version in its master branch. You can install it using Composer by referencing dev-master as your preferred version in your project's composer.json file as the previous example shows.

You may also install this development version:

```
git clone git://github.com/weavora/doctrine-extensions.git
cd doctrine-extensions

```

The above processes will install library to the doctrine-extensions folder.

ORM Extensions
--------------

[](#orm-extensions)

Doctrine advices to use entity repositories that will contain business logic related to entities retrieval. Most probably, you will use a query builder inside the repository to build DQL. The issue is that a standard query builder has quite general API and doesn't provide such useful shortcuts like named scopes, a single method to apply custom criteria with parameters, etc.

This library is intended to fix what's missing and make your life a little bit easier.

### How to organize repositories

[](#how-to-organize-repositories)

Let's say you want to create a blog application. You'll probably create a post entity which will have references to the category, author and comments. And now you're thinking about an approach to organize your repositories.

Common issues with repositories:

- You have to duplicate code as soon as you have duplicated conditions
- Even simple methods with few conditions and ordering look massive

You can solve the first issue with a custom query builder per entity. It will also hide your criteria details from the repository that doesn't really need to know that.

To solve the issue with huge and not very descriptive methods, you'll create an extension for the query builder with some helpful shortcuts to make code more readable.

An example of how PostQueryBuilder &amp; PostRepository could look like:

```
