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: 82: 83: 84: 85: 86: 87: 88: 89: 90:
<?php
namespace Guzzle\Service\Builder;
use Guzzle\Service\AbstractConfigLoader;
use Guzzle\Service\Exception\ServiceNotFoundException;
class ServiceBuilderLoader extends AbstractConfigLoader
{
protected function build($config, array $options)
{
$class = !empty($config['class']) ? $config['class'] : __NAMESPACE__ . '\\ServiceBuilder';
$services = isset($config['services']) ? $config['services'] : $config;
foreach ($services as $name => &$service) {
$service['params'] = isset($service['params']) ? $service['params'] : array();
if (!empty($service['extends'])) {
if (!isset($services[$service['extends']])) {
throw new ServiceNotFoundException(
"{$name} is trying to extend a non-existent service: {$service['extends']}"
);
}
$extended = &$services[$service['extends']];
if (empty($service['class'])) {
$service['class'] = isset($extended['class']) ? $extended['class'] : '';
}
if ($extendsParams = isset($extended['params']) ? $extended['params'] : false) {
$service['params'] = $service['params'] + $extendsParams;
}
}
if (!empty($options)) {
$service['params'] = $options + $service['params'];
}
$service['class'] = isset($service['class']) ? $service['class'] : '';
}
return new $class($services);
}
protected function mergeData(array $a, array $b)
{
$result = $b + $a;
if (isset($a['services']) && $b['services']) {
$result['services'] = $b['services'] + $a['services'];
foreach ($result['services'] as $name => &$service) {
if (isset($a['services'][$name]['extends'])
&& isset($b['services'][$name]['extends'])
&& $b['services'][$name]['extends'] == $name
) {
$service += $a['services'][$name];
$service['extends'] = $a['services'][$name]['extends'];
if (isset($a['services'][$name]['params'])) {
$service['params'] += $a['services'][$name]['params'];
}
}
}
}
return $result;
}
}