|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_CodeGenerator |
|
17 * @subpackage PHP |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @category Zend |
|
25 * @package Zend_CodeGenerator |
|
26 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
27 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
28 */ |
|
29 abstract class Zend_CodeGenerator_Abstract |
|
30 { |
|
31 |
|
32 /** |
|
33 * @var string |
|
34 */ |
|
35 protected $_sourceContent = null; |
|
36 |
|
37 /** |
|
38 * @var bool |
|
39 */ |
|
40 protected $_isSourceDirty = true; |
|
41 |
|
42 /** |
|
43 * __construct() |
|
44 * |
|
45 * @param array $options |
|
46 */ |
|
47 public function __construct($options = array()) |
|
48 { |
|
49 $this->_init(); |
|
50 if ($options != null) { |
|
51 // use Zend_Config objects if provided |
|
52 if ($options instanceof Zend_Config) { |
|
53 $options = $options->toArray(); |
|
54 } |
|
55 // pass arrays to setOptions |
|
56 if (is_array($options)) { |
|
57 $this->setOptions($options); |
|
58 } |
|
59 } |
|
60 $this->_prepare(); |
|
61 } |
|
62 |
|
63 /** |
|
64 * setConfig() |
|
65 * |
|
66 * @param Zend_Config $config |
|
67 * @return Zend_CodeGenerator_Abstract |
|
68 */ |
|
69 public function setConfig(Zend_Config $config) |
|
70 { |
|
71 $this->setOptions($config->toArray()); |
|
72 return $this; |
|
73 } |
|
74 |
|
75 /** |
|
76 * setOptions() |
|
77 * |
|
78 * @param array $options |
|
79 * @return Zend_CodeGenerator_Abstract |
|
80 */ |
|
81 public function setOptions(Array $options) |
|
82 { |
|
83 foreach ($options as $optionName => $optionValue) { |
|
84 $methodName = 'set' . $optionName; |
|
85 if (method_exists($this, $methodName)) { |
|
86 $this->{$methodName}($optionValue); |
|
87 } |
|
88 } |
|
89 return $this; |
|
90 } |
|
91 |
|
92 /** |
|
93 * setSourceContent() |
|
94 * |
|
95 * @param string $sourceContent |
|
96 */ |
|
97 public function setSourceContent($sourceContent) |
|
98 { |
|
99 $this->_sourceContent = $sourceContent; |
|
100 return; |
|
101 } |
|
102 |
|
103 /** |
|
104 * getSourceContent() |
|
105 * |
|
106 * @return string |
|
107 */ |
|
108 public function getSourceContent() |
|
109 { |
|
110 return $this->_sourceContent; |
|
111 } |
|
112 |
|
113 /** |
|
114 * _init() - this is called before the constuctor |
|
115 * |
|
116 */ |
|
117 protected function _init() |
|
118 { |
|
119 |
|
120 } |
|
121 |
|
122 /** |
|
123 * _prepare() - this is called at construction completion |
|
124 * |
|
125 */ |
|
126 protected function _prepare() |
|
127 { |
|
128 |
|
129 } |
|
130 |
|
131 /** |
|
132 * generate() - must be implemented by the child |
|
133 * |
|
134 */ |
|
135 abstract public function generate(); |
|
136 |
|
137 /** |
|
138 * __toString() - casting to a string will in turn call generate() |
|
139 * |
|
140 * @return string |
|
141 */ |
|
142 final public function __toString() |
|
143 { |
|
144 return $this->generate(); |
|
145 } |
|
146 |
|
147 } |