forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiUtils.php
81 lines (63 loc) · 2.07 KB
/
DiUtils.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Enqueue\Symfony;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
class DiUtils
{
public const DEFAULT_CONFIG = 'default';
/**
* @var string
*/
private $moduleName;
/**
* @var string
*/
private $configName;
public function __construct(string $moduleName, string $configName)
{
$this->moduleName = $moduleName;
$this->configName = $configName;
}
public static function create(string $moduleName, string $configName): self
{
return new self($moduleName, $configName);
}
public function getModuleName(): string
{
return $this->moduleName;
}
public function getConfigName(): string
{
return $this->configName;
}
public function reference(string $serviceName, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): Reference
{
return new Reference($this->format($serviceName), $invalidBehavior);
}
public function referenceDefault(string $serviceName, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): Reference
{
return new Reference($this->formatDefault($serviceName), $invalidBehavior);
}
public function parameter(string $serviceName): string
{
$fullName = $this->format($serviceName);
return "%$fullName%";
}
public function parameterDefault(string $serviceName): string
{
$fullName = $this->formatDefault($serviceName);
return "%$fullName%";
}
public function format(string $serviceName): string
{
return $this->doFormat($this->moduleName, $this->configName, $serviceName);
}
public function formatDefault(string $serviceName): string
{
return $this->doFormat($this->moduleName, self::DEFAULT_CONFIG, $serviceName);
}
private function doFormat(string $moduleName, string $configName, string $serviceName): string
{
return sprintf('enqueue.%s.%s.%s', $moduleName, $configName, $serviceName);
}
}