PageRenderTime 12ms CodeModel.GetById 6ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

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