Skip to content
This repository

[hotfix/ZF-11516] Implement "disable layout" command in Zend\Tool #360

Closed
wants to merge 1 commit into from

2 participants

Adam Lundrigan Matthew Weier O'Phinney
Adam Lundrigan

No description provided.

Matthew Weier O'Phinney
Owner

Reviewed, merged, and pushed to master - thanks!

Matthew Weier O'Phinney weierophinney closed this August 30, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
56  library/Zend/Tool/Project/Provider/Layout.php
@@ -25,6 +25,7 @@
25 25
 namespace Zend\Tool\Project\Provider;
26 26
 
27 27
 use Zend\Tool\Project\Profile\Profile as ProjectProfile;
  28
+use Zend\Tool\Project\Exception\RuntimeException as ProjectRuntimeException;
28 29
 
29 30
 /**
30 31
  * @uses       \Zend\Tool\Framework\Provider\Pretendable
@@ -39,6 +40,11 @@ class Layout
39 40
     extends AbstractProvider 
40 41
     implements \Zend\Tool\Framework\Provider\Pretendable
41 42
 {
  43
+    /**
  44
+     * @var string Layout path
  45
+     */
  46
+    protected $_layoutPath = 'APPLICATION_PATH "/layouts/scripts/"';
  47
+
42 48
     
43 49
     public static function createResource(ProjectProfile $profile, $layoutName = 'layout')
44 50
     {
@@ -81,12 +87,10 @@ public function enable()
81 87
             return;
82 88
         }
83 89
         
84  
-        $layoutPath = 'APPLICATION_PATH "/layouts/scripts/"';
85  
-        
86 90
         if ($this->_registry->getRequest()->isPretend()) {
87 91
             $this->_registry->getResponse()->appendContent('Would add "resources.layout.layoutPath" key to the application config file.');
88 92
         } else {
89  
-            $applicationConfigResource->addStringItem('resources.layout.layoutPath', $layoutPath, 'production', false);
  93
+            $applicationConfigResource->addStringItem('resources.layout.layoutPath', $this->_layoutPath, 'production', false);
90 94
             $applicationConfigResource->create(); 
91 95
             
92 96
             $layoutScriptFile = self::createResource($profile);
@@ -99,6 +103,7 @@ public function enable()
99 103
                 );
100 104
                 
101 105
             $this->_registry->getResponse()->appendContent('A layout entry has been added to the application config file.');
  106
+            $this->_storeProfile();
102 107
         }
103 108
         
104 109
        
@@ -107,9 +112,46 @@ public function enable()
107 112
     
108 113
     public function disable()
109 114
     {
110  
-        // @todo
  115
+        $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
  116
+
  117
+        $applicationConfigResource = $this->_getApplicationConfigResource($profile);
  118
+        $zc = $applicationConfigResource->getAsZendConfig();
  119
+
  120
+        if (isset($zc->resources) && !isset($zc->resources->layout)) {
  121
+            $this->_registry->getResponse()->appendContent('No layout configuration exists in application config file.');
  122
+            return;
  123
+        }
  124
+
  125
+        if ($this->_registry->getRequest()->isPretend()) {
  126
+            $this->_registry->getResponse()->appendContent('Would remove "resources.layout.layoutPath" key from the application config file.');
  127
+        } else {
  128
+
  129
+            // Remove the resources.layout.layoutPath directive from application config
  130
+            $applicationConfigResource->removeStringItem('resources.layout.layoutPath', $this->_layoutPath, 'production', false);
  131
+            $applicationConfigResource->create();
  132
+
  133
+            // Delete layoutsDirectory entry from .zfproject.xml
  134
+            $applicationDirectory = $profile->search('applicationDirectory');
  135
+            $layoutDirectory = $applicationDirectory->search('layoutsDirectory');
  136
+            if ($layoutDirectory !== false) {
  137
+                $layoutDirectory->setDeleted();
  138
+            }
  139
+
  140
+            // Tell the user about the good work we've done
  141
+            $this->_registry->getResponse()->appendContent('Layout entry has been removed from the application config file.');
  142
+
  143
+            $this->_storeProfile();
  144
+        }
  145
+     }
  146
+
  147
+    protected function _getApplicationConfigResource(ProjectProfile $profile)
  148
+    {
  149
+        $applicationConfigResource = $profile->search('ApplicationConfigFile');
  150
+        if (!$applicationConfigResource) {
  151
+            throw new ProjectRuntimeException('A project with an application config file is required to use this provider.');
  152
+        }
  153
+
  154
+        return $applicationConfigResource;
111 155
     }
112  
-    
113  
-    
114  
-    
115 156
 }
  157
+
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.