Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for PHP 5.5 #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
vendor
build
bin
Expand All @@ -6,3 +7,4 @@ composer.lock
cache.properties
coverage.clover
docs/_build
Makefile
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
language: php
sudo: false
php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- hhvm

before_install:
- composer self-update
Expand All @@ -17,8 +19,8 @@ script:
- ./bin/phpunit --coverage-clover=coverage.clover

after_script:
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

notifications:
email: false
Expand Down
99 changes: 54 additions & 45 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,58 @@
{
"name": "yohang/finite",
"description": "A simple PHP5.3+ Finite State Machine",
"keywords": ["statemachine", "workflow", "state", "transition", "symfony", "bundle"],
"homepage": "https://github.com/yohang/Finite",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Yohan Giarelli",
"email": "[email protected]",
"homepage": "http://yohan.giarel.li"
},
{
"name": "Finite contributors",
"homepage": "https://github.com/yohang/Finite/graphs/contributors"
}
],
"require": {
"php": ">=5.5",
"symfony/options-resolver": "^2.6|^3.0|^4.0",
"symfony/event-dispatcher": "^2.6|^3.0|^4.0",
"symfony/property-access": "^2.6|^3.0|^4.0"
"name": "yohang/finite",
"description": "A simple PHP5.6+ Finite State Machine",
"keywords": [
"statemachine",
"workflow",
"state",
"transition",
"symfony",
"bundle"
],
"homepage": "https://github.com/yohang/Finite",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Yohan Giarelli",
"email": "[email protected]",
"homepage": "http://yohan.giarel.li"
},
"require-dev": {
"phpunit/phpunit": "^4.0",
"pimple/pimple": "^1.0",
"symfony/dependency-injection": "^2.6|^3.0|^4.0",
"symfony/framework-bundle": "^2.6|^3.0|^4.0",
"symfony/security": "^2.6|^3.0|^4.0",
"twig/twig": "^1.13"
},
"suggest": {
"pimple/pimple": "Needed for use with PimpleFactory",
"symfony/security": "Needed for using SecurityAwareStateMachine",
"symfony/yaml": "Yaml allows you to define your State graph in YAML"
},
"autoload": {
"psr-0": { "Finite": "src/" }
},
"config": {
"bin-dir":"bin"
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
{
"name": "Finite contributors",
"homepage": "https://github.com/yohang/Finite/graphs/contributors"
}
],
"require": {
"php": ">=5.6",
"symfony/options-resolver": "^2.6|^3.0|^4.0",
"symfony/event-dispatcher": "^2.6|^3.0|^4.0",
"symfony/property-access": "^2.6|^3.0|^4.0",
"phpunit/phpunit": "^5.7"
},
"require-dev": {
"pimple/pimple": "^1.0",
"symfony/dependency-injection": "^2.6|^3.0|^4.0",
"symfony/framework-bundle": "^2.6|^3.0|^4.0",
"symfony/security": "^2.6|^3.0|^4.0",
"twig/twig": "^1.13"
},
"suggest": {
"pimple/pimple": "Needed for use with PimpleFactory",
"symfony/security": "Needed for using SecurityAwareStateMachine",
"symfony/yaml": "Yaml allows you to define your State graph in YAML"
},
"autoload": {
"psr-0": {
"Finite": "src/"
}
},
"config": {
"bin-dir": "bin"
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
}
}
86 changes: 48 additions & 38 deletions src/Finite/StateMachine/StateMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class StateMachine implements StateMachineInterface
*
* @var array
*/
protected $states = array();
protected $states = [];

/**
* The available transitions.
*
* @var array
*/
protected $transitions = array();
protected $transitions = [];

