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

  • ServiceBuilder
  • ServiceBuilderLoader

Interfaces

  • ServiceBuilderInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Service\Builder;
 4: 
 5: use Guzzle\Service\AbstractConfigLoader;
 6: use Guzzle\Service\Exception\ServiceNotFoundException;
 7: 
 8: /**
 9:  * Service builder config loader
10:  */
11: class ServiceBuilderLoader extends AbstractConfigLoader
12: {
13:     /**
14:      * {@inheritdoc}
15:      */
16:     protected function build($config, array $options)
17:     {
18:         // A service builder class can be specified in the class field
19:         $class = !empty($config['class']) ? $config['class'] : __NAMESPACE__ . '\\ServiceBuilder';
20: 
21:         // Account for old style configs that do not have a services array
22:         $services = isset($config['services']) ? $config['services'] : $config;
23: 
24:         // Validate the configuration and handle extensions
25:         foreach ($services as $name => &$service) {
26: 
27:             $service['params'] = isset($service['params']) ? $service['params'] : array();
28: 
29:             // Check if this client builder extends another client
30:             if (!empty($service['extends'])) {
31: 
32:                 // Make sure that the service it's extending has been defined
33:                 if (!isset($services[$service['extends']])) {
34:                     throw new ServiceNotFoundException(
35:                         "{$name} is trying to extend a non-existent service: {$service['extends']}"
36:                     );
37:                 }
38: 
39:                 $extended = &$services[$service['extends']];
40: 
41:                 // Use the correct class attribute
42:                 if (empty($service['class'])) {
43:                     $service['class'] = isset($extended['class']) ? $extended['class'] : '';
44:                 }
45:                 if ($extendsParams = isset($extended['params']) ? $extended['params'] : false) {
46:                     $service['params'] = $service['params'] + $extendsParams;
47:                 }
48:             }
49: 
50:             // Overwrite default values with global parameter values
51:             if (!empty($options)) {
52:                 $service['params'] = $options + $service['params'];
53:             }
54: 
55:             $service['class'] = isset($service['class']) ? $service['class'] : '';
56:         }
57: 
58:         return new $class($services);
59:     }
60: 
61:     /**
62:      * {@inheritdoc}
63:      */
64:     protected function mergeData(array $a, array $b)
65:     {
66:         $result = $b + $a;
67: 
68:         // Merge services using a recursive union of arrays
69:         if (isset($a['services']) && $b['services']) {
70: 
71:             // Get a union of the services of the two arrays
72:             $result['services'] = $b['services'] + $a['services'];
73: 
74:             // Merge each service in using a union of the two arrays
75:             foreach ($result['services'] as $name => &$service) {
76: 
77:                 // By default, services completely override a previously defined service unless it extends itself
78:                 if (isset($a['services'][$name]['extends'])
79:                     && isset($b['services'][$name]['extends'])
80:                     && $b['services'][$name]['extends'] == $name
81:                 ) {
82:                     $service += $a['services'][$name];
83:                     // Use the `extends` attribute of the parent
84:                     $service['extends'] = $a['services'][$name]['extends'];
85:                     // Merge parameters using a union if both have parameters
86:                     if (isset($a['services'][$name]['params'])) {
87:                         $service['params'] += $a['services'][$name]['params'];
88:                     }
89:                 }
90:             }
91:         }
92: 
93:         return $result;
94:     }
95: }
96: 
php-coveralls API documentation generated by ApiGen 2.8.0