File indexing completed on 2024-05-12 06:02:21

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_CodeGenerator
0017  * @subpackage PHP
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @category   Zend
0025  * @package    Zend_CodeGenerator
0026  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0027  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0028  */
0029 abstract class Zend_CodeGenerator_Abstract
0030 {
0031 
0032     /**
0033      * @var string
0034      */
0035     protected $_sourceContent = null;
0036 
0037     /**
0038      * @var bool
0039      */
0040     protected $_isSourceDirty = true;
0041 
0042     /**
0043      * __construct()
0044      *
0045      * @param array $options
0046      */
0047     public function __construct($options = array())
0048     {
0049         $this->_init();
0050         if ($options != null) {
0051             // use Zend_Config objects if provided
0052             if ($options instanceof Zend_Config) {
0053                 $options = $options->toArray();
0054             }
0055             // pass arrays to setOptions
0056             if (is_array($options)) {
0057                 $this->setOptions($options);
0058             }
0059         }
0060         $this->_prepare();
0061     }
0062 
0063     /**
0064      * setConfig()
0065      *
0066      * @param Zend_Config $config
0067      * @return Zend_CodeGenerator_Abstract
0068      */
0069     public function setConfig(Zend_Config $config)
0070     {
0071         $this->setOptions($config->toArray());
0072         return $this;
0073     }
0074 
0075     /**
0076      * setOptions()
0077      *
0078      * @param array $options
0079      * @return Zend_CodeGenerator_Abstract
0080      */
0081     public function setOptions(Array $options)
0082     {
0083         foreach ($options as $optionName => $optionValue) {
0084             $methodName = 'set' . $optionName;
0085             if (method_exists($this, $methodName)) {
0086                 $this->{$methodName}($optionValue);
0087             }
0088         }
0089         return $this;
0090     }
0091 
0092     /**
0093      * setSourceContent()
0094      *
0095      * @param string $sourceContent
0096      */
0097     public function setSourceContent($sourceContent)
0098     {
0099         $this->_sourceContent = $sourceContent;
0100         return;
0101     }
0102 
0103     /**
0104      * getSourceContent()
0105      *
0106      * @return string
0107      */
0108     public function getSourceContent()
0109     {
0110         return $this->_sourceContent;
0111     }
0112 
0113     /**
0114      * _init() - this is called before the constuctor
0115      *
0116      */
0117     protected function _init()
0118     {
0119 
0120     }
0121 
0122     /**
0123      * _prepare() - this is called at construction completion
0124      *
0125      */
0126     protected function _prepare()
0127     {
0128 
0129     }
0130 
0131     /**
0132      * generate() - must be implemented by the child
0133      *
0134      */
0135     abstract public function generate();
0136 
0137     /**
0138      * __toString() - casting to a string will in turn call generate()
0139      *
0140      * @return string
0141      */
0142     final public function __toString()
0143     {
0144         return $this->generate();
0145     }
0146 
0147 }