File indexing completed on 2024-06-23 05:55:50

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_Zf_BootstrapFile extends Zend_Tool_Project_Context_Filesystem_File
0035 {
0036 
0037     /**
0038      * @var string
0039      */
0040     protected $_filesystemName = 'Bootstrap.php';
0041 
0042     /**
0043      * @var Zend_Tool_Project_Profile_Resource
0044      */
0045     protected $_applicationConfigFile = null;
0046 
0047     /**
0048      * @var Zend_Tool_Project_Profile_Resource
0049      */
0050     protected $_applicationDirectory = null;
0051 
0052     /**
0053      * @var Zend_Application
0054      */
0055     protected $_applicationInstance = null;
0056 
0057 
0058     /**
0059      * getName()
0060      *
0061      * @return string
0062      */
0063     public function getName()
0064     {
0065         return 'BootstrapFile';
0066     }
0067 
0068     public function init()
0069     {
0070         parent::init();
0071 
0072         $this->_applicationConfigFile = $this->_resource->getProfile()->search('ApplicationConfigFile');
0073         $this->_applicationDirectory = $this->_resource->getProfile()->search('ApplicationDirectory');
0074 
0075         if (($this->_applicationConfigFile === false) || ($this->_applicationDirectory === false)) {
0076             throw new Exception('To use the BootstrapFile context, your project requires the use of both the "ApplicationConfigFile" and "ApplicationDirectory" contexts.');
0077         }
0078 
0079 
0080     }
0081 
0082     /**
0083      * getContents()
0084      *
0085      * @return array
0086      */
0087     public function getContents()
0088     {
0089 
0090         $codeGenFile = new Zend_CodeGenerator_Php_File(array(
0091             'classes' => array(
0092                 new Zend_CodeGenerator_Php_Class(array(
0093                     'name' => 'Bootstrap',
0094                     'extendedClass' => 'Zend_Application_Bootstrap_Bootstrap',
0095                     )),
0096                 )
0097             ));
0098 
0099         return $codeGenFile->generate();
0100     }
0101 
0102     public function getApplicationInstance()
0103     {
0104         if ($this->_applicationInstance == null) {
0105             if ($this->_applicationConfigFile->getContext()->exists()) {
0106                 define('APPLICATION_PATH', $this->_applicationDirectory->getPath());
0107                 $applicationOptions = array();
0108                 $applicationOptions['config'] = $this->_applicationConfigFile->getPath();
0109 
0110                 $this->_applicationInstance = new Zend_Application(
0111                     'development',
0112                     $applicationOptions
0113                     );
0114             }
0115         }
0116 
0117         return $this->_applicationInstance;
0118     }
0119 }