Ver Fonte

ZF-7940
- Added Application config writer removal functionality
- Added Application provider namespace change functionality
- Added USERPROFILE as option for win32 (vista) home path recognition
- Cleaned up project provider
- Deleted rouge Utilty files (accidentally commited previously)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20252 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph há 16 anos atrás
pai
commit
893803b0cf

+ 20 - 4
bin/zf.php

@@ -197,6 +197,17 @@ class ZF
                 $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
             }
         }
+
+        $homeDirectory = getenv('USERPROFILE');
+        
+        if ($homeDirectory) {
+            $this->_logMessage('Home directory found in environment variable USERPROFILE with value ' . $homeDirectory, $returnMessages);
+            if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
+                return $homeDirectory;
+            } else {
+                $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
+            }
+        }
         
         return false;
     }
@@ -325,13 +336,18 @@ class ZF
     protected function _setupToolRuntime()
     {
 
-        // last ditch efforts
-        if ($this->_tryClientLoad()) {
-            return;
+        $includePathPrepend = getenv('ZEND_TOOL_INCLUDE_PATH_PREPEND');
+        $includePathFull = getenv('ZEND_TOOL_INCLUDE_PATH');
+        
+        // check if the user has not provided anything
+        if (!($includePathPrepend || $includePathFull)) {
+            if ($this->_tryClientLoad()) {
+                return;
+            }
         }
         
         // if ZF is not in the include_path, but relative to this file, put it in the include_path
-        if (($includePathPrepend = getenv('ZEND_TOOL_INCLUDE_PATH_PREPEND')) || ($includePathFull = getenv('ZEND_TOOL_INCLUDE_PATH'))) {
+        if ($includePathPrepend || $includePathFull) {
             if (isset($includePathPrepend) && ($includePathPrepend !== false)) {
                 set_include_path($includePathPrepend . PATH_SEPARATOR . get_include_path());
             } elseif (isset($includePathFull) && ($includePathFull !== false)) {

+ 60 - 9
library/Zend/Tool/Project/Context/Zf/ApplicationConfigFile.php

@@ -127,6 +127,7 @@ class Zend_Tool_Project_Context_Zf_ApplicationConfigFile extends Zend_Tool_Proje
             }
             
             if ($insideSection) {
+                // if its blank, or a section heading
                 if ((trim($contentLine) == null) || ($contentLines[$contentLineIndex + 1][0] == '[')) {
                     $newLines[] = $key . ' = ' . $value . "\n";
                     $insideSection = null;
@@ -179,15 +180,65 @@ class Zend_Tool_Project_Context_Zf_ApplicationConfigFile extends Zend_Tool_Proje
         return $this;
     }
     
-//    public function removeStringItem($key, $section = 'production')
-//    {
-//        
-//    }
-//    
-//    public function removeItem($item, $section = 'production')
-//    {
-//        
-//    }
+    public function removeStringItem($key, $section = 'production')
+    {
+        $contentLines = file($this->getPath());
+        
+        $newLines = array();
+        $insideSection = false;
+        
+        foreach ($contentLines as $contentLineIndex => $contentLine) {
+            
+            if ($insideSection === false && preg_match('#^\[' . $section . '#', $contentLine)) {
+                $insideSection = true;
+            }
+            
+            if ($insideSection) {
+                // if its blank, or a section heading
+                if ((trim($contentLine) == null) || ($contentLines[$contentLineIndex + 1][0] == '[')) {
+                    $insideSection = null;
+                }
+            }
+            
+            if (!preg_match('#' . $key . '\s?=.*#', $contentLine)) { 
+                $newLines[] = $contentLine;
+            }
+        }
+
+        $this->_content = implode('', $newLines);
+    }
+    
+    public function removeItem($item, $section = 'production')
+    {
+        $stringItems = array();
+        $stringValues = array();
+        $configKeyNames = array();
+        
+        $rii = new RecursiveIteratorIterator(
+            new RecursiveArrayIterator($item),
+            RecursiveIteratorIterator::SELF_FIRST
+            );
+        
+        $lastDepth = 0;
+        
+        // loop through array structure recursively to create proper keys
+        foreach ($rii as $name => $value) {
+            $lastDepth = $rii->getDepth();
+            
+            if (is_array($value)) {
+                array_push($configKeyNames, $name);
+            } else {
+                $stringItems[] = implode('.', $configKeyNames) . '.' . $name;
+                $stringValues[] = $value;
+            }
+        }
+        
+        foreach ($stringItems as $stringItemIndex => $stringItem) {
+            $this->removeStringItem($stringItem, $section);
+        }
+        
+        return $this;
+    }
     
     protected function _getDefaultContents()
     {

+ 28 - 1
library/Zend/Tool/Project/Provider/Application.php

@@ -26,14 +26,41 @@
  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Tool_Project_Provider_Application extends Zend_Tool_Project_Provider_Abstract
+class Zend_Tool_Project_Provider_Application 
+    extends Zend_Tool_Project_Provider_Abstract
+    implements Zend_Tool_Framework_Provider_Pretendable
 {
     
     protected $_specialties = array('ClassNamePrefix');
     
     public function changeClassNamePrefix($classNamePrefix, $force = false)
     {
+        $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
         
+        $configFileResource = $profile->search('ApplicationConfigFile');
+        $zc = $configFileResource->getAsZendConfig('production');
+        if ($zc->appnamespace == $classNamePrefix) {
+            throw new Zend_Tool_Project_Exception('The requested name ' . $classNamePrefix . ' is already the prefix.');
+        }
+
+        // remove the old
+        $configFileResource->removeStringItem('appnamespace', 'production');
+        $configFileResource->create();
+        
+        // add the new
+        $configFileResource->addStringItem('appnamespace', $classNamePrefix, 'production', true);
+        $configFileResource->create();
+        
+        // update the project profile
+        $applicationDirectory = $profile->search('ApplicationDirectory');
+        $applicationDirectory->setClassNamePrefix($classNamePrefix);
+
+        // note to the user
+        $this->_registry->getResponse()->appendContent('application.ini updated with new appnamespace ' . $classNamePrefix);
+        $this->_registry->getResponse()->appendContent('Note: All existing models will need to be altered to this new namespace by hand', array('color' => 'yellow'));
+        
+        // store profile
+        $this->_storeProfile();
     }
     
 }

+ 63 - 63
library/Zend/Tool/Project/Provider/Project.php

@@ -116,69 +116,69 @@ class Zend_Tool_Project_Provider_Project
     {
         $data = <<<EOS
 <?xml version="1.0" encoding="UTF-8"?>
-    <projectProfile type="default" version="1.10">
-        <projectDirectory>
-            <projectProfileFile />
-            <applicationDirectory>
-                <apisDirectory enabled="false" />
-                <configsDirectory>
-                    <applicationConfigFile type="ini" />
-                </configsDirectory>
-                <controllersDirectory>
-                    <controllerFile controllerName="Index">
-                        <actionMethod actionName="index" />
-                    </controllerFile>
-                    <controllerFile controllerName="Error" />
-                </controllersDirectory>
-                <formsDirectory enabled="false" />
-                <layoutsDirectory enabled="false" />
-                <modelsDirectory />
-                <modulesDirectory enabled="false" />
-                <viewsDirectory>
-                    <viewScriptsDirectory>
-                        <viewControllerScriptsDirectory forControllerName="Index">
-                            <viewScriptFile forActionName="index" />
-                        </viewControllerScriptsDirectory>
-                        <viewControllerScriptsDirectory forControllerName="Error">
-                            <viewScriptFile forActionName="error" />
-                        </viewControllerScriptsDirectory>
-                    </viewScriptsDirectory>
-                    <viewHelpersDirectory />
-                    <viewFiltersDirectory enabled="false" />
-                </viewsDirectory>
-                <bootstrapFile />
-            </applicationDirectory>
-            <dataDirectory enabled="false">
-                <cacheDirectory enabled="false" />
-                <searchIndexesDirectory enabled="false" />
-                <localesDirectory enabled="false" />
-                <logsDirectory enabled="false" />
-                <sessionsDirectory enabled="false" />
-                <uploadsDirectory enabled="false" />
-            </dataDirectory>
-            <libraryDirectory>
-                <zfStandardLibraryDirectory enabled="false" />
-            </libraryDirectory>
-            <publicDirectory>
-                <publicStylesheetsDirectory enabled="false" />
-                <publicScriptsDirectory enabled="false" />
-                <publicImagesDirectory enabled="false" />
-                <publicIndexFile />
-                <htaccessFile />
-            </publicDirectory>
-            <projectProvidersDirectory enabled="false" />
-            <temporaryDirectory enabled="false" />
-            <testsDirectory>
-                <testPHPUnitConfigFile />
-                <testApplicationDirectory>
-                    <testApplicationBootstrapFile />
-                </testApplicationDirectory>
-                <testLibraryDirectory>
-                    <testLibraryBootstrapFile />
-                </testLibraryDirectory>
-            </testsDirectory>
-        </projectDirectory>
-    </projectProfile>
+<projectProfile type="default" version="1.10">
+    <projectDirectory>
+        <projectProfileFile />
+        <applicationDirectory>
+            <apisDirectory enabled="false" />
+            <configsDirectory>
+                <applicationConfigFile type="ini" />
+            </configsDirectory>
+            <controllersDirectory>
+                <controllerFile controllerName="Index">
+                    <actionMethod actionName="index" />
+                </controllerFile>
+                <controllerFile controllerName="Error" />
+            </controllersDirectory>
+            <formsDirectory enabled="false" />
+            <layoutsDirectory enabled="false" />
+            <modelsDirectory />
+            <modulesDirectory enabled="false" />
+            <viewsDirectory>
+                <viewScriptsDirectory>
+                    <viewControllerScriptsDirectory forControllerName="Index">
+                        <viewScriptFile forActionName="index" />
+                    </viewControllerScriptsDirectory>
+                    <viewControllerScriptsDirectory forControllerName="Error">
+                        <viewScriptFile forActionName="error" />
+                    </viewControllerScriptsDirectory>
+                </viewScriptsDirectory>
+                <viewHelpersDirectory />
+                <viewFiltersDirectory enabled="false" />
+            </viewsDirectory>
+            <bootstrapFile />
+        </applicationDirectory>
+        <dataDirectory enabled="false">
+            <cacheDirectory enabled="false" />
+            <searchIndexesDirectory enabled="false" />
+            <localesDirectory enabled="false" />
+            <logsDirectory enabled="false" />
+            <sessionsDirectory enabled="false" />
+            <uploadsDirectory enabled="false" />
+        </dataDirectory>
+        <libraryDirectory>
+            <zfStandardLibraryDirectory enabled="false" />
+        </libraryDirectory>
+        <publicDirectory>
+            <publicStylesheetsDirectory enabled="false" />
+            <publicScriptsDirectory enabled="false" />
+            <publicImagesDirectory enabled="false" />
+            <publicIndexFile />
+            <htaccessFile />
+        </publicDirectory>
+        <projectProvidersDirectory enabled="false" />
+        <temporaryDirectory enabled="false" />
+        <testsDirectory>
+            <testPHPUnitConfigFile />
+            <testApplicationDirectory>
+                <testApplicationBootstrapFile />
+            </testApplicationDirectory>
+            <testLibraryDirectory>
+                <testLibraryBootstrapFile />
+            </testLibraryDirectory>
+        </testsDirectory>
+    </projectDirectory>
+</projectProfile>
 EOS;
         return $data;
     }

+ 0 - 81
library/Zend/Tool/Project/Utility/ApplicationConfigWriter.php

@@ -1,81 +0,0 @@
-<?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
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
- * @license    http://framework.zend.com/license/new-bsd     New BSD License
- */
-
-/**
- * @category   Zend
- * @package    Zend_Tool
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
- * @license    http://framework.zend.com/license/new-bsd     New BSD License
- */
-class Zend_Tool_Project_Utility_ApplicationConfigWriter
-{
-    
-    public function setFilename()
-    {
-        
-    }
-    
-    
-    protected function _writeArrayToConfig($configArray)
-    {
-        
-    }
-    
-    protected function _writeStringToConfig()
-    {
-        $configKeyNames = array('resources', 'db');
-        
-        $newDbLines = array();
-        
-
-        
-        $originalLines = file($this->_appConfigFilePath);
-        
-        $newLines = array();
-        $insideSection = false;
-        
-        foreach ($originalLines as $originalLineIndex => $originalLine) {
-            
-            if ($insideSection === false && preg_match('#^\[' . $this->_sectionName . '#', $originalLine)) {
-                $insideSection = true;
-            }
-            
-            if ($insideSection) {
-                if ((trim($originalLine) == null) || ($originalLines[$originalLineIndex + 1][0] == '[')) {
-                    foreach ($newDbLines as $newDbLine) {
-                        $newLines[] = $newDbLine;
-                    }
-                    $insideSection = null;
-                }
-            }
-            
-            $newLines[] = $originalLine;
-        }
-
-        $newConfigContents = implode('', $newLines);
-        
-        if (!$isPretend) {
-            file_put_contents($this->_appConfigFilePath, $newConfigContents);
-        }
-        
-        return $newConfigContents;
-    }
-    
-}