/**
* The current state.
Expand Down Expand Up @@ -92,10 +92,12 @@ public function initialize()
try {
$initialState = $this->stateAccessor->getState($this->object);
} catch (Exception\NoSuchPropertyException $e) {
throw new Exception\ObjectException(sprintf(
'StateMachine can\'t be initialized because the defined property_path of object "%s" does not exist.',
get_class($this->object)
), $e->getCode(), $e);
throw new Exception\ObjectException(
sprintf(
'StateMachine can\'t be initialized because the defined property_path of object "%s" does not exist.',
get_class($this->object)
), $e->getCode(), $e
);
}

if (null === $initialState) {
Expand All @@ -115,18 +117,20 @@ public function initialize()
*
* @throws Exception\StateException
*/
public function apply($transitionName, array $parameters = array())
public function apply($transitionName, array $parameters = [])
{
$transition = $this->getTransition($transitionName);
$event = new TransitionEvent($this->getCurrentState(), $transition, $this, $parameters);
if (!$this->can($transition, $parameters)) {
throw new Exception\StateException(sprintf(
'The "%s" transition can not be applied to the "%s" state of object "%s" with graph "%s".',
$transition->getName(),
$this->currentState->getName(),
get_class($this->getObject()),
$this->getGraph()
));
throw new Exception\StateException(
sprintf(
'The "%s" transition can not be applied to the "%s" state of object "%s" with graph "%s".',
$transition->getName(),
$this->currentState->getName(),
get_class($this->getObject()),
$this->getGraph()
)
);
}

$this->dispatchTransitionEvent($transition, $event, FiniteEvents::PRE_TRANSITION);
Expand All @@ -143,7 +147,7 @@ public function apply($transitionName, array $parameters = array())
/**
* {@inheritdoc}
*/
public function can($transition, array $parameters = array())
public function can($transition, array $parameters = [])
{
$transition = $transition instanceof TransitionInterface ? $transition : $this->getTransition($transition);

Expand Down Expand Up @@ -180,7 +184,7 @@ public function addTransition($transition, $initialState = null, $finalState = n
{
if ((null === $initialState || null === $finalState) && !$transition instanceof TransitionInterface) {
throw new \InvalidArgumentException(
'You must provide a TransitionInterface instance or the $transition, '.
'You must provide a TransitionInterface instance or the $transition, ' .
'$initialState and $finalState parameters'
);
}
Expand Down Expand Up @@ -220,12 +224,14 @@ public function addTransition($transition, $initialState = null, $finalState = n
public function getTransition($name)
{
if (!isset($this->transitions[$name])) {
throw new Exception\TransitionException(sprintf(
'Unable to find a transition called "%s" on object "%s" with graph "%s".',
$name,
get_class($this->getObject()),
$this->getGraph()
));
throw new Exception\TransitionException(
sprintf(
'Unable to find a transition called "%s" on object "%s" with graph "%s".',
$name,
$this->getObject() ? get_class($this->getObject()) : 'undefined',
$this->getGraph()
)
);
}

return $this->transitions[$name];
Expand All @@ -236,15 +242,17 @@ public function getTransition($name)
*/
public function getState($name)
{
$name = (string) $name;
$name = (string)$name;

if (!isset($this->states[$name])) {
throw new Exception\StateException(sprintf(
'Unable to find a state called "%s" on object "%s" with graph "%s".',
$name,
get_class($this->getObject()),
$this->getGraph()
));
throw new Exception\StateException(
sprintf(
'Unable to find a state called "%s" on object "%s" with graph "%s".',
$name,
$this->getObject() ? get_class($this->getObject()) : 'undefined',
$this->getGraph()
)
);
}

return $this->states[$name];
Expand Down Expand Up @@ -305,11 +313,13 @@ protected function findInitialState()
}
}

throw new Exception\StateException(sprintf(
'No initial state found on object "%s" with graph "%s".',
get_class($this->getObject()),
$this->getGraph()
));
throw new Exception\StateException(
sprintf(
'No initial state found on object "%s" with graph "%s".',
get_class($this->getObject()),
$this->getGraph()
)
);
}

/**
Expand Down Expand Up @@ -392,15 +402,15 @@ function (State $state) use ($property, $value) {
* Dispatches event for the transition
*
* @param TransitionInterface $transition
* @param TransitionEvent $event
* @param type $transitionState
* @param TransitionEvent $event
* @param type $transitionState
*/
private function dispatchTransitionEvent(TransitionInterface $transition, TransitionEvent $event, $transitionState)
{
$this->dispatcher->dispatch($transitionState, $event);
$this->dispatcher->dispatch($transitionState.'.'.$transition->getName(), $event);
$this->dispatcher->dispatch($transitionState . '.' . $transition->getName(), $event);
if (null !== $this->getGraph()) {
$this->dispatcher->dispatch($transitionState.'.'.$this->getGraph().'.'.$transition->getName(), $event);
$this->dispatcher->dispatch($transitionState . '.' . $this->getGraph() . '.' . $transition->getName(), $event);
}
}
}
Loading