class GuardsPass in State Machine 8
Adds the context provider service IDs to the context manager.
Hierarchy
- class \Drupal\state_machine\DependencyInjection\Compiler\GuardsPass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface
Expanded class hierarchy of GuardsPass
1 file declares its use of GuardsPass
File
- src/
DependencyInjection/ Compiler/ GuardsPass.php, line 11
Namespace
Drupal\state_machine\DependencyInjection\CompilerView source
class GuardsPass implements CompilerPassInterface {
/**
* {@inheritdoc}
*
* Passes the grouped service IDs of guards to the guard factory.
*/
public function process(ContainerBuilder $container) {
$guards = [];
$priorities = [];
foreach ($container
->findTaggedServiceIds('state_machine.guard') as $id => $attributes) {
if (empty($attributes[0]['group'])) {
// Guards without a specified group should be invoked for all of them.
$attributes[0]['group'] = '_generic';
}
$group_id = $attributes[0]['group'];
$guards[$group_id][$id] = $id;
$priorities[$group_id][$id] = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
}
// Sort the guards by priority.
foreach ($priorities as $group_id => $services) {
array_multisort($priorities[$group_id], SORT_DESC, $guards[$group_id]);
}
$definition = $container
->getDefinition('state_machine.guard_factory');
$definition
->addArgument($guards);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GuardsPass:: |
public | function | Passes the grouped service IDs of guards to the guard factory. |