vendor/yohang/finite/src/Finite/Factory/SymfonyDependencyInjectionFactory.php line 34

Open in your IDE?
  1. <?php
  2. namespace Finite\Factory;
  3. use Finite\Exception\FactoryException;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. /**
  6.  * A concrete implementation of State Machine Factory using the sf2 DIC.
  7.  *
  8.  * @author Yohan Giarelli <yohan@frequence-web.fr>
  9.  */
  10. class SymfonyDependencyInjectionFactory extends AbstractFactory
  11. {
  12.     /**
  13.      * @var ContainerInterface
  14.      */
  15.     protected $container;
  16.     /**
  17.      * @var string
  18.      */
  19.     protected $key;
  20.     /**
  21.      * @param ContainerInterface $container
  22.      * @param string             $key
  23.      */
  24.     public function __construct(ContainerInterface $container$key)
  25.     {
  26.         $this->container $container;
  27.         $this->key $key;
  28.         if (!$container->has($key)) {
  29.             throw new FactoryException(
  30.                 sprintf(
  31.                     'You must define the "%s" service as your StateMachine definition',
  32.                     $key
  33.                 )
  34.             );
  35.         }
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     protected function createStateMachine()
  41.     {
  42.         return $this->container->get($this->key);
  43.     }
  44. }