tourze/doctrine-function-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

English | 中文

Latest Version Total Downloads PHP Version License Tests Code Coverage

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

  1. Register the bundle in your Symfony application:
// config/bundles.php
return [
    // ...
    Tourze\DoctrineFunctionBundle\DoctrineFunctionBundle::class => ['all' => true],
];
  1. 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 JSON
  • JSON_SEARCH - Search within JSON data
  • JSON_ARRAY - Create JSON arrays
  • JSON_CONTAINS - Check if JSON contains value
  • JSON_LENGTH - Get JSON length
  • ANY_VALUE - Get any value from group
  • FIELD - Find field position
  • FIND_IN_SET - Find value in comma-separated list
  • IFELSE - Conditional expression
  • DATEDIFF - Date difference
  • RAND - Random string value

Datetime Functions

  • DAY - Extract day from date
  • MONTH - Extract month from date
  • YEAR - Extract year from date
  • HOUR - Extract hour from datetime
  • MINUTE - Extract minute from datetime
  • WEEK - Extract week from date
  • WEEKDAY - Extract weekday from date

Numeric Functions

  • ACOS, ASIN, ATAN, ATAN2 - Trigonometric functions
  • COS, SIN, TAN - Trigonometric functions
  • DEGREES, RADIANS - Angle conversion
  • EXP, LOG, LOG10, LOG2 - Logarithmic functions
  • POWER, SQRT - Power functions
  • CEIL, FLOOR, ROUND - Rounding functions
  • PI, RAND - Mathematical constants and random
  • BIT_COUNT, BIT_XOR - Bit operations
  • STDDEV, 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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-19