vendor/winzou/state-machine/src/SM/Callback/CallbackFactory.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the StateMachine package.
  4.  *
  5.  * (c) Alexandre Bacco
  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 SM\Callback;
  11. use SM\SMException;
  12. class CallbackFactory implements CallbackFactoryInterface
  13. {
  14.     /**
  15.      * @var string
  16.      */
  17.     protected $class;
  18.     /**
  19.      * @throws SMException
  20.      */
  21.     public function __construct(string $class)
  22.     {
  23.         if (!class_exists($class)) {
  24.             throw new SMException(sprintf(
  25.                'Class %s given to CallbackFactory does not exist.',
  26.                 $class
  27.             ));
  28.         }
  29.         $this->class $class;
  30.     }
  31.     /**
  32.      * {@inheritDoc}
  33.      */
  34.     public function get(array $specs): CallbackInterface
  35.     {
  36.         if (!isset($specs['do'])) {
  37.             throw new SMException(sprintf(
  38.                'CallbackFactory::get needs the index "do" to be able to build a callback, array %s given.',
  39.                 json_encode($specs)
  40.             ));
  41.         }
  42.         $class $this->class;
  43.         return new $class($specs$specs['do']);
  44.     }
  45. }