1: <?php
 2: 
 3: namespace Guzzle\Service\Resource;
 4: 
 5: use Guzzle\Common\Exception\InvalidArgumentException;
 6: use Guzzle\Service\Command\CommandInterface;
 7: 
 8: /**
 9:  * Abstract resource iterator factory implementation
10:  */
11: abstract class AbstractResourceIteratorFactory implements ResourceIteratorFactoryInterface
12: {
13:     /**
14:      * {@inheritdoc}
15:      */
16:     public function build(CommandInterface $command, array $options = array())
17:     {
18:         if (!$this->canBuild($command)) {
19:             throw new InvalidArgumentException('Iterator was not found for ' . $command->getName());
20:         }
21: 
22:         $className = $this->getClassName($command);
23: 
24:         return new $className($command, $options);
25:     }
26: 
27:     /**
28:      * {@inheritdoc}
29:      */
30:     public function canBuild(CommandInterface $command)
31:     {
32:         return (bool) $this->getClassName($command);
33:     }
34: 
35:     /**
36:      * Get the name of the class to instantiate for the command
37:      *
38:      * @param CommandInterface $command Command that is associated with the iterator
39:      *
40:      * @return string
41:      */
42:     abstract protected function getClassName(CommandInterface $command);
43: }
44: