承接 kampernet/action-chain 相关项目开发

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

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

kampernet/action-chain

最新稳定版本:1.0.2

Composer 安装命令:

composer require kampernet/action-chain

包简介

Action chain helper classes for implementing commands

README 文档

README

This is a simple, dependency free implementation of the Command Pattern in PHP. Useful for creating an orchestration layer

Usage

This will create a group of Commands with a certain name.

    class RegisterAction extends ActionChain {

        public function __construct() {
            $this->add(new RegisterUserAction());
            $this->add(new SendWelcomeEmailAction());
        }

    }

These are the individual command examples

    class RegisterUserAction extends Command {

        private $request;
        private $response;

        public function execute($request, $response = null) {

            $this->request = $request;
            $this->response = $response;

            // eg: code to take the request data and persist the user
            // probably more likely to call a service or domain model method here.
        }

        public function undo() {

            // eg: code to "undo" anything this command would have done
        }
    }

Once your commands are built, you can just call them from the routes: ( example using Symfony's Request )

    Route::get('/register', function() {

        $response = new Response();
        $reg = new RegisterAction();
        if (!$reg->execute(Request::createFromGlobals(), $response)) {
            $reg->undo();
        }

        return $response;
    });

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-06-11