承接 shipmonk/doctrine-hint-driven-sql-walker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

shipmonk/doctrine-hint-driven-sql-walker

最新稳定版本:2.0.2

Composer 安装命令:

composer require shipmonk/doctrine-hint-driven-sql-walker

包简介

Doctrine's SqlWalker that allows hooking multiple handlers via ->setHint() while each can edit produced SQL or its part.

README 文档

README

Since Doctrine's SqlWalker serves as a translator from DQL AST to SQL, it becomes problematic when you want to alter resulting SQL within multiple libraries by such approach. There just can be only single SqlWalker.

This library solves this issue, by providing HintHandler base class which is designed for SQL modification and can be used multiple times in $queryBuilder->setHint().

Installation:

composer require shipmonk/doctrine-hint-driven-sql-walker

Usage:

$queryBuilder
    ->getQuery()
    ->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, HintDrivenSqlWalker::class)
    ->setHint(MaxExecutionTimeHintHandler::class, 1000)

Where MaxExecutionTimeHintHandler just extends our HintHandler and picks some SqlNode to hook to and alters appropriate SQL part:

class MaxExecutionTimeSqlWalker extends HintHandler
{

    public function getNodes(): array
    {
        return [SqlNode::SelectClause];
    }

    public function processNode(
        SqlNode $sqlNode,
        string $sql,
    ): string
    {
        // grab the 1000 passed to ->setHint()
        $milliseconds = $this->getHintValue();

        // edit SQL as needed
        return preg_replace(
            '~^SELECT (.*?)~',
            "SELECT /*+ MAX_EXECUTION_TIME($milliseconds) */ \\1 ",
            $sql
        );
    }

SqlNode is an enum of all walkXxx methods in Doctrine's SqlWalker, so you are able to intercept any part of AST processing the SqlWalker does.

Limitations

  • Please note that since doctrine/orm 3.3.0, the produced SQL gets finalized with LIMIT / OFFSET / FOR UPDATE after SqlWalker processing is done.
    • Thus, implementors should be aware that those SQL parts can be appended to the SQL after HintHandler processing.
    • This means that e.g. placing a comment at the end of the SQL breaks LIMIT functionality completely

Implementors

Compatibility

Version PHP Compatibility doctrine/orm
v1 7.2 - 8.3 2.x
v2 8.1 - 8.4 3.x

统计信息

  • 总下载量: 218.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固