sergeil/doctrine-array-query-builder-bundle

提供了一种使用标准PHP数组表示法构建查询的替代方法

dev-develop 2017-01-03 06:54 UTC

This package is auto-updated.

Last update: 2024-09-06 09:12:32 UTC


README

使用此捆绑包,您将能够使用简单的PHP关联数组表示法构建复杂的DQL查询,这样查询的编写将变得更加简单,需要从UI构建查询的分析应用程序将特别受益(捆绑包开箱即支持ExtJs框架使用的客户端/服务器通信协议)。

预告

假设我们有一个经典的用户和组实体,它们作为多对多相关联,并且用户实体与配置文件实体有一个一对一的关联,这样一个示例查询可能看起来是这样的

$query = array(
    'filter' => [
        // if the property is OneToMany relation and IN query is used the MEMBER OF query will be built automatically
        array('property' => 'groups', 'value' => 'in:1,2,3'),
        array('property' => 'username', 'value' => 'like:John%'),
        // this will automatically build proper JOINS under the hood
        array('property' => 'profile.insurance.securityNumber', 'value' => 'isNull')
    ],
    'fetch' => [
        // this will inform array query builder that you want to have associated Profile and then Insurance entities
        // to be fetched as well
        'profile.insurance'
    ],
    'sort' => [
        array('property' => 'id', 'direction' => 'DESC')
    ],
    'page' => 1,
    'limit' => 25
);

/* @var \Sli\DoctrineArrayQueryBuilderBundle\Querying\ArrayQueryBuilder $aqb */
$aqb = $container->get('sli_doctrine_array_query_builder.querying.array_query_builder');

// Only those users will be returned:
// 1. belong to groups with IDS 1, 2 and 3
// 2. whose `username`s contain John
// 3. whose associated Insurance entity's securityNumber is NULL
// Result will be ordered by ID field and paginated
$users = $aqb->buildQuery('MyCompany\MyBundle\Entity\User', $query);

有关所有支持的功能,请参阅位于Tests/Functional/Querying/ArrayQueryBuilderTest.php的功能测试。

支持的过滤运算符

  • eq
  • neq
  • like
  • notLike
  • gt
  • gte
  • lt
  • lte
  • in
  • notIn
  • isNull
  • isNotNull

安装

将此依赖项添加到您的composer.json中

"sergeil/doctrine-array-query-builder-bundle": "dev-develop"

更新您的AppKernel类并添加以下内容

new \Sli\DoctrineArrayQueryBuilderBundle\SliDoctrineArrayQueryBuilderBundle(),

许可

此捆绑包采用MIT许可。有关完整的许可信息,请参阅捆绑包中的Resources/meta/LICENSE。