Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Apr 28, 2019
0 parents commit e0741b8
Show file tree
Hide file tree
Showing 29 changed files with 1,366 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## State

A state in state machine that can be verified whether can be transitioned to another state. State accepts unique ID and optional context

## Transitions

You can use 2 predefined transitions. Transition has one role to decide whether you can go from one state to another

* `StaticTransition` - which accepts FROM and TO states and boolean
* `CallableTransition` - which accepts FROM and TO states and callback. Callback is passed both states and must return boolean

## Example usage

```php
use Tlapnet\Stamus\State\State;
use Tlapnet\Stamus\StateMachineBuilder;
use Tlapnet\Stamus\Transition\StaticTransition;
use Tlapnet\Stamus\Transition\CallableTransition;

// Create states
$state1 = new State('START');
$state2 = new State('S2', ['isReady' => TRUE]);
$state3 = new State('END');

// Create transitions
$transition1 = new StaticTransition($state1, $state2);
$transition2 = new CallableTransition(
$state2,
$state3,
function(State $s2, State $s3): bool {
return $s2->getContext()['isReady'] === TRUE;
});

// Build state machine
$smb = new StateMachineBuilder();
$smb->addState($state1);
$smb->addState($state2);
$smb->addState($state3);

$smb->addTransition($transition1);
$smb->addTransition($transition2);

$sm = $smb->build();

// Use machine
$sm->setCurrentState('START');
if ($sm->canChange('S2')) {
$sm->change('S2');
}

if ($sm->getCurrentState()->getId() === 'S2') {
$sm->change('END');
}

```
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = tab
tab_width = 4

[{*.json,*.yml,*.md}]
indent_style = space
indent_size = 2
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Not archived
.docs export-ignore
tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
Makefile export-ignore
phpstan.neon export-ignore
README.md export-ignore
ruleset.xml export-ignore
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# IDE
/.idea

# Composer
/vendor
/composer.lock

# Tests
/temp
/coverage.xml
55 changes: 55 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
language: php
php:
- 7.2
- 7.3
- 7.4snapshot
- nightly

before_install:
- phpenv config-rm xdebug.ini || return 0 # Turn off XDebug

install:
- travis_retry composer install --no-progress --prefer-dist # Install dependencies

script:
- make tests # Tests

jobs:
include:
- env: title="Lowest Dependencies 7.2"
php: 7.2
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
script:
- make tests

- stage: Quality Assurance
php: 7.3
script:
- make qa

- stage: Test Coverage
if: branch = master AND type = push
php: 7.3
script:
- make coverage
after_script:
- composer global require php-coveralls/php-coveralls ^2.1.0
- ~/.composer/vendor/bin/php-coveralls --verbose --config tests/.coveralls.yml

- stage: Outdated Dependencies
if: branch = master AND type = cron
php: 7.3
script:
- composer outdated --direct

allow_failures:
- stage: Test Coverage
- php: 7.4snapshot
- php: nightly

sudo: false

cache:
directories:
- $HOME/.composer/cache
Loading

0 comments on commit e0741b8

Please sign in to comment.