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

  • AbstractConfigLoader
  • CachingConfigLoader
  • Client

Interfaces

  • ClientInterface
  • ConfigLoaderInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Service;
 4: 
 5: use Guzzle\Cache\CacheAdapterInterface;
 6: 
 7: /**
 8:  * Decorator that adds caching to a service description loader
 9:  */
10: class CachingConfigLoader implements ConfigLoaderInterface
11: {
12:     /**
13:      * @var ConfigLoaderInterface
14:      */
15:     protected $loader;
16: 
17:     /**
18:      * @var CacheAdapterInterface
19:      */
20:     protected $cache;
21: 
22:     /**
23:      * Add caching to a config loader
24:      *
25:      * @param ConfigLoaderInterface $loader Loader used to load the config when there is a cache miss
26:      * @param CacheAdapterInterface $cache  Object used to cache the loaded result
27:      */
28:     public function __construct(ConfigLoaderInterface $loader, CacheAdapterInterface $cache)
29:     {
30:         $this->loader = $loader;
31:         $this->cache = $cache;
32:     }
33: 
34:     /**
35:      * {@inheritdoc}
36:      */
37:     public function load($config, array $options = array())
38:     {
39:         if (!is_string($config)) {
40:             $key = false;
41:         } else {
42:             $key = 'loader_' . crc32($config);
43:             if ($result = $this->cache->fetch($key)) {
44:                 return $result;
45:             }
46:         }
47: 
48:         $result = $this->loader->load($config, $options);
49:         if ($key) {
50:             $this->cache->save($key, $result);
51:         }
52: 
53:         return $result;
54:     }
55: }
56: 
php-coveralls API documentation generated by ApiGen 2.8.0