41 public static function factory($config =
null, array $globalParameters = array())
44 if (!static::$cachedFactory) {
49 return self::$cachedFactory->load($config, $globalParameters);
58 public function __construct(array $serviceBuilderConfig = array())
60 $this->builderConfig = $serviceBuilderConfig;
65 return array(
'service_builder.create_client');
70 $this->builderConfig = json_decode($serialized,
true);
75 return json_encode($this->builderConfig);
101 return isset($this->builderConfig[$name]) ? $this->builderConfig[$name] :
null;
104 public function get($name, $throwAway =
false)
106 if (!isset($this->builderConfig[$name])) {
109 if (isset($this->clients[$name])) {
110 return $this->clients[$name];
114 foreach ($this->builderConfig as $actualName => $config) {
115 if (isset($config[
'alias']) && $config[
'alias'] == $name) {
116 return $this->
get($actualName, $throwAway);
122 if (!$throwAway && isset($this->clients[$name])) {
123 return $this->clients[$name];
126 $builder =& $this->builderConfig[$name];
129 foreach ($builder[
'params'] as &$v) {
130 if (is_string($v) && substr($v, 0, 1) ==
'{' && substr($v, -1) ==
'}') {
131 $v = $this->
get(trim($v,
'{} '));
136 $config = $builder[
'params'];
137 if (is_array($throwAway)) {
138 $config = $throwAway + $config;
141 $client = $builder[
'class']
::factory($config);
144 $this->clients[$name] = $client;
147 if ($client instanceof ClientInterface) {
148 foreach ($this->
plugins as $plugin) {
149 $client->addSubscriber($plugin);
152 $this->
dispatch(
'service_builder.create_client', array(
'client' => $client));
158 public function set($key, $service)
160 if (is_array($service) && isset($service[
'class']) && isset($service[
'params'])) {
161 $this->builderConfig[$key] = $service;
163 $this->clients[$key] = $service;
169 public function offsetSet($offset, $value)
171 $this->
set($offset, $value);
176 unset($this->builderConfig[$offset]);
177 unset($this->clients[$offset]);
182 return isset($this->builderConfig[$offset]) || isset($this->clients[$offset]);
187 return $this->
get($offset);