承接 paliari/doctrine-ransack 相关项目开发

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

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

paliari/doctrine-ransack

Composer 安装命令:

composer require paliari/doctrine-ransack

包简介

Advanced query searching for Doctrine ORM (based on Ruby on Rails Ransack)

README 文档

README

Installation

$ composer require paliari/doctrine-ransack

Configuration

Your setup, example

<?php
use Paliari\Doctrine\Ransack;
use Paliari\Doctrine\RansackConfig;

$ransack = new Ransack(new RansackConfig($entityManager));

Usage

<?php
use Paliari\Doctrine\Ransack;
use Paliari\Doctrine\RansackConfig;
use Paliari\Doctrine\VO\RansackOrderByVO;
use Paliari\Doctrine\VO\RansackParamsVO;

$entityName = User::class;
$alias = 't';
$paramsVO = new RansackParamsVO();
$paramsVO->where = [
    'person.address.street_cont' => 'Av% Brasil',
    'or' => [
        'name_eq' => 'Jhon',
        'email_start' => 'jhon',
        'person.address.city_eq' => 'Maringá',
    ],
    'id_order_by' => 'asc',
];
$paramsVO->orderBy = [
    new RansackOrderByVO(['field' => 'person.name', 'order' => 'ASC']),
    new RansackOrderByVO(['field' => 'person.id', 'order' => 'DESC']),
];
$paramsVO->groupBy = [
    'person.name',
    'person.address_id',
];
$qb = $entityManager->createQueryBuilder()->from($entityName, $alias);
$ransackBuilder = $this->ransack
    ->query($qb, $entityName, $alias)
    ->includes()
    ->where($paramsVO);
$users = $ransackBuilder->getQuery()->getResult();

// Using includes
$includes = [
  'only' => ['id', 'email'],
  'include' => [
    'person' ['only' => ['id', 'name']],
  ],
];
$rows = $ransackBuilder->includes($includes)->getArrayResult();

Custom Association

Your class of get custom association

<?php

use Doctrine\ORM\Query\Expr\Join;
use Paliari\Doctrine\CustomAssociationInterface;
use Paliari\Doctrine\VO\RelationVO;
use Paliari\Doctrine\VO\JoinVO;
use Person;
use User;

class CustomAssociation implements CustomAssociationInterface
{
    public function __invoke(string $entityName, string $alias, string $field): ?RelationVO
    {
        if (User::class === $entityName && 'custom' == $field) {
            $relationVO = new RelationVO();
            $relationVO->entityName = $entityName;
            $relationVO->fieldName = $field;
            $relationVO->targetEntity = Person::class;
            $joinVO = new JoinVO();
            $joinVO->join = Person::class;
            $joinVO->alias = "{$alias}_$field";
            $joinVO->conditionType = Join::WITH;
            $joinVO->condition = "$alias.email = $joinVO->alias.email";
            $relationVO->join = $joinVO;

            return $relationVO;
        }

        return null;
    }
}

Setup with CustomAssociation

<?php
use Paliari\Doctrine\Ransack;
use Paliari\Doctrine\RansackConfig;

$customAssociation = new CustomAssociation();
$config = new RansackConfig($entityManager, $customAssociation);
$ransack = new Ransack($config);

$entityName = User::class;
$alias = 't';
$paramsVO = new RansackParamsVO();
$paramsVO->where = [
    'custom.email_eq' => 'your-email@gmail.com',
];
$includes = [
  'only' => ['id', 'email'],
  'include' => [
    'custom' ['only' => ['id', 'name']],
  ],
];
$qb = $entityManager->createQueryBuilder()->from($entityName, $alias);
$ransackBuilder = $this->ransack
    ->query($qb, $entityName, $alias)
    ->includes()
    ->where($paramsVO);
$users = $ransackBuilder->getQuery()->getResult();

Filters

The filters must be passed in a hash with the name of the key containing the field ending with the predicates below ex: person.name_eq, person.id_gt.

It is also possible to combine predicates within or or and clauses, eg:

$where = [
    'name_cont' => 'Jhon',
    'or' => [
        'person.name_start' => 'Jhon',
        'person.email_end' => '@gmail.com',
        'and' => [
            'person.address.city_eq' => 'Maringá',
            'person.address.state_eq' => 'PR',
        ],
    ],
];

List of all possible predicates

  • *_eq (equal)

    • Example:

      {"col_eq": "Fulano da Silva"}
    • SQL result:

      WHERE col = 'Fulano da Silva'
  • *_not_eq (not equal)

    • Example:

      {"col_not_eq": "Fulano da Silva"}
    • SQL result:

      WHERE col <> 'Fulano da Silva'
  • *_in (match any values in array)

    • Example:

      {"col_in": [13, 21, 124, 525]}
    • SQL result:

      WHERE col IN (13, 21, 124, 525)
  • *_not_in (match none of values in array)

    • Example:

      {"col_not_in": [13, 21, 124, 525]}
    • SQL result:

      WHERE col NOT IN (13, 21, 124, 525)
  • *_null (is null)

    • Example:

      {"col_null": null}
    • SQL result:

      WHERE col IS NULL
  • *_not_null (is not null)

    • Example:

      {"col_not_null": null}
    • SQL result:

      WHERE col IS NOT NULL
  • *_present (not null and not empty)

    Only compatible with string columns.

    • Example:

      {"col_present": 1}
    • SQL result:

      WHERE col IS NOT NULL AND col != ''
  • *_blank (is null or empty)

    Only compatible with string columns.

    • Example:

      {"col_blank": 1}
    • SQL result:

      WHERE col IS NULL OR col = ''
  • *_lt (less than)

    • Example:

      {"col_lt": 25}
    • SQL result:

      WHERE col < 25
  • *_lteq (less than or equal to)

    • Example:

      {"col_lteq": 25}
    • SQL result:

      WHERE col <= 25
  • *_gt (greater than)

    • Example:

      {"col_gt": 25}
    • SQL result:

      WHERE col > 25
  • *_gteq (greater than or equal to)

    • Example:

      {"col_gteq": 25}
    • SQL result:

      WHERE col >= 25
  • *_matches (matches with LIKE)

    • Example:

      {"col_matches": "Fulano"}
    • SQL result:

      WHERE col LIKE 'Fulano'
  • *_not_matches (does not match with LIKE)

    • Example:

      {"col_not_matches": "Fulano"}
    • SQL result:

      WHERE col NOT LIKE 'Fulano'
  • *_cont (contains value)

    • Example:

      {"col_cont": "Fulano"}
    • SQL result:

      WHERE col LIKE '%Fulano%'
  • *_not_cont (does not contain)

    • Example:

      {"col_not_cont": "Fulano Silva"}
    • SQL result:

      WHERE col NOT LIKE '%Fulano%Silva%'
  • *_start (starts with)

    • Example:

      {"col_start": "Fulano"}
    • SQL result:

      WHERE col LIKE 'Fulano%'
  • *_not_start (does not start with)

    • Example:

      {"col_not_start": "Fulano"}
    • SQL result:

      WHERE col NOT LIKE 'Fulano%'
  • *_end (ends with)

    • Example:

      {"col_end": "Fulano"}
    • SQL result:

      WHERE col LIKE '%Fulano'
  • *_not_end (does not end with)

    • Example:

      {"col_not_end": "Fulano"}
    • SQL result:

      WHERE col NOT LIKE '%Fulano'
  • *_between (between in 2 values)

    • Example:

      {"col_between": [10, 20]}
    • SQL result:

      WHERE col BETWEEN 10 AND 20

Authors

paliari/doctrine-ransack 适用场景与选型建议

paliari/doctrine-ransack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.91k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2016 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-15