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