1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: namespace Minion\Service;
12:
13: use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
14: use Symfony\Component\HttpFoundation\ParameterBag;
15:
16: 17: 18: 19: 20: 21:
22: class ServiceConfig implements ServiceConfigInterface
23: {
24:
25: protected $id;
26:
27: protected $providerClass;
28:
29: protected $tags;
30:
31: protected $options;
32:
33: 34: 35:
36: public function __construct($id, array $parsed) {
37: $class = null;
38: $options = $tags = [];
39: if(isset($parsed['class']))
40: if(\is_string($parsed['class']))
41: if(\class_exists($parsed['class']))
42: $class = $parsed['class'];
43: else throw new InvalidConfigurationException("Class '{$parsed['class']}' defined in '$id' not found");
44: else throw new InvalidConfigurationException("Class argument is not a string");
45: else throw new InvalidConfigurationException("Missing 'class' for '$id' service");
46: if(isset($parsed['options'])) {
47: if(\is_array($parsed['options']))
48: $options = $parsed['options'];
49: else throw new InvalidConfigurationException("service options must be an array");
50: }
51: if(isset($parsed['tags'])) {
52: if(\is_array($parsed['tags']))
53: $tags = $parsed['tags'];
54: else throw new InvalidConfigurationException("service tags must be an array");
55: }
56:
57: $this->id = $id;
58: $this->providerClass = $class;
59: $this->options = new ParameterBag($options);
60: $this->tags = $tags;
61: }
62:
63: 64: 65:
66: public function getTags() {
67: return $this->tags;
68: }
69:
70: 71: 72:
73: public function getId() {
74: return $this->id;
75: }
76:
77: 78: 79:
80: public function getOption($name) {
81: if(!$this->options->has($name))
82: throw new \InvalidArgumentException("Option '$name' is not defined");
83:
84: return $this->options->get($name);
85: }
86:
87: 88: 89:
90: public function getOptions() {
91: return $this->options->all();
92: }
93:
94: 95: 96:
97: public function getProviderClass() {
98: return $this->providerClass;
99: }
100: }