承接 api-skeletons/doctrine-criteria 相关项目开发

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

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

api-skeletons/doctrine-criteria

Composer 安装命令:

composer require api-skeletons/doctrine-criteria

包简介

Doctrine Criteria from Array Parameters

README 文档

README

Build Status Coverage Gitter Patreon Total Downloads

This library builds a Criteria object from array parameters for use in filtering collections.

Installation

Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.

$ composer require api-skeletons/doctrine-criteria

Once installed, add ApiSkeletons\Doctrine\Criteria to your list of modules inside config/application.config.php or config/modules.config.php.

laminas-component-installer

If you use laminas-component-installer, that plugin will install doctrine-criteria as a module for you.

Configuring the Module

Copy config/apiskeletons-doctrine-criteria.global.php.dist to config/autoload/apiskeletons-doctrine-criteria.global.php and edit the list of aliases for those you want enabled. By default all supported expressions are enabled.

Note AND and OR composite expressions are not supported yet.

Use

use Doctrine\Common\Util\ClassUtils;
use ApiSkeletons\Doctrine\Criteria\Builder as CriteriaBuilder;

$filterArray = [
    [
        'type' => 'eq',
        'field' => 'name',
        'value' => 'Grateful Dead',
    ],
    [
        'type' => 'beginswith',
        'field' => 'state',
        'value' => 'UT',
    ],
];

$orderByArray = [
    [
        'type' => 'field',
        'field' => 'venue',
        'direction' => 'asc',
    ]
];

$criteriaBuilder = $container->get(CriteriaBuilder::class);
$entityClassName = ClassUtils::getRealClass(get_class($collection->first()));
$metadata = $objectManager->getClassMetadata($entityClassName);
$criteria = $criteriaBuilder->create($metadata, $filterArray, $orderByArray);

$filteredCollection = $collection->matching($criteria);

Filters

Filters are not simple key/value pairs. Filters are a key-less array of filter definitions. Each filter definition is an array and the array values vary for each filter type.

Each filter definition requires at a minimum a 'type'. A type references the configuration key such as 'eq', 'neq', 'contains'.

Each filter definition requires at a minimum a 'field'. This is the name of a field on the target entity.

Each filter definition may specify 'where' with values of either 'and', 'or'.

Format of Date Fields

When a date field is involved in a filter you may specify the format of the date using PHP date formatting options. The default date format is ISO 8601 Y-m-d\TH:i:sP If you have a date field which is just Y-m-d then add the format to the filter. For complete date format options see DateTime::createFromFormat

[
    'format' => 'Y-m-d',
    'value' => '2014-02-04',
]

Included Filter Types

Equals:

Doctrine Collections does not currently support DateTime Equals comparisons. Any DateTime values sent through the equals filter will always return not equals. This is a shortcoming of doctrine/collections and not this module. Other comparison operators should work as expected.

['type' => 'eq', 'field' => 'fieldName', 'value' => 'matchValue']

Not Equals:

['type' => 'neq', 'field' => 'fieldName', 'value' => 'matchValue']

Less Than:

['type' => 'lt', 'field' => 'fieldName', 'value' => 'matchValue']

Less Than or Equals:

['type' => 'lte', 'field' => 'fieldName', 'value' => 'matchValue']

Greater Than:

['type' => 'gt', 'field' => 'fieldName', 'value' => 'matchValue']

Greater Than or Equals:

['type' => 'gte', 'field' => 'fieldName', 'value' => 'matchValue']

Contains:

Used to search inside of a string. Comlimentary with Starts With & Ends With, contains matches a string inside any part of the value.

['type' => 'contains', 'field' => 'fieldName', 'value' => 'matchValue']

Starts With:

['type' => 'startswith', 'field' => 'fieldName', 'value' => 'matchValue']

Ends With:

['type' => 'endswith', 'field' => 'fieldName', 'value' => 'matchValue']

Member Of:

Used to search inside an array field to match the matchValue to an array element.

['type' => 'memeberof', 'field' => 'fieldName', 'value' => 'matchValue']

In:

Note: Dates in the In and NotIn filters are not handled as dates. It is recommended you use other filters instead of these filters for date datatypes.

['type' => 'in', 'field' => 'fieldName', 'values' => [1, 2, 3]]

NotIn:

Note: Dates in the In and NotIn filters are not handled as dates. It is recommended you use other filters instead of these filters for date datatypes.

['type' => 'notin', 'field' => 'fieldName', 'values' => [1, 2, 3]]

IsNull:

Used to determine if the field is null. There is no corresponding IsNotNull.

['type' => 'isnull', 'field' => 'fieldName']

OrderBy

Field:

['type' => 'field', 'field' => 'fieldName', 'direction' => 'desc']

api-skeletons/doctrine-criteria 适用场景与选型建议

api-skeletons/doctrine-criteria 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 124 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「orm」 「doctrine」 「filter」 「criteria」 「laminas」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 api-skeletons/doctrine-criteria 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 api-skeletons/doctrine-criteria 我们能提供哪些服务?
定制开发 / 二次开发

基于 api-skeletons/doctrine-criteria 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-07-06