Skip to content

Commit

Permalink
Documentation OK
Browse files Browse the repository at this point in the history
  • Loading branch information
davispeixoto committed Jan 23, 2019
1 parent fc64efc commit 0a77959
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ composer.phar
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock
/.php_cs.cache
109 changes: 108 additions & 1 deletion README.md
@@ -1,4 +1,111 @@
# Workflow
A PHP package for dealing with state transitions
A PHP package for dealing with state transitions.

[![Latest Stable Version](https://img.shields.io/packagist/v/davispeixoto/workflow.svg)](https://packagist.org/packages/davispeixoto/workflow)
[![Total Downloads](https://img.shields.io/packagist/dt/davispeixoto/workflow.svg)](https://packagist.org/packages/davispeixoto/workflow)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/davispeixoto/workflow/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/davispeixoto/workflow/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/davispeixoto/workflow/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/davispeixoto/workflow/?branch=master)
[![Build Status](https://travis-ci.org/davispeixoto/workflow.svg?branch=master)](https://travis-ci.org/davispeixoto/workflow)

State transitions are a good way to manage lifecycles and pipelines
on applications, as for example:

- Order and payment status on an e-commerce
- Invoice Status on a finance system
- Ticket Status on ticket service desk system
- Sales status on a CRM

## Installation
The workflow package can be installed via [Composer](http://getcomposer.org) by requiring the
`davispeixoto/workflow` package in your project's `composer.json`.

```json
{
"require": {
"davispeixoto/workflow": "~1.0"
}
}
```

Or

```sh
$ php composer.phar require davispeixoto/workflow
```

And running a composer update from your terminal:
```sh
php composer.phar update
```

## Usage
To use it, first you need to create the status you are going to use
for representing your states.

```php
<?php
use MyCLabs\Enum\Enum;

class SalesStates extends Enum
{
public const NEW = 'new';
public const DEALING = 'dealing';
public const WON = 'won';
public const LOST = 'lost';
}
```

Then you can create your workflow based on valid transitions

```php
<?php
use Davispeixoto\Workflow\Transition;
use Davispeixoto\Workflow\Workflow;

class SalesWorkflow extends Workflow
{
public function __construct(SalesStates $initialStatus)
{
parent::__construct($initialStatus);

// setup the transitions
$transitions = [];

$transitions[] = new Transition(
new SalesStates(SalesStates::NEW),
new SalesStates(SalesStates::DEALING)
);

$transitions[] = new Transition(
new SalesStates(SalesStates::DEALING),
new SalesStates(SalesStates::WON)
);

$transitions[] = new Transition(
new SalesStates(SalesStates::DEALING),
new SalesStates(SalesStates::LOST)
);

$this->allowedTransitions = $transitions;

// setup the finished status, if any/needed
$finished = [];

$finished[] = new SalesStates(SalesStates::WON);
$finished[] = new SalesStates(SalesStates::LOST);

$this->finishedStatus = $finished;
}
}
```

Now you can use this workflow to manage state transitions on you applications.

## License
This software is licensed under the [MIT license](http://opensource.org/licenses/MIT)

## Versioning
This project follows the [Semantic Versioning](http://semver.org/)

## Thanks
For all PHP community
3 changes: 1 addition & 2 deletions tests/auxiliary/SalesWorkflow.php
Expand Up @@ -10,11 +10,10 @@

use Davispeixoto\Workflow\Transition;
use Davispeixoto\Workflow\Workflow;
use MyCLabs\Enum\Enum;

class SalesWorkflow extends Workflow
{
public function __construct(Enum $initialStatus)
public function __construct(SalesStates $initialStatus)
{
parent::__construct($initialStatus);

Expand Down

0 comments on commit 0a77959

Please sign in to comment.