StateMachine.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Sylius package.
  4. *
  5. * (c) Paweł Jędrzejewski
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sylius\Component\Resource\StateMachine;
  11. use SM\StateMachine\StateMachine as BaseStateMachine;
  12. /**
  13. * Sylius State Machine
  14. *
  15. * @author Alexandre Bacco <alexandre.bacco@gmail.com>
  16. */
  17. class StateMachine extends BaseStateMachine implements StateMachineInterface
  18. {
  19. /**
  20. * @{inheritDoc}
  21. */
  22. public function getTransitionFromState($fromState)
  23. {
  24. foreach ($this->getPossibleTransitions() as $transition) {
  25. $config = $this->config['transitions'][$transition];
  26. if (in_array($fromState, $config['from'])) {
  27. return $transition;
  28. }
  29. }
  30. return null;
  31. }
  32. /**
  33. * @{inheritDoc}
  34. */
  35. public function getTransitionToState($toState)
  36. {
  37. foreach ($this->getPossibleTransitions() as $transition) {
  38. $config = $this->config['transitions'][$transition];
  39. if ($toState === $config['to']) {
  40. return $transition;
  41. }
  42. }
  43. return null;
  44. }
  45. }