tourze/doctrine-function-bundle
最新稳定版本:1.0.1
Composer 安装命令:
composer require tourze/doctrine-function-bundle
包简介
A Symfony bundle that automatically registers custom Doctrine SQL functions from beberlei/doctrineextensions and tourze/doctrine-function-collection packages
README 文档
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.
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-19