Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

2 participants

@adamlundrigan

No description provided.

@weierophinney

Reviewed, merged, and pushed to master - thanks!

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.
Showing with 49 additions and 7 deletions.
  1. +49 −7 library/Zend/Tool/Project/Provider/Layout.php
View
56 library/Zend/Tool/Project/Provider/Layout.php
@@ -25,6 +25,7 @@
namespace Zend\Tool\Project\Provider;
use Zend\Tool\Project\Profile\Profile as ProjectProfile;
+use Zend\Tool\Project\Exception\RuntimeException as ProjectRuntimeException;
/**
* @uses \Zend\Tool\Framework\Provider\Pretendable
@@ -39,6 +40,11 @@ class Layout
extends AbstractProvider
implements \Zend\Tool\Framework\Provider\Pretendable
{
+ /**
+ * @var string Layout path
+ */
+ protected $_layoutPath = 'APPLICATION_PATH "/layouts/scripts/"';
+
public static function createResource(ProjectProfile $profile, $layoutName = 'layout')
{
@@ -81,12 +87,10 @@ public function enable()
return;
}
- $layoutPath = 'APPLICATION_PATH "/layouts/scripts/"';
-
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', $layoutPath, 'production', false);
+ $applicationConfigResource->addStringItem('resources.layout.layoutPath', $this->_layoutPath, 'production', false);
$applicationConfigResource->create();
$layoutScriptFile = self::createResource($profile);
@@ -99,6 +103,7 @@ public function enable()
);
$this->_registry->getResponse()->appendContent('A layout entry has been added to the application config file.');
+ $this->_storeProfile();
}
@@ -107,9 +112,46 @@ public function enable()
public function disable()
{
- // @todo
+ $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();
+
+ // Delete layoutsDirectory entry from .zfproject.xml
+ $applicationDirectory = $profile->search('applicationDirectory');
+ $layoutDirectory = $applicationDirectory->search('layoutsDirectory');
+ if ($layoutDirectory !== false) {
+ $layoutDirectory->setDeleted();
+ }
+
+ // 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(ProjectProfile $profile)
+ {
+ $applicationConfigResource = $profile->search('ApplicationConfigFile');
+ if (!$applicationConfigResource) {
+ throw new ProjectRuntimeException('A project with an application config file is required to use this provider.');
+ }
+
+ return $applicationConfigResource;
}
-
-
-
}
+
Something went wrong with that request. Please try again.