CodeGenerator.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_Tool
  17. * @subpackage Framework
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * This class is the front most class for utilizing Zend_Tool_Project
  24. *
  25. * A profile is a hierarchical set of resources that keep track of
  26. * items within a specific project.
  27. *
  28. * @category Zend
  29. * @package Zend_Tool
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Tool_Project_Context_Content_Engine_CodeGenerator
  34. {
  35. /**
  36. * @var Zend_Tool_Framework_Client_Storage
  37. */
  38. protected $_storage = null;
  39. /**
  40. * @var string
  41. */
  42. protected $_contentPrefix = null;
  43. /**
  44. * __construct()
  45. *
  46. * @param Zend_Tool_Framework_Client_Storage $storage
  47. * @param string $contentPrefix
  48. */
  49. public function __construct(Zend_Tool_Framework_Client_Storage $storage, $contentPrefix)
  50. {
  51. $this->_storage = $storage;
  52. $this->_contentPrefix = $contentPrefix;
  53. }
  54. /**
  55. * hasContent()
  56. *
  57. * @param Zend_Tool_Project_Context_Interface $context
  58. * @param string $method
  59. * @return string
  60. */
  61. public function hasContent(Zend_Tool_Project_Context_Interface $context, $method)
  62. {
  63. return $this->_storage->has($this->_contentPrefix . '/' . $context->getName() . '/' . $method . '.php');
  64. }
  65. /**
  66. * getContent()
  67. *
  68. * @param Zend_Tool_Project_Context_Interface $context
  69. * @param string $method
  70. * @param mixed $parameters
  71. * @return string
  72. */
  73. public function getContent(Zend_Tool_Project_Context_Interface $context, $method, $parameters)
  74. {
  75. $streamUri = $this->_storage->getStreamUri($this->_contentPrefix . '/' . $context->getName() . '/' . $method . '.php');
  76. if (method_exists($context, 'getCodeGenerator')) {
  77. $codeGenerator = $context->getCodeGenerator();
  78. } else {
  79. $codeGenerator = new Zend_CodeGenerator_Php_File();
  80. }
  81. $codeGenerator = include $streamUri;
  82. if (!$codeGenerator instanceof Zend_CodeGenerator_Abstract) {
  83. throw new Zend_Tool_Project_Exception('Custom file at ' . $streamUri . ' did not return the $codeGenerator object.');
  84. }
  85. return $codeGenerator->generate();
  86. }
  87. }