-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathMissingComponentFactory.php
42 lines (37 loc) · 1.16 KB
/
MissingComponentFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Enqueue\Symfony;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
class MissingComponentFactory
{
public static function getConfiguration(string $componentName, array $packages): ArrayNodeDefinition
{
if (1 == count($packages)) {
$message = sprintf(
'In order to use the component "%s" install a package "%s"',
$componentName,
implode('", "', $packages)
);
} else {
$message = sprintf(
'In order to use the component "%s" install one of the packages "%s"',
$componentName,
implode('", "', $packages)
);
}
$node = new ArrayNodeDefinition($componentName);
$node
->info($message)
->beforeNormalization()
->always(function () {
return [];
})
->end()
->validate()
->always(function () use ($message) {
throw new \InvalidArgumentException($message);
})
->end()
;
return $node;
}
}