File indexing completed on 2024-06-30 05:58:49

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_Tool
0017  * @subpackage Framework
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  * This class is the front most class for utilizing Zend_Tool_Project
0025  *
0026  * A profile is a hierarchical set of resources that keep track of
0027  * items within a specific project.
0028  *
0029  * @category   Zend
0030  * @package    Zend_Tool
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Tool_Project_Context_Content_Engine_CodeGenerator
0035 {
0036     /**
0037      * @var Zend_Tool_Framework_Client_Storage
0038      */
0039     protected $_storage = null;
0040 
0041     /**
0042      * @var string
0043      */
0044     protected $_contentPrefix = null;
0045 
0046     /**
0047      * __construct()
0048      *
0049      * @param Zend_Tool_Framework_Client_Storage $storage
0050      * @param string $contentPrefix
0051      */
0052     public function __construct(Zend_Tool_Framework_Client_Storage $storage, $contentPrefix)
0053     {
0054         $this->_storage       = $storage;
0055         $this->_contentPrefix = $contentPrefix;
0056     }
0057 
0058     /**
0059      * hasContent()
0060      *
0061      * @param Zend_Tool_Project_Context_Interface $context
0062      * @param string $method
0063      * @return string
0064      */
0065     public function hasContent(Zend_Tool_Project_Context_Interface $context, $method)
0066     {
0067         return $this->_storage->has($this->_contentPrefix . '/' . $context->getName() . '/' . $method . '.php');
0068     }
0069 
0070     /**
0071      * getContent()
0072      *
0073      * @param Zend_Tool_Project_Context_Interface $context
0074      * @param string $method
0075      * @param mixed $parameters
0076      * @return string
0077      */
0078     public function getContent(Zend_Tool_Project_Context_Interface $context, $method, $parameters)
0079     {
0080         $streamUri = $this->_storage->getStreamUri($this->_contentPrefix . '/' . $context->getName() . '/' . $method . '.php');
0081 
0082         if (method_exists($context, 'getCodeGenerator')) {
0083             $codeGenerator = $context->getCodeGenerator();
0084         } else {
0085             $codeGenerator = new Zend_CodeGenerator_Php_File();
0086         }
0087 
0088         $codeGenerator = include $streamUri;
0089 
0090         if (!$codeGenerator instanceof Zend_CodeGenerator_Abstract) {
0091             throw new Zend_Tool_Project_Exception('Custom file at ' . $streamUri . ' did not return the $codeGenerator object.');
0092         }
0093 
0094         return $codeGenerator->generate();
0095     }
0096 
0097 
0098 }