1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Provider_Abstract
*/
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Layout extends Zend_Tool_Project_Provider_Abstract implements Zend_Tool_Framework_Provider_Pretendable
{
/**
* @var string Layout path
*/
protected $_layoutPath = 'APPLICATION_PATH "/layouts/scripts/"';
public static function createResource(Zend_Tool_Project_Profile $profile, $layoutName = 'layout')
{
$applicationDirectory = $profile->search('applicationDirectory');
$layoutDirectory = $applicationDirectory->search('layoutsDirectory');
if ($layoutDirectory == false) {
$layoutDirectory = $applicationDirectory->createResource('layoutsDirectory');
}
$layoutScriptsDirectory = $layoutDirectory->search('layoutScriptsDirectory');
if ($layoutScriptsDirectory == false) {
$layoutScriptsDirectory = $layoutDirectory->createResource('layoutScriptsDirectory');
}
$layoutScriptFile = $layoutScriptsDirectory->search('layoutScriptFile', array('layoutName' => 'layout'));
if ($layoutScriptFile == false) {
$layoutScriptFile = $layoutScriptsDirectory->createResource('layoutScriptFile', array('layoutName' => 'layout'));
}
return $layoutScriptFile;
}
public function enable()
{
$profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
$applicationConfigResource = $profile->search('ApplicationConfigFile');
if (!$applicationConfigResource) {
throw new Zend_Tool_Project_Exception('A project with an application config file is required to use this provider.');
}
$zc = $applicationConfigResource->getAsZendConfig();
if (isset($zc->resources) && isset($zc->resources->layout)) {
$this->_registry->getResponse()->appendContent('A layout resource already exists in this project\'s application configuration file.');
return;
}
if ($this->_registry->getRequest()->isPretend()) {
$this->_registry->getResponse()->appendContent('Would add "resources.layout.layoutPath" key to the application config file.');
} else {
$applicationConfigResource->addStringItem('resources.layout.layoutPath', $this->_layoutPath, 'production', false);
$applicationConfigResource->create();
$this->_registry->getResponse()->appendContent('A layout entry has been added to the application config file.');
$layoutScriptFile = self::createResource($profile);
if (!$layoutScriptFile->exists()) {
$layoutScriptFile->create();
$this->_registry->getResponse()->appendContent(
'A default layout has been created at '
. $layoutScriptFile->getPath()
);
}
$this->_storeProfile();
}
}
public function disable()
{
$profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
$applicationConfigResource = $this->_getApplicationConfigResource($profile);
$zc = $applicationConfigResource->getAsZendConfig();
if (isset($zc->resources) && !isset($zc->resources->layout)) {
$this->_registry->getResponse()->appendContent('No layout configuration exists in application config file.');
return;
}
if ($this->_registry->getRequest()->isPretend()) {
$this->_registry->getResponse()->appendContent('Would remove "resources.layout.layoutPath" key from the application config file.');
} else {
// Remove the resources.layout.layoutPath directive from application config
$applicationConfigResource->removeStringItem('resources.layout.layoutPath', $this->_layoutPath, 'production', false);
$applicationConfigResource->create();
// Tell the user about the good work we've done
$this->_registry->getResponse()->appendContent('Layout entry has been removed from the application config file.');
$this->_storeProfile();
}
}
protected function _getApplicationConfigResource(Zend_Tool_Project_Profile $profile)
{
$applicationConfigResource = $profile->search('ApplicationConfigFile');
if (!$applicationConfigResource) {
throw new Zend_Tool_Project_Exception('A project with an application config file is required to use this provider.');
}
return $applicationConfigResource;
}
}
|