定制 shipmonk/doctrine-query-checker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

shipmonk/doctrine-query-checker

最新稳定版本:0.1.0

Composer 安装命令:

composer require shipmonk/doctrine-query-checker

包简介

Doctrine Query AST validator

README 文档

README

Doctrine Query Tree Walker that perform additional checks on the query AST in addition to the default checks performed by Doctrine.

Currently it checks that the types of the parameters passed to the query are correct. For example the following will result in exception:

// throws: Parameter 'created_at' has no type specified in 3rd argument of setParameter(). Thus it is inferred as 'string', but it is compared with 'u.createdAt' which can only be compared with 'datetime_immutable'.
$this->entityManager->createQueryBuilder()
    ->select('u')
    ->from(User::class, 'u')
    ->where('u.createdAt < :created_at')
    ->setParameter('created_at', 'not a date')
    ->getQuery()
    ->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [QueryCheckerTreeWalker::class]);
    ->getResult();

If you want to log the exceptions instead of throwing them, you can pass a logger to the QueryCheckerTreeWalker:

QueryCheckerTreeWalker::setLogger($logger);

Installation

composer require shipmonk/doctrine-query-checker

Enabling for a specific query

use Doctrine\ORM\Query;
use ShipMonk\DoctrineQueryChecker\QueryCheckerTreeWalker;

$query = $this->entityManager->createQueryBuilder()
    ->select('u')
    ->from(User::class, 'u')
    ->getQuery()
    ->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [QueryCheckerTreeWalker::class]);

Enabling for all queries

use Doctrine\ORM\Query;
use ShipMonk\DoctrineQueryChecker\QueryCheckerTreeWalker;

$this->entityManager->getConfiguration()
    ->setDefaultQueryHint(Query::HINT_CUSTOM_TREE_WALKERS, [QueryCheckerTreeWalker::class]);

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-21