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:
<?php
namespace Guzzle\Service\Description;
use Guzzle\Service\AbstractConfigLoader;
use Guzzle\Service\Exception\DescriptionBuilderException;
class ServiceDescriptionLoader extends AbstractConfigLoader
{
protected function build($config, array $options)
{
$operations = array();
if (!empty($config['operations'])) {
foreach ($config['operations'] as $name => $op) {
$name = $op['name'] = isset($op['name']) ? $op['name'] : $name;
if (!empty($op['extends'])) {
$this->resolveExtension($name, $op, $operations);
}
$op['parameters'] = isset($op['parameters']) ? $op['parameters'] : array();
$operations[$name] = $op;
}
}
return new ServiceDescription(array(
'apiVersion' => isset($config['apiVersion']) ? $config['apiVersion'] : null,
'baseUrl' => isset($config['baseUrl']) ? $config['baseUrl'] : null,
'description' => isset($config['description']) ? $config['description'] : null,
'operations' => $operations,
'models' => isset($config['models']) ? $config['models'] : null
) + $config);
}
protected function resolveExtension($name, array &$op, array &$operations)
{
$resolved = array();
$original = empty($op['parameters']) ? false: $op['parameters'];
$hasClass = !empty($op['class']);
foreach ((array) $op['extends'] as $extendedCommand) {
if (empty($operations[$extendedCommand])) {
throw new DescriptionBuilderException("{$name} extends missing operation {$extendedCommand}");
}
$toArray = $operations[$extendedCommand];
$resolved = empty($resolved)
? $toArray['parameters']
: array_merge($resolved, $toArray['parameters']);
$op = $op + $toArray;
if (!$hasClass && isset($toArray['class'])) {
$op['class'] = $toArray['class'];
}
}
$op['parameters'] = $original ? array_merge($resolved, $original) : $resolved;
}
}