luxifer / doctrine-functions

📚 Set of DQL Function for MySQL
http://luxifer.github.io/doctrine-functions/
MIT License
88 stars 14 forks source link
doctrine dql-functions mysql php

Doctrine Functions

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads

This package contains doctrine functions, you can contribute by forking it and propose pull request with your own functions. List of available functions:

Edit this file in your pull request to add your functions to the list.

Requirements

This library is expected to work with PHP >= 5.3, but you should consider to upgrade to PHP >= 7.0. To contribute to this library you must have PHP >= 7.0 to run the test suite.

Installation

Just add the package to your composer.json

{
    "require": {
        "luxifer/doctrine-functions": "^1.5"
    }
}

Integration

1) Doctrine Only

According to the Doctrine documentation you can register the functions in this package this way.

<?php
$config = new \Doctrine\ORM\Configuration();
$config->addCustomDatetimeFunction('date', 'Luxifer\DQL\Datetime\Date');

$em = EntityManager::create($dbParams, $config);

2) Using Symfony 2

With Symfony 2 you can register your functions directly in the config.yml file.

doctrine:
    orm:
        entity_managers:
            default:
                dql:
                    datetime_functions:
                        date:     Luxifer\DQL\Datetime\Date
                        datediff: Luxifer\DQL\Datetime\DateDiff
                        # etc