1: <?php
2:
3: namespace Guzzle\Service\Description;
4:
5: use Guzzle\Service\AbstractConfigLoader;
6: use Guzzle\Service\Exception\DescriptionBuilderException;
7:
8: 9: 10:
11: class ServiceDescriptionLoader extends AbstractConfigLoader
12: {
13: 14: 15:
16: protected function build($config, array $options)
17: {
18: $operations = array();
19: if (!empty($config['operations'])) {
20: foreach ($config['operations'] as $name => $op) {
21: $name = $op['name'] = isset($op['name']) ? $op['name'] : $name;
22:
23: if (!empty($op['extends'])) {
24: $this->resolveExtension($name, $op, $operations);
25: }
26: $op['parameters'] = isset($op['parameters']) ? $op['parameters'] : array();
27: $operations[$name] = $op;
28: }
29: }
30:
31: return new ServiceDescription(array(
32: 'apiVersion' => isset($config['apiVersion']) ? $config['apiVersion'] : null,
33: 'baseUrl' => isset($config['baseUrl']) ? $config['baseUrl'] : null,
34: 'description' => isset($config['description']) ? $config['description'] : null,
35: 'operations' => $operations,
36: 'models' => isset($config['models']) ? $config['models'] : null
37: ) + $config);
38: }
39:
40: 41: 42: 43: 44: 45:
46: protected function resolveExtension($name, array &$op, array &$operations)
47: {
48: $resolved = array();
49: $original = empty($op['parameters']) ? false: $op['parameters'];
50: $hasClass = !empty($op['class']);
51: foreach ((array) $op['extends'] as $extendedCommand) {
52: if (empty($operations[$extendedCommand])) {
53: throw new DescriptionBuilderException("{$name} extends missing operation {$extendedCommand}");
54: }
55: $toArray = $operations[$extendedCommand];
56: $resolved = empty($resolved)
57: ? $toArray['parameters']
58: : array_merge($resolved, $toArray['parameters']);
59:
60: $op = $op + $toArray;
61: if (!$hasClass && isset($toArray['class'])) {
62: $op['class'] = $toArray['class'];
63: }
64: }
65: $op['parameters'] = $original ? array_merge($resolved, $original) : $resolved;
66: }
67: }
68: