GuardFactory.php in State Machine 8
File
src/Guard/GuardFactory.php
View source
<?php
namespace Drupal\state_machine\Guard;
use Symfony\Component\DependencyInjection\ContainerInterface;
class GuardFactory implements GuardFactoryInterface {
protected $container;
protected $guardServiceIds;
public function __construct(ContainerInterface $container, array $guard_service_ids) {
$this->container = $container;
$this->guardServiceIds = $guard_service_ids;
}
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;
}
}