Skip to content

Commit

Permalink
Merge b31ffcd into 57835ee
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowhand committed Jun 5, 2018
2 parents 57835ee + b31ffcd commit 1b080d5
Show file tree
Hide file tree
Showing 27 changed files with 352 additions and 131 deletions.
16 changes: 3 additions & 13 deletions .travis.yml
@@ -1,26 +1,17 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

sudo: false
- 7.2

cache:

directories:
- $HOME/.composer/cache

matrix:
fast_finish: true

before_install:
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then mv phpspec.no-coverage.yml phpspec.yml; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then mv phpspec.no-coverage.yml phpspec.yml; fi
- if [ "$TRAVIS_PHP_VERSION" == "hhvm" ]; then mv phpspec.no-coverage.yml phpspec.yml; fi

install:
- travis_retry composer install

Expand All @@ -29,5 +20,4 @@ script:

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- if [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.xml; fi
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.xml; fi
- php ocular.phar code-coverage:upload --format=php-clover coverage.xml
12 changes: 12 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,17 @@
# Changelog

## 1.0.0 - ???

### Added

* Add strict typing.

### Changed

* Now requires PHP 7.1 or newer.
* Pipeline requires processor as first argument.
* Processor requires payload as first argument.

## 0.3.0 - 2016-10-13

* A pipeline now has a processor which is responsible for the stage invoking.
Expand Down
3 changes: 2 additions & 1 deletion README.md
@@ -1,6 +1,7 @@
# League\Pipeline

[![Author](http://img.shields.io/badge/author-@frankdejonge-blue.svg?style=flat-square)](https://twitter.com/frankdejonge)
[![Author](https://img.shields.io/badge/author-@frankdejonge-blue.svg?style=flat-square)](https://twitter.com/frankdejonge)
[![Maintainer](https://img.shields.io/badge/maintainer-@shadowhand-blue.svg?style=flat-square)](https://twitter.com/shadowhand)
[![Build Status](https://img.shields.io/travis/thephpleague/pipeline/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/pipeline)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/pipeline.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/pipeline/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/pipeline.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/pipeline)
Expand Down
14 changes: 10 additions & 4 deletions composer.json
Expand Up @@ -8,7 +8,13 @@
"authors": [
{
"name": "Frank de Jonge",
"email": "info@frenky.net"
"email": "info@frenky.net",
"role": "Author"
},
{
"name": "Woody Gilk",
"email": "woody.gilk@gmail.com",
"role": "Maintainer"
}
],
"autoload": {
Expand All @@ -22,13 +28,13 @@
}
},
"require": {
"php": ">=5.5"
"php": ">=7.1"
},
"scripts": {
"test": "phpspec run"
},
"require-dev": {
"phpspec/phpspec": "^2.2",
"henrikbjorn/phpspec-code-coverage": "^1.0"
"phpspec/phpspec": "^4.3",
"leanphp/phpspec-code-coverage": "^4.2"
}
}
1 change: 1 addition & 0 deletions docs/.gitignore
@@ -0,0 +1 @@
_site
1 change: 1 addition & 0 deletions docs/CNAME
@@ -0,0 +1 @@
pipeline.thephpleague.com
8 changes: 8 additions & 0 deletions docs/_data/images.yml
@@ -0,0 +1,8 @@
# Path to project specific favicon.ico, leave blank to use default
favicon:

# Path to project specific apple-touch-icon-precomposed.png, leave blank to use default
apple_touch:

# Path to project logo
logo:
4 changes: 4 additions & 0 deletions docs/_data/menu.yml
@@ -0,0 +1,4 @@
Getting Started:
Introduction: '/'
Installation: '/installation/'
Usage: '/usage/'
5 changes: 5 additions & 0 deletions docs/_data/project.yml
@@ -0,0 +1,5 @@
title: Pipeline
tagline: Composable sequental operations
description: Pipeline Pattern implementation for PHP.
google_analytics_tracking_id:
base_href: https://pipeline.thephpleague.com/
102 changes: 102 additions & 0 deletions docs/_layouts/default.html
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% if page.url == '/' %}
<title>{{ site.data.project.title }} - {{ site.data.project.tagline }}</title>
{% else %}
<title>{{ page.title }} - {{ site.data.project.title }}</title>
{% endif %}
{% if site.data.project.description %}
<meta name="description" content="{{ site.data.project.description }}">
{% endif %}
{% if site.data.project.base_href %}
<base href="{{ site.data.project.base_href }}">
{% endif %}
{% if site.data.images.favicon %}
<link rel="icon" type="image/x-icon" href="{{ site.data.images.favicon }}" />
{% else %}
<link rel="icon" type="image/x-icon" href="https://theme.thephpleague.com/img/favicon.ico" />
{% endif %}
{% if site.data.images.apple_touch %}
<link rel="apple-touch-icon-precomposed" href="{{ site.data.images.apple_touch }}">
{% else %}
<link rel="apple-touch-icon-precomposed" href="https://theme.thephpleague.com/img/apple-touch-icon-precomposed.png">
{% endif %}
<link rel="stylesheet" href="https://theme.thephpleague.com/css/all.css">
</head>
<body>

<section class="all_packages">
<a href="https://thephpleague.com/">
<img src="https://theme.thephpleague.com/img/loep_logo.png" width="195" height="200" alt="The League of Extraordinary Packages">
</a>
<h2>Our Packages:</h2>
<ul>
<!-- Loaded via JavaScript -->
</ul>
</section>

<header>
<a class="logo" href="/">
{% if site.data.images.logo %}
<span class="icon">
<img src="{{ site.data.images.logo }}" width="50" height="40" alt="{{ site.data.project.title }} - {{ site.data.project.tagline }}">
</span>
{% endif %}
<span class="name">{{ site.data.project.title }}</span>
<span class="tagline">{{ site.data.project.tagline }}</span>
</a>
<a href="https://thephpleague.com/" class="league">
Presented by The League of Extraordinary Packages
</a>
</header>

<input type="checkbox" id="menu">
<label for="menu" onclick>
<div class="closed">&#9776; Menu</div>
<div class="open">&#9776; Hide Menu</div>
</label>

<main>
<menu>
{% for section in site.data.menu %}
<h2>{{ section[0] }}</h2>
<ul>
{% for link in section[1] %}
<li {% if page.url == link[1] %}class="selected"{% endif %}>
<a href="{{ link[1] }}">{{ link[0] }}</a>
</li>
{% endfor %}
</ul>
{% endfor %}
</menu>
<article>
{{ content }}
</article>
</main>

<footer>
<span>&copy; Copyright <a href="https://thephpleague.com">The League of Extraordinary Packages</a>.</span>
<span>Site design by <a href="https://reinink.ca">Jonathan Reinink</a>.</span>
</footer>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//theme.thephpleague.com/js/scripts.js"></script>
<script src="//theme.thephpleague.com/js/prism.js"></script>

{% if site.data.project.google_analytics_tracking_id %}
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','{{ site.data.project.google_analytics_tracking_id }}');ga('send','pageview');
</script>
{% endif %}

</body>
</html>
43 changes: 43 additions & 0 deletions docs/index.md
@@ -0,0 +1,43 @@
---
layout: default
permalink: /
title: Introduction
---

# League\Pipeline

[![Maintainer](https://img.shields.io/badge/author-@shadowhand-blue.svg?style=flat-square)](https://twitter.com/shadowhand)
[![Author](https://img.shields.io/badge/author-@frankdejonge-blue.svg?style=flat-square)](https://twitter.com/frankdejonge)
[![Build Status](https://img.shields.io/travis/thephpleague/pipeline/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/pipeline)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/pipeline.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/pipeline/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/pipeline.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/pipeline)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Packagist Version](https://img.shields.io/packagist/v/league/pipeline.svg?style=flat-square)](https://packagist.org/packages/league/pipeline)
[![Total Downloads](https://img.shields.io/packagist/dt/league/pipeline.svg?style=flat-square)](https://packagist.org/packages/league/pipeline)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/44ebfc4c-0e97-4b47-925e-b17de7ddce4f/mini.png)](https://insight.sensiolabs.com/projects/44ebfc4c-0e97-4b47-925e-b17de7ddce4f)

## Introduction

This package provides a plug and play implementation of
the Pipeline Pattern. It's an architectural pattern which
encapsulates sequential processes. When used, it allows you
to mix and match operation, and pipelines, to create new
execution chains. The pipeline pattern is often compared
to a production line, where each stage performs a certain
operation on a given payload/subject. Stages can act on,
manipulate, decorate, or even replace the payload.

If you find yourself passing results from one function to
another to complete a series of tasks on a given subject,
you might want to convert it into a pipeline.

## Goals

* Provide an implementations of the Pipeline Pattern.
* Be highly composable.
* Be immutable.

## Questions?

This package was created by [@frankdejonge](https://twitter.com/frankdejonge), currently maintained by [@shadowhand](https://twitter.com/shadowhand).

13 changes: 13 additions & 0 deletions docs/installation.md
@@ -0,0 +1,13 @@
---
layout: default
permalink: /installation/
title: Installation
---

# Installation

The recommended way to install this package, is through composer.

~~~bash
composer require league/pipeline
~~~
99 changes: 99 additions & 0 deletions docs/usage.md
@@ -0,0 +1,99 @@
---
layout: default
permalink: /usage/
title: Usage
---

# Using League\Pipeline

## Basic Example

~~~php
use League\Pipeline\Pipeline;

class TimesTwoStage
{
public function __invoke($payload)
{
return $payload * 2;
}
}

class AddOneStage
{
public function __invoke($payload)
{
return $payload + 1;
}
}

$pipeline = (new Pipeline)
->pipe(new TimeTwoStage)
->pipe(new AddOneStage);

// Returns 21
$pipeline->process(10);
~~~

## Re-usable Pipelines

Because the PipelineInterface is an extension of the StageInterface
pipelines can be re-used as stages. This creates a highly composable model
to create complex execution patterns while keeping the cognitive load low.

For example, if we'd want to compose a pipeline to process API calls, we'd create
something along these lines:

~~~php
$processApiRequest = (new Pipeline)
->pipe(new ExecuteHttpRequest) // 2
->pipe(new ParseJsonResponse); // 3

$pipeline = (new Pipeline)
->pipe(new ConvertToPsr7Request) // 1
->pipe($processApiRequest) // (2,3)
->pipe(new ConvertToResponseDto); // 4

$pipeline->process(new DeleteBlogPost($postId));
~~~

## Pipeline Builders

Because Pipelines themselves are immutable, pipeline builders are introduced to
facilitate distributed composition of a pipeline.

The PipelineBuilder's collect stages and allow you to create a pipelines at
any given time.

~~~php
use League\Pipeline\PipelineBuilder;

// Prepare the builder
$pipelineBuilder = (new PipelineBuilder)
->add(new LogicalStage)
->add(new AnotherStage)
->add(new LastStage);

// Build the pipeline
$pipeline = $pipelineBuilder->build();
~~~

## Exception handling

This package is completely transparent when dealing with exception. In no case
will this package catch an exception or silence an error. Exception should be
dealt with on a per-case basis. Either inside a __stage__ or at time when the
pipeline processes a payload.

~~~php
$pipeline = (new Pipeline)
->pipe(function () {
throw new LogicException();
});

try {
$pipeline->process($payload);
} catch(LogicException $e) {
// Handle the exception.
}
~~~
5 changes: 0 additions & 5 deletions phpspec.no-coverage.yml

This file was deleted.

3 changes: 2 additions & 1 deletion phpspec.yml.dist
Expand Up @@ -3,8 +3,9 @@ suites:
pipeline_suite:
namespace: League\Pipeline
psr4_prefix: League\Pipeline

extensions:
- PhpSpec\Extension\CodeCoverageExtension
LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension: ~

code_coverage:
format:
Expand Down

0 comments on commit 1b080d5

Please sign in to comment.