Skip to content

Commit f76607c

Browse files
authored
Merge pull request peckadesign#2 from peckadesign/prefix
Extension: named sections prefix
2 parents 2d00bd8 + cd61d89 commit f76607c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Now you can configure your supervisor.
2727

2828
```yaml
2929
supervisor:
30+
prefix: my-project #prefixes every named section
31+
3032
defaults:
3133
program:
3234
autorestart: on

src/DI/SupervisorExtension.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ final class SupervisorExtension extends CompilerExtension
1717
{
1818

1919
const DEFAULTS = [
20+
'prefix' => NULL,
2021
'configuration' => [],
2122
'defaults' => [],
2223
];
@@ -33,7 +34,11 @@ public function loadConfiguration()
3334
}
3435
}
3536

36-
$this->loadSupervisorConfiguration($config['configuration'], $config['defaults']);
37+
$this->loadSupervisorConfiguration(
38+
(array) $config['configuration'],
39+
(array) $config['defaults'],
40+
isset($config['prefix']) ? (string) $config['prefix'] : NULL
41+
);
3742

3843
$builder->addDefinition($this->prefix('renderCommand'))
3944
->setClass(RenderCommand::class, [strtr($this->prefix('render'), '.', ':')])
@@ -46,7 +51,7 @@ public function loadConfiguration()
4651
}
4752

4853

49-
private function loadSupervisorConfiguration(array $config, array $defaults = [])
54+
private function loadSupervisorConfiguration(array $config, array $defaults = [], string $prefix = NULL)
5055
{
5156
$builder = $this->getContainerBuilder();
5257

@@ -59,9 +64,13 @@ private function loadSupervisorConfiguration(array $config, array $defaults = []
5964
}
6065
if (is_subclass_of($sectionClass, Named::class)) {
6166
foreach ((array) $sectionConfig as $name => $properties) {
67+
$name = Helpers::expand($name, $builder->parameters);
68+
if ($prefix !== NULL) {
69+
$name = sprintf('%s-%s', $prefix, $name);
70+
}
6271
$configuration->addSetup('addSection', [
6372
new Statement($sectionClass, [
64-
Helpers::expand($name, $builder->parameters),
73+
$name,
6574
isset($defaults[$sectionName]) ? $this->mergeProperties($properties, $defaults[$sectionName]) : $properties,
6675
]),
6776
]);

0 commit comments

Comments
 (0)