定制 aambr/phpchain 二次开发

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

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

aambr/phpchain

最新稳定版本:1.1.1

Composer 安装命令:

composer require aambr/phpchain

包简介

README 文档

README

Set of classes that help to create chains of steps to minimize clutter in domain logic.

Install

composer require aambr/phpchain

Quick start

$dispatcher = new ChainDispatcher($dependencyInjectionContainer);
$dispatcher->chain('user.register')->define([
  'Steps\CreateUserStep', Steps\CreateProfileStep::class, 'sendWelcomeEmail'
]); // all of these will be resolved by dependency container unless 
    // there is a concrete ChainStep object ready
    
$dispatcher->chain('user.register')->dispatch()->execute(new \ArrayObject([
  'username' => 'valid-username',
  'email' => 'valid@email.com'
]));

ChainDispatcher accepts any depenendecy injection container which extends \ArrayObject to resolve each step depenendecy.

Divide and conquer

The goal is to devide complex domain logic into individual steps that can be reused in future processes. Create your own steps by inheriting ChainStep and implement logic in process(\ArrayObject $input).

Share variables between steps

Steps can share variables between each other by altering $input keys, which is possible because we are passing \ArrayObject instance reference instead an array which is passed by value. For example CreateUserStep after successful action can set $input['user'] = $createdUser, which then can be used by sendWelcomeEmail.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-08-11