ygto/job-collector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ygto/job-collector

Composer 安装命令:

composer require ygto/job-collector

包简介

job collector to write more clean code

README 文档

README

don't mess around when handling too much process.

Installation

composer require ygto/job-collector

or

"require": {
    "ygto/job-collector": "^1.0"
}

JobCollector\Job

JobCollector\Job interface has 4 methods

  • handle() first handle method run.
  • rollback() if handle method throw exception then rollback method run.
  • onSuccess() if handle method run successfully then onSuccess run and keep the method's return ;
  • onError() if handle method throw exception then onError run and keep the method's return ;

JobCollector\Collector

JobCollector\Collector has 4 methods

  • push(\JobCollector\Job $job) push job to collector
  • handle() run pushed jobs if all jobs run successfully return true else return false
  • getSuccess() return onSuccess methods return
  • getError() return onError methods return

Usage

//GetPayment.php

<?php namespace Jobs;

use JobCollector\Job;

class GetPayment implements Job
{
    protected $user;
    protected $order;
    protected $payment;

    protected $success = 'payment handled successfully.';
    protected $error = 'there is a error in payment';

    public function __construct($user, $order, $payment)
    {
        $this->user = $user;
        $this->order = $order;
        $this->payment = $payment;
    }

    public function handle()
    {
        if (!$this->payment->getPayment($this->user, $this->order)) {
            //payment error setted;
            $this->error = $this->payment->getError();
            throw new \Exception($this->error);
        }
    }

    public function rollback()
    {
        $this->payment->refundPayment($this->user, $this->order);
    }

    public function onSuccess()
    {
        return $this->success;
    }

    public function onError()
    {
        return $this->error;
    }
}

//ExampleController.php

<?php

use JobCollector\Collector;
use Jobs\CheckUserBalance;
use Jobs\GetPayment;
use Jobs\PrintPayslip;

class ExampleController
{

    public function checkout(User $user, Order $order, Payment $payment, PdfLibrary $pdf)
    {
        $collector = new JobCollector\Collector();
        $collector->push(new CheckUserBalance($user, $order))
            ->push(new GetPayment($user, $order, $payment))
            ->push(new PrintPayslip($user, $order, $pdf));

        if ($collector->handle()) {
            //$collector->getSuccess();
        } else {
            //$collector->getError();
        }
    }
}

ygto/job-collector 适用场景与选型建议

ygto/job-collector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 586 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 ygto/job-collector 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-01-07