-
-
Notifications
You must be signed in to change notification settings - Fork 336
/
RectorServiceConfigurator.php
55 lines (45 loc) · 1.79 KB
/
RectorServiceConfigurator.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
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace Rector\Core\DependencyInjection\Loader\Configurator;
use Rector\Core\Configuration\ValueObjectInliner;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServiceConfigurator;
/**
* @api
* Same as Symfony service configurator, with extra "configure()" method for easier DX
*/
final class RectorServiceConfigurator extends ServiceConfigurator
{
/**
* @deprecated Use @see \Rector\Config\RectorConfig instead
* @param mixed[] $configuration
*/
public function configure(array $configuration): self
{
$this->ensureClassIsConfigurable($this->id);
// decorate with value object inliner so Symfony understands, see https://getrector.org/blog/2020/09/07/how-to-inline-value-object-in-symfony-php-config
array_walk_recursive($configuration, static function (&$value) {
if (is_object($value)) {
$value = ValueObjectInliner::inline($value);
}
return $value;
});
$this->call('configure', [$configuration]);
return $this;
}
private function ensureClassIsConfigurable(?string $class): void
{
if ($class === null) {
throw new InvalidConfigurationException('The class is missing');
}
if (! is_a($class, ConfigurableRectorInterface::class, true)) {
$errorMessage = sprintf(
'The service "%s" is not configurable. Make it implement "%s" or remove "configure()" call.',
$class,
ConfigurableRectorInterface::class,
);
throw new InvalidConfigurationException($errorMessage);
}
}
}