You are here

class GuardFactory in State Machine 8

Default implementation of the guard factory.

Hierarchy

Expanded class hierarchy of GuardFactory

1 string reference to 'GuardFactory'
state_machine.services.yml in ./state_machine.services.yml
state_machine.services.yml
1 service uses GuardFactory
state_machine.guard_factory in ./state_machine.services.yml
Drupal\state_machine\Guard\GuardFactory

File

src/Guard/GuardFactory.php, line 10

Namespace

Drupal\state_machine\Guard
View source
class GuardFactory implements GuardFactoryInterface {

  /**
   * The service container.
   *
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected $container;

  /**
   * The guard service ids, grouped by workflow group ID.
   *
   * @var string[]
   */
  protected $guardServiceIds;

  /**
   * Constructs a new GuardFactory object.
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The service container.
   * @param string[] $guard_service_ids
   *   The guard service IDs, grouped by workflow group ID.
   */
  public function __construct(ContainerInterface $container, array $guard_service_ids) {
    $this->container = $container;
    $this->guardServiceIds = $guard_service_ids;
  }

  /**
   * {@inheritdoc}
   */
  public function get($group_id) {
    $service_ids = [];
    if (isset($this->guardServiceIds[$group_id])) {
      $service_ids = array_merge($service_ids, $this->guardServiceIds[$group_id]);
    }
    if (isset($this->guardServiceIds['_generic'])) {
      $service_ids = array_merge($service_ids, $this->guardServiceIds['_generic']);
    }
    $guards = [];
    foreach ($service_ids as $service_id) {
      $guards[] = $this->container
        ->get($service_id);
    }
    return $guards;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GuardFactory::$container protected property The service container.
GuardFactory::$guardServiceIds protected property The guard service ids, grouped by workflow group ID.
GuardFactory::get public function Gets the instantiated guards for the given group ID. Overrides GuardFactoryInterface::get
GuardFactory::__construct public function Constructs a new GuardFactory object.