-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigResolver.php
40 lines (33 loc) · 1.2 KB
/
ConfigResolver.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
<?php
declare(strict_types=1);
namespace Coshi\VariatorBundle;
use Coshi\Variator\ConfigResolver as BaseResolver;
use Coshi\Variator\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
class ConfigResolver extends BaseResolver implements ContainerAwareInterface
{
use ContainerAwareTrait;
/**
* @param array $config
*
* @return mixed
*
* @throws ServiceCircularReferenceException
* @throws ServiceNotFoundException
* @throws InvalidConfigurationException
*/
protected function resolveInstance(array $config)
{
$class = $config[0];
if (class_exists($class)) {
return parent::resolveInstance($config);
}
if (0 !== strpos($class, '@')) {
throw new InvalidConfigurationException(sprintf('String "%s" doesn\'t match service definition', $class));
}
return $this->container->get(trim(substr($class, 1)));
}
}