tourze / doctrine-function-bundle
A Symfony bundle that automatically registers custom Doctrine SQL functions from beberlei/doctrineextensions and tourze/doctrine-function-collection packages
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/tourze/doctrine-function-bundle
Requires
- beberlei/doctrineextensions: ^1.5.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- symfony/config: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/yaml: ^7.3
- tourze/bundle-dependency: 1.*
- tourze/doctrine-function-collection: 1.0.*
- tourze/symfony-dependency-service-loader: 1.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/phpunit-symfony-kernel-test: 1.0.*
- tourze/phpunit-symfony-unit-test: 1.*
This package is auto-updated.
Last update: 2025-11-01 16:24:58 UTC
README
A Symfony bundle that automatically registers custom Doctrine SQL functions from beberlei/doctrineextensions and tourze/doctrine-function-collection packages.
Features
- Zero Configuration: Automatically registers 40+ custom SQL functions
- Multiple Function Types:
- String functions (JSON_EXTRACT, ANY_VALUE, FIELD, FIND_IN_SET, etc.)
- Datetime functions (DAY, MONTH, YEAR, HOUR, MINUTE, etc.)
- Numeric functions (ACOS, SIN, TAN, POWER, RAND, etc.)
- JSON functions (JSON_ARRAY, JSON_CONTAINS, JSON_SEARCH, etc.)
- Symfony Integration: Seamlessly integrates with Doctrine ORM through compiler passes
- Production Ready: Fully tested and optimized for performance
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
Installation
composer require tourze/doctrine-function-bundle
Quick Start
- Register the bundle in your Symfony application:
// config/bundles.php return [ // ... Tourze\DoctrineFunctionBundle\DoctrineFunctionBundle::class => ['all' => true], ];
- Use the functions in your DQL queries:
use Doctrine\ORM\EntityManagerInterface; // JSON functions $query = $entityManager->createQuery(' SELECT u FROM App\Entity\User u WHERE JSON_EXTRACT(u.metadata, "$.role") = :role '); $query->setParameter('role', 'admin'); // String functions $query = $entityManager->createQuery(' SELECT p FROM App\Entity\Product p WHERE FIND_IN_SET(:category, p.categories) > 0 '); $query->setParameter('category', 'electronics'); // Datetime functions $query = $entityManager->createQuery(' SELECT o FROM App\Entity\Order o WHERE YEAR(o.createTime) = :year AND MONTH(o.createTime) = :month '); $query->setParameters(['year' => 2023, 'month' => 12]); // Numeric functions $query = $entityManager->createQuery(' SELECT p FROM App\Entity\Point p WHERE POWER(p.x, 2) + POWER(p.y, 2) < :radius '); $query->setParameter('radius', 100);
Available Functions
String Functions
JSON_EXTRACT- Extract data from JSONJSON_SEARCH- Search within JSON dataJSON_ARRAY- Create JSON arraysJSON_CONTAINS- Check if JSON contains valueJSON_LENGTH- Get JSON lengthANY_VALUE- Get any value from groupFIELD- Find field positionFIND_IN_SET- Find value in comma-separated listIFELSE- Conditional expressionDATEDIFF- Date differenceRAND- Random string value
Datetime Functions
DAY- Extract day from dateMONTH- Extract month from dateYEAR- Extract year from dateHOUR- Extract hour from datetimeMINUTE- Extract minute from datetimeWEEK- Extract week from dateWEEKDAY- Extract weekday from date
Numeric Functions
ACOS,ASIN,ATAN,ATAN2- Trigonometric functionsCOS,SIN,TAN- Trigonometric functionsDEGREES,RADIANS- Angle conversionEXP,LOG,LOG10,LOG2- Logarithmic functionsPOWER,SQRT- Power functionsCEIL,FLOOR,ROUND- Rounding functionsPI,RAND- Mathematical constants and randomBIT_COUNT,BIT_XOR- Bit operationsSTDDEV,VARIANCE- Statistical functions
Testing
Run tests from the project root:
vendor/bin/phpunit packages/doctrine-function-bundle/tests
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.