3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Code\Generator
;
14 abstract class AbstractGenerator
implements GeneratorInterface
17 * Line feed to use in place of EOL
19 const LINE_FEED
= "\n";
24 protected $isSourceDirty = true;
27 * @var int|string 4 spaces by default
29 protected $indentation = ' ';
34 protected $sourceContent = null;
37 * @param array $options
39 public function __construct($options = array())
42 $this->setOptions($options);
47 * @param bool $isSourceDirty
48 * @return AbstractGenerator
50 public function setSourceDirty($isSourceDirty = true)
52 $this->isSourceDirty
= (bool) $isSourceDirty;
59 public function isSourceDirty()
61 return $this->isSourceDirty
;
65 * @param string $indentation
66 * @return AbstractGenerator
68 public function setIndentation($indentation)
70 $this->indentation
= (string) $indentation;
77 public function getIndentation()
79 return $this->indentation
;
83 * @param string $sourceContent
84 * @return AbstractGenerator
86 public function setSourceContent($sourceContent)
88 $this->sourceContent
= (string) $sourceContent;
95 public function getSourceContent()
97 return $this->sourceContent
;
101 * @param array|Traversable $options
102 * @throws Exception\InvalidArgumentException
103 * @return AbstractGenerator
105 public function setOptions($options)
107 if (!is_array($options) && !$options instanceof Traversable
) {
108 throw new Exception\
InvalidArgumentException(sprintf(
109 '%s expects an array or Traversable object; received "%s"',
111 (is_object($options) ?
get_class($options) : gettype($options))
115 foreach ($options as $optionName => $optionValue) {
116 $methodName = 'set' . $optionName;
117 if (method_exists($this, $methodName)) {
118 $this->{$methodName}($optionValue);