/library/Zend/Tool/Project/Context/Zf/BootstrapFile.php

https://bitbucket.org/hamidrezas/melobit · PHP · 119 lines · 48 code · 18 blank · 53 comment · 5 complexity · 62cb98f30e511b62d723c593f01abb57 MD5 · raw file

  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: BootstrapFile.php 24594 2012-01-05 21:27:01Z matthew $
  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-2012 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_Zf_BootstrapFile extends Zend_Tool_Project_Context_Filesystem_File
  34. {
  35. /**
  36. * @var string
  37. */
  38. protected $_filesystemName = 'Bootstrap.php';
  39. /**
  40. * @var Zend_Tool_Project_Profile_Resource
  41. */
  42. protected $_applicationConfigFile = null;
  43. /**
  44. * @var Zend_Tool_Project_Profile_Resource
  45. */
  46. protected $_applicationDirectory = null;
  47. /**
  48. * @var Zend_Application
  49. */
  50. protected $_applicationInstance = null;
  51. /**
  52. * getName()
  53. *
  54. * @return string
  55. */
  56. public function getName()
  57. {
  58. return 'BootstrapFile';
  59. }
  60. public function init()
  61. {
  62. parent::init();
  63. $this->_applicationConfigFile = $this->_resource->getProfile()->search('ApplicationConfigFile');
  64. $this->_applicationDirectory = $this->_resource->getProfile()->search('ApplicationDirectory');
  65. if (($this->_applicationConfigFile === false) || ($this->_applicationDirectory === false)) {
  66. throw new Exception('To use the BootstrapFile context, your project requires the use of both the "ApplicationConfigFile" and "ApplicationDirectory" contexts.');
  67. }
  68. }
  69. /**
  70. * getContents()
  71. *
  72. * @return array
  73. */
  74. public function getContents()
  75. {
  76. $codeGenFile = new Zend_CodeGenerator_Php_File(array(
  77. 'classes' => array(
  78. new Zend_CodeGenerator_Php_Class(array(
  79. 'name' => 'Bootstrap',
  80. 'extendedClass' => 'Zend_Application_Bootstrap_Bootstrap',
  81. )),
  82. )
  83. ));
  84. return $codeGenFile->generate();
  85. }
  86. public function getApplicationInstance()
  87. {
  88. if ($this->_applicationInstance == null) {
  89. if ($this->_applicationConfigFile->getContext()->exists()) {
  90. define('APPLICATION_PATH', $this->_applicationDirectory->getPath());
  91. $applicationOptions = array();
  92. $applicationOptions['config'] = $this->_applicationConfigFile->getPath();
  93. $this->_applicationInstance = new Zend_Application(
  94. 'development',
  95. $applicationOptions
  96. );
  97. }
  98. }
  99. return $this->_applicationInstance;
  100. }
  101. }