承接 guglielmopepe/rings 相关项目开发

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

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

guglielmopepe/rings

最新稳定版本:2.0.1

Composer 安装命令:

composer require guglielmopepe/rings

包简介

A package for pipeline, macro and middleware

README 文档

README

Rings allows you to create and dispatch sequential, decorable, filterable and/or composable pipelines.

Table of Contents

Benefits

  • Be highly composable.
  • Be immutable.

Features

Rings are implemented as immutable chains. When you enqueue a new decorator, a new stage will be created with the added decorator.

You can enqueue decorators that add functionality to the pipeline. You can enqueue decorators that filter the operations to be done on data. You can enqueue decorators which add sub pipelines.

This makes pipelines easy to reuse, highly composable, and minimizes side-effects.

Prerequisites

  • PHP 7.2.0

Yes, that's the only hard requirement.

Installation

Use Composer

$ composer require guglielmopepe/rings

Usage

// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 1 <br />';return $data;}));
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 2 <br />';return $data;}));
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 3 <br />';return $data;}));

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data([]));

Documentation

Create pipeline like macro

// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        return new \Rings\Classes\Data(['foo' => '***' . $data['foo'] . '***']);
    })
);

$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        return new \Rings\Classes\Data(['foo' => '___' . $data['foo'] . '___']);
    })
);

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => 'bar']));


// print ___***bar***___
echo $data['foo'];

Create pipeline with filter

// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        if (strpos($data['foo'], '***') !== FALSE)
        {
            return $data;
        }

        return new \Rings\Classes\Data(['foo' => '***' . $data['foo'] . '***']);
    })
);

$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        if (strpos($data['foo'], '___') !== FALSE)
        {
            return $data;
        }

        return new \Rings\Classes\Data(['foo' => '___' . $data['foo'] . '___']);
    })
);

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => 'bar']));


// print ___***bar***___
echo $data['foo'];

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => '***bar***']));


// print ***bar***
echo $data['foo'];

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => '___bar___']));


// print ***bar***
echo $data['foo'];

Support

If you have a request, please create a GitHub issue.

If you discover a security vulnerability, please send an email to Guglielmo Pepe at info@guglielmopepe.com. All security vulnerabilities will be promptly addressed.

Faq

To do

Contributing

If you want to say thank you and/or support the active development of Rings:

  1. Add a GitHub Star to the project.
  2. Share the project on social media.
  3. Write a review or tutorial on Medium, Dev.to or personal blog.

Contacts

If you need information please send an email to info@guglielmopepe.com.

Roadmap

See the list of open issues:

Change log

Please see Changelog file for more information on what has changed recently.

License

Distributed under the MIT License. Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-30