定制 halpdesk/perform 二次开发

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

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

halpdesk/perform

Composer 安装命令:

composer require halpdesk/perform

包简介

README 文档

README

Perform is a swiss army repository adapter. It provides functions such as find, get, all for your Model. It is built for systems with a lot of integrations where data comes from different sources. The package provides two classes which both needs to be implemented in order to set up one entity; a model class and a query class.

The library is build with Eloquent in mind. The model class mimics the Eloquent model and the query class mimics the Eloquent builder.

docs/perform.png

WIP

The library is a work in progres. See tests for implementation. A short example is given below:

Example

An example with two classes, the Person class and the PersonQuery class. In this example, the person data is located in a person.json.

Model class

use Halpdesk\Perform\Abstracts\Model;
use Halpdesk\Perform\Contracts\Model as ModelContract;

class Person extends Model implements ModelContract
{
    static public $query = PersonQuery::class;

    protected $fields = [
        'id',
        'name',
        'age',
        'birthDate',
    ];

    protected $casts = [
        'name'      => 'string',
        'age'       => 'integer',
        'birthDate' => 'datetime',
    ];

    protected $dates = [
        'birthDate',
    ];

    public $dateFormat = 'Y-m-d';
}

Query class

use Halpdesk\Perform\Abstracts\Query;
use Halpdesk\Perform\Contracts\Query as QueryContract;

class PersonQuery extends Query implements QueryContract
{
    protected $model = Person::class;

    public function load() : void
    {
        /*
         * Use any method to set the data: read from file, make HTTP call, query database, etc.
         * In this example, we use a json file which contains all person data
         */
        $data = json_file_to_array('./person.json');
        $this->setData(collect($data));
    }

    /*
     *  create(), update() and delete() must be implemented
     *  in this class in order to actually use those functions
     *
     *  it will not be covered in this simple example (yet).
     */
}

Data source (person.json)

[
    { "id": 1, "name": "Adam", "age": 37, "birthDate": "1982-11-02" },
    { "id": 2, "name": "Billy", "age": 26, "birthDate": "1993-05-28" },
    { "id": 3, "name": "Charlie", "age": 31, "birthDate": "1988-10-05" },
    { "id": 4, "name": "David", "age": 33, "birthDate": "1986-03-14" }
    { "id": 5, "name": "Billy", "age": 22, "birthDate": "1997-02-09" }
]

Method examples

Below is a few examples of what you can do with the model class. The query class is mostly abstracted/hidden (just as the Builder class in Laravel Eloquent).

    // Constructs a Person with data associated with id:1 from person.json
    $person = Person::find(1);

    // Return a collection with Persons named Billy from person.json
    $persons = Person::where("name", "Billy")->get();

    // Return a full collection with Persons constructed from person.json
    $all = Person::all();

    // Throws a ModelNotFoundException (since id:7 does not exist in the person loaded)
    $person = Person::findOrFail(7);

    // Convert the Person class to an array
    $personArray = Person::findOrFail(2)->toArray();

    // Create a new person -- this method calls the query class to attempt store the person in the data source (i.e. person.json)
    // But the create method must be implemented in the query class; if it is not, an `NotImplementedException` will be thrown
    $newPerson = Person::create([
        "name" => "Ester",
        "age" => 55,
        "birthDate" => "1964-07-02"
    ]);

    // Same as above, but creates a temporary object which is not meant to be stored in the data source
    $tempNewPerson = Person::make([
        "name" => "Ester",
        "age" => 55,
        "birthDate" => "1964-07-02"
    ]);

    // Other methods that needs to be implemented to work, or otherwise throw an `NotImplementedException`
    $person->save();
    $person->update();
    $person->delete();

Tests

Run tests with PHPUnit

halpdesk/perform 适用场景与选型建议

halpdesk/perform 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 halpdesk/perform 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-09-16