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

  • AbstractResourceIteratorFactory
  • CompositeResourceIteratorFactory
  • MapResourceIteratorFactory
  • Model
  • ResourceIterator
  • ResourceIteratorApplyBatched
  • ResourceIteratorClassFactory

Interfaces

  • ResourceIteratorFactoryInterface
  • ResourceIteratorInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Service\Resource;
 4: 
 5: use Guzzle\Inflection\InflectorInterface;
 6: use Guzzle\Inflection\Inflector;
 7: use Guzzle\Service\Command\CommandInterface;
 8: 
 9: /**
10:  * Factory for creating {@see ResourceIteratorInterface} objects using a convention of storing iterator classes under a
11:  * root namespace using the name of a {@see CommandInterface} object as a convention for determining the name of an
12:  * iterator class. The command name is converted to CamelCase and Iterator is appended (e.g. abc_foo => AbcFoo).
13:  */
14: class ResourceIteratorClassFactory extends AbstractResourceIteratorFactory
15: {
16:     /**
17:      * @var array List of namespaces used to look for classes
18:      */
19:     protected $namespaces;
20: 
21:     /**
22:      * @var InflectorInterface Inflector used to determine class names
23:      */
24:     protected $inflector;
25: 
26:     /**
27:      * @param string|array       $namespaces List of namespaces for iterator objects
28:      * @param InflectorInterface $inflector  Inflector used to resolve class names
29:      */
30:     public function __construct($namespaces = array(), InflectorInterface $inflector = null)
31:     {
32:         $this->namespaces = (array) $namespaces;
33:         $this->inflector = $inflector ?: Inflector::getDefault();
34:     }
35: 
36:     /**
37:      * Registers a namespace to check for Iterators
38:      *
39:      * @param string $namespace Namespace which contains Iterator classes
40:      *
41:      * @return self
42:      */
43:     public function registerNamespace($namespace)
44:     {
45:         array_unshift($this->namespaces, $namespace);
46: 
47:         return $this;
48:     }
49: 
50:     /**
51:      * {@inheritdoc}
52:      */
53:     protected function getClassName(CommandInterface $command)
54:     {
55:         $iteratorName = $this->inflector->camel($command->getName()) . 'Iterator';
56: 
57:         // Determine the name of the class to load
58:         foreach ($this->namespaces as $namespace) {
59:             $potentialClassName = $namespace . '\\' . $iteratorName;
60:             if (class_exists($potentialClassName)) {
61:                 return $potentialClassName;
62:             }
63:         }
64: 
65:         return false;
66:     }
67: }
68: 
php-coveralls API documentation generated by ApiGen 2.8.0