ProjectProviderFile.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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-2012 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. * @see Zend_Tool_Project_Context_Filesystem_File
  24. */
  25. require_once 'Zend/Tool/Project/Context/Filesystem/File.php';
  26. /**
  27. * @see Zend_CodeGenerator_Php_File
  28. */
  29. require_once 'Zend/CodeGenerator/Php/File.php';
  30. /**
  31. * This class is the front most class for utilizing Zend_Tool_Project
  32. *
  33. * A profile is a hierarchical set of resources that keep track of
  34. * items within a specific project.
  35. *
  36. * @category Zend
  37. * @package Zend_Tool
  38. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Tool_Project_Context_Zf_ProjectProviderFile extends Zend_Tool_Project_Context_Filesystem_File
  42. {
  43. /**
  44. * @var string
  45. */
  46. protected $_projectProviderName = null;
  47. /**
  48. * @var array
  49. */
  50. protected $_actionNames = array();
  51. /**
  52. * init()
  53. *
  54. * @return Zend_Tool_Project_Context_Zf_ProjectProviderFile
  55. */
  56. public function init()
  57. {
  58. $this->_projectProviderName = $this->_resource->getAttribute('projectProviderName');
  59. $this->_actionNames = $this->_resource->getAttribute('actionNames');
  60. $this->_filesystemName = ucfirst($this->_projectProviderName) . 'Provider.php';
  61. if (strpos($this->_actionNames, ',')) {
  62. $this->_actionNames = explode(',', $this->_actionNames);
  63. } else {
  64. $this->_actionNames = ($this->_actionNames) ? array($this->_actionNames) : array();
  65. }
  66. parent::init();
  67. return $this;
  68. }
  69. /**
  70. * getPersistentAttributes()
  71. *
  72. * @return array
  73. */
  74. public function getPersistentAttributes()
  75. {
  76. return array(
  77. 'projectProviderName' => $this->getProjectProviderName(),
  78. 'actionNames' => implode(',', $this->_actionNames)
  79. );
  80. }
  81. /**
  82. * getName()
  83. *
  84. * @return string
  85. */
  86. public function getName()
  87. {
  88. return 'ProjectProviderFile';
  89. }
  90. /**
  91. * getProjectProviderName()
  92. *
  93. * @return string
  94. */
  95. public function getProjectProviderName()
  96. {
  97. return $this->_projectProviderName;
  98. }
  99. /**
  100. * getContents()
  101. *
  102. * @return string
  103. */
  104. public function getContents()
  105. {
  106. $filter = new Zend_Filter_Word_DashToCamelCase();
  107. $className = $filter->filter($this->_projectProviderName) . 'Provider';
  108. $class = new Zend_CodeGenerator_Php_Class(array(
  109. 'name' => $className,
  110. 'extendedClass' => 'Zend_Tool_Project_Provider_Abstract'
  111. ));
  112. $methods = array();
  113. foreach ($this->_actionNames as $actionName) {
  114. $methods[] = new Zend_CodeGenerator_Php_Method(array(
  115. 'name' => $actionName,
  116. 'body' => ' /** @todo Implementation */'
  117. ));
  118. }
  119. if ($methods) {
  120. $class->setMethods($methods);
  121. }
  122. $codeGenFile = new Zend_CodeGenerator_Php_File(array(
  123. 'requiredFiles' => array(
  124. 'Zend/Tool/Project/Provider/Abstract.php',
  125. 'Zend/Tool/Project/Provider/Exception.php'
  126. ),
  127. 'classes' => array($class)
  128. ));
  129. return $codeGenFile->generate();
  130. }
  131. }