BootstrapFile.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. * @see Zend_Tool_Project_Context_Filesystem_File
  24. */
  25. require_once 'Zend/Tool/Project/Context/Filesystem/File.php';
  26. require_once 'Zend/Application.php';
  27. /**
  28. * This class is the front most class for utilizing Zend_Tool_Project
  29. *
  30. * A profile is a hierarchical set of resources that keep track of
  31. * items within a specific project.
  32. *
  33. * @category Zend
  34. * @package Zend_Tool
  35. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. class Zend_Tool_Project_Context_Zf_BootstrapFile extends Zend_Tool_Project_Context_Filesystem_File
  39. {
  40. /**
  41. * @var string
  42. */
  43. protected $_filesystemName = 'Bootstrap.php';
  44. protected $_applicationInstance = null;
  45. protected $_bootstrapInstance = null;
  46. /**
  47. * getName()
  48. *
  49. * @return string
  50. */
  51. public function getName()
  52. {
  53. return 'BootstrapFile';
  54. }
  55. public function init()
  56. {
  57. parent::init();
  58. $applicationConfigFile = $this->_resource->getProfile()->search('ApplicationConfigFile');
  59. $applicationDirectory = $this->_resource->getProfile()->search('ApplicationDirectory');
  60. if (($applicationConfigFile === false) || ($applicationDirectory === false)) {
  61. throw new Exception('To use the BootstrapFile context, your project requires the use of both the "ApplicationConfigFile" and "ApplicationDirectory" contexts.');
  62. }
  63. if ($applicationConfigFile->getContext()->exists()) {
  64. define('APPLICATION_PATH', $applicationDirectory->getPath());
  65. $applicationOptions = array();
  66. $applicationOptions['config'] = $applicationConfigFile->getPath();
  67. $this->_applicationInstance = new Zend_Application(
  68. 'development',
  69. $applicationOptions
  70. );
  71. }
  72. }
  73. /**
  74. * getContents()
  75. *
  76. * @return array
  77. */
  78. public function getContents()
  79. {
  80. $autoloadMethodBody =<<<EOS
  81. \$autoloader = new Zend_Application_Module_Autoloader(array(
  82. 'namespace' => 'Application_',
  83. 'basePath' => APPLICATION_PATH,
  84. ));
  85. return \$autoloader;
  86. EOS;
  87. $codeGenFile = new Zend_CodeGenerator_Php_File(array(
  88. 'classes' => array(
  89. new Zend_CodeGenerator_Php_Class(array(
  90. 'name' => 'Bootstrap',
  91. 'extendedClass' => 'Zend_Application_Bootstrap_Bootstrap',
  92. 'methods' => array(
  93. new Zend_CodeGenerator_Php_Method(array(
  94. 'name' => '_initAppAutoloader',
  95. 'body' => $autoloadMethodBody,
  96. ))
  97. )
  98. )),
  99. )
  100. ));
  101. return $codeGenFile->generate();
  102. }
  103. }