Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • Operation
  • Parameter
  • SchemaFormatter
  • SchemaValidator
  • ServiceDescription
  • ServiceDescriptionLoader

Interfaces

  • OperationInterface
  • ServiceDescriptionInterface
  • ValidatorInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Service\Description;
 4: 
 5: use Guzzle\Service\AbstractConfigLoader;
 6: use Guzzle\Service\Exception\DescriptionBuilderException;
 7: 
 8: /**
 9:  * Loader for service descriptions
10:  */
11: class ServiceDescriptionLoader extends AbstractConfigLoader
12: {
13:     /**
14:      * {@inheritdoc}
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:                 // Extend other operations
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:      * @param string $name       Name of the operation
42:      * @param array  $op         Operation value array
43:      * @param array  $operations Currently loaded operations
44:      * @throws DescriptionBuilderException when extending a non-existent operation
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: 
php-coveralls API documentation generated by ApiGen 2.8.0