承接 devgroup/yii2-data-structure-tools 相关项目开发

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

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

devgroup/yii2-data-structure-tools

Composer 安装命令:

composer require devgroup/yii2-data-structure-tools

包简介

Data structure collections, helpers and utilities for yii2 ActiveRecord models(trees, sorts and etc.)

README 文档

README

TBD

WARNING: This extension is under active development. Don't use it in production!

Build Status codecov.io

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist devgroup/yii2-data-structure-tools "*"

or add

"devgroup/yii2-data-structure-tools": "*"

to the require section of your composer.json file.

Usage

TBD

Credits and inspiration sources

Search concept

for now it works only with STATIC VALUES property storage

Note, that search will work only with models with DevGroup\DataStructure\traits\PropertiesTrait trait and DevGroup\DataStructure\behaviors\HasProperties behavior connected. See how to connect (Russian for now)

Extension provides flexible system of search. Each property have configuration point that switches ability to use this property in search.

Basic search will be done in two ways:

  • common search against regular databases e.g.: mysql, mariadb etc;
  • elasticsearch indices search.

Main feature is that if you want to use elasticseatch, and defined it in the app config, but not still configure it your search will just work fine with auto fallback to simple mysql searching. And when your elasticsearch will be properly started search will be automatically switched for elasticseatch.

Preferred search mechanism you can define in the application configuration files, like this:

    'modules' => [
    ...
         'properties' => [
             'class' => 'DevGroup\DataStructure\Properties\Module',
             'searchClass' => \DevGroup\DataStructure\searchOld\elastic\Search::class,
             'searchConfig' => [
                 'hosts' => ['host1:9200', 'https://host2:9200'],
                 'watcherClass' => MyWatch::class,
             ]
                       
         ],
    ...
    ],
  • searchClass - class to be used for search. If omit - there will be no search configured,
  • searchConfig - array additional parameters to be applied for search object, except common search. For elastic search following special keys may be set:
    • hosts see hosts config,
    • watcherClass - you can use your own watcher for elsticsearch if needed.

If you want to start using elasticsearch, first of all you have to install and configure it.

Then, if you already have entries in your database you may want to generate and load start indices. For this run in console:

./yii properties/elastic/fill-index

This command will create indices for all properties that you allowed to search.

How to search

For now only available to perform filtering against properties static values

At any place you want

<?= \DevGroup\DataStructure\search\widgets\FilterFormWidget::widget([
    'modelClass' => \app\models\Page::class,
    'filterRoute' => ['/url/to/filter'],
    'config' => [
        'storage' => [
            EAV::class,
            StaticValues::class,
        ]
    ]
]) ?>

This will render basic filter form with all properties and values contained in the elasticsearch index

  • 'modelClass' - required param, any model class name you have in your app with assigned properties and their static values,
  • 'filterRoute' - required param, action attribute for rendered filter form,
  • 'config' - optional, additional array of config. Special key storage will be used for definition against what property storage search will be proceed. If you omit it search will be work only against StaticValues storage by default

In your controller

public function actionFilter()
{
  /** @var AbstractSearch $component */
  $search = \Yii::$app->getModule('properties')->getSearch();
  $config = ['storage' => [
      EAV::class,
      StaticValues::class,
    ]
  ];
  $modelIds = $search->filterByProperties(Page::class, $config, \Yii::$app->request->get('filter'));
  $dataProvider = new ActiveDataProvider([
      //provider config
  ]);
  //other stuff here
}
  • Page - any model class name you have in your app with assigned properties and their static values
  • $modelIds will contain all found model ids, according to selected property values in filter. Using them you can show anything you want,
  • '$config' - optional, additional array of config. Special key storage will be used for definition against what property storage search will be proceed. If you omit it search will be work only against StaticValues storage by default

Filtering logic

Filters uses both intersection and union operations while search.

Lets see, for example you have filter request like this:

[
    1 => [2,3],
    13 => [18,9,34]
]

First of all this means that we want to find products that has property values assigned with id 2,3 from property with id 1, and 18, 9, 34 from property with id 13.

What will filter do?

  • For now it will find all products with assigned values with ids IN(2,3);
  • then it will find all products with assigned values with ids IN(12,9,34);
  • and finally it will return to you result of intersection from both previous results.

How to extend and implement

For all Search and Watch mechanisms you can use your custom implementation.

Actually you can create and use your own database connection, e.g.: MongoDB, ArangoDB.

Or you can just use your custom Watch class for elasticsearch index actualization.

Both Search and Watch classes are implements according interfaces and extends abstract classes

  • DevGroup\DataStructure\search\interfaces\Search and DevGroup\DataStructure\search\base\AbstractSearch for Search
  • DevGroup\DataStructure\search\interfaces\Watch and DevGroup\DataStructure\search\base\AbstractWatch for Watch

Just extend your class from needed abstract class and define it in application config, like described upper.

If you are realizing custom index, you probably need to create own controller for first time index initialization, like DevGroup\DataStructure\commands\ElasticIndexController

Define your own Watch class in your own Search class if necessary.

Clearly created and defined Watch class will be automatically subscribed to according system events.

devgroup/yii2-data-structure-tools 适用场景与选型建议

devgroup/yii2-data-structure-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 995 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 devgroup/yii2-data-structure-tools 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 995
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 9
  • 依赖项目数: 10
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 7
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-07