|
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-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Layout.php 20785 2010-01-31 09:43:03Z mikaelkael $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Tool_Project_Provider_Abstract |
|
25 */ |
|
26 require_once 'Zend/Tool/Project/Provider/Abstract.php'; |
|
27 |
|
28 /** |
|
29 * @category Zend |
|
30 * @package Zend_Tool |
|
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
33 */ |
|
34 class Zend_Tool_Project_Provider_Layout extends Zend_Tool_Project_Provider_Abstract implements Zend_Tool_Framework_Provider_Pretendable |
|
35 { |
|
36 |
|
37 public static function createResource(Zend_Tool_Project_Profile $profile, $layoutName = 'layout') |
|
38 { |
|
39 $applicationDirectory = $profile->search('applicationDirectory'); |
|
40 $layoutDirectory = $applicationDirectory->search('layoutsDirectory'); |
|
41 |
|
42 if ($layoutDirectory == false) { |
|
43 $layoutDirectory = $applicationDirectory->createResource('layoutsDirectory'); |
|
44 } |
|
45 |
|
46 $layoutScriptsDirectory = $layoutDirectory->search('layoutScriptsDirectory'); |
|
47 |
|
48 if ($layoutScriptsDirectory == false) { |
|
49 $layoutScriptsDirectory = $layoutDirectory->createResource('layoutScriptsDirectory'); |
|
50 } |
|
51 |
|
52 $layoutScriptFile = $layoutScriptsDirectory->search('layoutScriptFile', array('layoutName' => 'layout')); |
|
53 |
|
54 if ($layoutScriptFile == false) { |
|
55 $layoutScriptFile = $layoutScriptsDirectory->createResource('layoutScriptFile', array('layoutName' => 'layout')); |
|
56 } |
|
57 |
|
58 return $layoutScriptFile; |
|
59 } |
|
60 |
|
61 public function enable() |
|
62 { |
|
63 $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); |
|
64 |
|
65 $applicationConfigResource = $profile->search('ApplicationConfigFile'); |
|
66 |
|
67 if (!$applicationConfigResource) { |
|
68 throw new Zend_Tool_Project_Exception('A project with an application config file is required to use this provider.'); |
|
69 } |
|
70 |
|
71 $zc = $applicationConfigResource->getAsZendConfig(); |
|
72 |
|
73 if (isset($zc->resources) && isset($zf->resources->layout)) { |
|
74 $this->_registry->getResponse()->appendContent('A layout resource already exists in this project\'s application configuration file.'); |
|
75 return; |
|
76 } |
|
77 |
|
78 $layoutPath = 'APPLICATION_PATH "/layouts/scripts/"'; |
|
79 |
|
80 if ($this->_registry->getRequest()->isPretend()) { |
|
81 $this->_registry->getResponse()->appendContent('Would add "resources.layout.layoutPath" key to the application config file.'); |
|
82 } else { |
|
83 $applicationConfigResource->addStringItem('resources.layout.layoutPath', $layoutPath, 'production', false); |
|
84 $applicationConfigResource->create(); |
|
85 |
|
86 $layoutScriptFile = self::createResource($profile); |
|
87 |
|
88 $layoutScriptFile->create(); |
|
89 |
|
90 $this->_registry->getResponse()->appendContent( |
|
91 'Layouts have been enabled, and a default layout created at ' |
|
92 . $layoutScriptFile->getPath() |
|
93 ); |
|
94 |
|
95 $this->_registry->getResponse()->appendContent('A layout entry has been added to the application config file.'); |
|
96 } |
|
97 |
|
98 |
|
99 |
|
100 } |
|
101 |
|
102 public function disable() |
|
103 { |
|
104 // @todo |
|
105 } |
|
106 |
|
107 |
|
108 |
|
109 } |