Просмотр исходного кода

ZF-9045
- Added support to accept controller names in camelCase format, but note to user
- Added support to accept action names in mixedCase format, but note to user
- Added version & type support to the project profile (for tracking and later features)
- Fixed Application namespaces issues with persisting name
- Cleaned up method signatures in various providers

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

ralph 16 лет назад
Родитель
Сommit
ea4d7101fb

+ 0 - 4
library/Zend/Tool/Framework/Client/Abstract.php

@@ -315,10 +315,6 @@ abstract class Zend_Tool_Framework_Client_Abstract implements Zend_Tool_Framewor
             }
         }
 
-//        if ($specialtyName != '_Global') {
-//            $methodName .= $specialtyName;
-//        }
-
         $this->_handleDispatchExecution($provider, $methodName, $callParameters);
     }
     

+ 2 - 2
library/Zend/Tool/Project/Context/System/ProjectProfileFile.php

@@ -66,7 +66,7 @@ class Zend_Tool_Project_Context_System_ProjectProfileFile
      * @var Zend_Tool_Project_Profile
      */
     protected $_profile = null;
-
+    
     /**
      * getName()
      *
@@ -76,7 +76,7 @@ class Zend_Tool_Project_Context_System_ProjectProfileFile
     {
         return 'ProjectProfileFile';
     }
-
+    
     /**
      * setProfile()
      *

+ 1 - 2
library/Zend/Tool/Project/Context/Zf/ApplicationConfigFile.php

@@ -116,8 +116,7 @@ class Zend_Tool_Project_Context_Zf_ApplicationConfigFile extends Zend_Tool_Proje
      */
     public function addStringItem($key, $value, $section = 'production', $quoteValue = true)
     {
-        
-        
+        // null quote value means to auto-detect
         if ($quoteValue === null) {
             $quoteValue = preg_match('#[\"\']#', $value) ? false : true;
         }

+ 3 - 1
library/Zend/Tool/Project/Context/Zf/ApplicationDirectory.php

@@ -45,7 +45,9 @@ class Zend_Tool_Project_Context_Zf_ApplicationDirectory extends Zend_Tool_Projec
     
     public function init()
     {
-        $this->_classNamePrefix = $this->_resource->getAttribute('classNamePrefix');
+        if ($this->_resource->hasAttribute('classNamePrefix')) {
+            $this->_classNamePrefix = $this->_resource->getAttribute('classNamePrefix');
+        }
         parent::init();
     }
     

+ 0 - 6
library/Zend/Tool/Project/Context/Zf/DbTableFile.php

@@ -82,12 +82,6 @@ class Zend_Tool_Project_Context_Zf_DbTableFile extends Zend_Tool_Project_Context
                             'defaultValue' => $this->_actualTableName
                             ))
                         ),
-//                    'methods' => array(
-//                        new Zend_CodeGenerator_Php_Method(array(
-//                            'name' => 'init',
-//                            'body' => '/* Form Elements & Other Definitions Here ... */',
-//                            ))
-//                        )
                 
                     ))
                 )

+ 1 - 6
library/Zend/Tool/Project/Profile.php

@@ -48,12 +48,7 @@ class Zend_Tool_Project_Profile extends Zend_Tool_Project_Profile_Resource_Conta
      * @var bool
      */
     protected static $_traverseEnabled = false;
-
-    /**
-     * @var array
-     */
-    protected $_attributes = array();
-
+    
     /**
      * Constructor, standard usage would allow the setting of options
      *

+ 18 - 4
library/Zend/Tool/Project/Profile/FileParser/Xml.php

@@ -69,8 +69,13 @@ class Zend_Tool_Project_Profile_FileParser_Xml implements Zend_Tool_Project_Prof
         $this->_profile = $profile;
         $xmlElement = new SimpleXMLElement('<projectProfile />');
 
-//        $xmlElement->addAttribute('version', $profile->getVersion());
-//        $xmlElement->addAttribute('type', $profile->getType());
+        if ($profile->hasAttribute('type')) {
+            $xmlElement->addAttribute('type', $profile->getAttribute('type'));
+        }
+        
+        if ($profile->hasAttribute('version')) {
+            $xmlElement->addAttribute('version', $profile->getAttribute('version'));
+        }
         
         self::_serializeRecurser($profile, $xmlElement);
 
@@ -106,10 +111,19 @@ class Zend_Tool_Project_Profile_FileParser_Xml implements Zend_Tool_Project_Prof
         if ($xmlDataIterator->getName() != 'projectProfile') {
             throw new Exception('Profiles must start with a projectProfile node');
         }
-
-
+        
+        if (isset($xmlDataIterator['type'])) {
+            $this->_profile->setAttribute('type', (string) $xmlDataIterator['type']);
+        }
+        
+        if (isset($xmlDataIterator['version'])) {
+            $this->_profile->setAttribute('version', (string) $xmlDataIterator['version']);
+        }
+        
+        // start un-serialization of the xml doc
         $this->_unserializeRecurser($xmlDataIterator);
 
+        // contexts should be initialized after the unwinding of the profile structure
         $this->_lazyLoadContexts();
 
         return $this->_profile;

+ 16 - 0
library/Zend/Tool/Project/Profile/Resource/Container.php

@@ -50,6 +50,11 @@ class Zend_Tool_Project_Profile_Resource_Container implements RecursiveIterator,
      * @var bool
      */
     protected $_appendable = true;
+    
+    /**
+     * @var array
+     */
+    protected $_attributes = array();
 
     /**
      * Finder method to be able to find resources by context name
@@ -248,6 +253,17 @@ class Zend_Tool_Project_Profile_Resource_Container implements RecursiveIterator,
     {
         return (array_key_exists($name, $this->_attributes)) ? $this->_attributes[$name] : null;
     }
+    
+    /**
+     * hasAttribute()
+     * 
+     * @param string $name
+     * @return bool
+     */
+    public function hasAttribute($name)
+    {
+        return array_key_exists($name, $this->_attributes);
+    }
 
     /**
      * setAppendable()

+ 43 - 10
library/Zend/Tool/Project/Provider/Action.php

@@ -126,32 +126,65 @@ class Zend_Tool_Project_Provider_Action
      * @param bool $viewIncluded     Whether the view should the view be included.
      * @param string $module         Module name action should be applied to.
      */
-    public function create($name, $controllerName = 'index', $viewIncluded = true, $module = null)
+    public function create($name, $controllerName = 'Index', $viewIncluded = true, $module = null)
     {
 
         $this->_loadProfile();
 
-        if (self::hasResource($this->_loadedProfile, $name, $controllerName, $module)) {
-            throw new Zend_Tool_Project_Provider_Exception('This controller (' . $controllerName . ') already has an action named (' . $name . ')');
-        }
-
         // Check that there is not a dash or underscore, return if doesnt match regex
         if (preg_match('#[_-]#', $name)) {
             throw new Zend_Tool_Project_Provider_Exception('Action names should be camel cased.');
         }
         
+        $originalName = $name;
+        $originalControllerName = $controllerName;
+        
         // ensure it is camelCase (lower first letter)
         $name = strtolower(substr($name, 0, 1)) . substr($name, 1);
         
+        // ensure controller is MixedCase
+        $controllerName = ucfirst($controllerName);
+        
+        if (self::hasResource($this->_loadedProfile, $name, $controllerName, $module)) {
+            throw new Zend_Tool_Project_Provider_Exception('This controller (' . $controllerName . ') already has an action named (' . $name . ')');
+        }
+        
         $actionMethod = self::createResource($this->_loadedProfile, $name, $controllerName, $module);
 
-        if ($this->_registry->getRequest()->isPretend()) {
-            $this->_registry->getResponse()->appendContent(
+        // get request/response object
+        $request = $this->_registry->getRequest();
+        $response = $this->_registry->getResponse();
+        
+        // alert the user about inline converted names
+        $tense = (($request->isPretend()) ? 'would be' : 'is');
+        
+        if ($name !== $originalName) {
+            $response->appendContent(
+                'Note: The canonical action name that ' . $tense
+                    . ' used with other providers is "' . $name . '";'
+                    . ' not "' . $originalName . '" as supplied',
+                array('color' => array('yellow'))
+                );
+        }
+        
+        if ($controllerName !== $originalControllerName) {
+            $response->appendContent(
+                'Note: The canonical controller name that ' . $tense
+                    . ' used with other providers is "' . $controllerName . '";'
+                    . ' not "' . $originalControllerName . '" as supplied',
+                array('color' => array('yellow'))
+                );
+        }
+        
+        unset($tense);
+        
+        if ($request->isPretend()) {
+            $response->appendContent(
                 'Would create an action named ' . $name .
                 ' inside controller at ' . $actionMethod->getParentResource()->getContext()->getPath()
                 );
         } else {
-            $this->_registry->getResponse()->appendContent(
+            $response->appendContent(
                 'Creating an action named ' . $name .
                 ' inside controller at ' . $actionMethod->getParentResource()->getContext()->getPath()
                 );
@@ -163,11 +196,11 @@ class Zend_Tool_Project_Provider_Action
             $viewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $name, $controllerName, $module);
 
             if ($this->_registry->getRequest()->isPretend()) {
-                $this->_registry->getResponse()->appendContent(
+                $response->appendContent(
                     'Would create a view script for the ' . $name . ' action method at ' . $viewResource->getContext()->getPath()
                     );
             } else {
-                $this->_registry->getResponse()->appendContent(
+                $response->appendContent(
                     'Creating a view script for the ' . $name . ' action method at ' . $viewResource->getContext()->getPath()
                     );
                 $viewResource->create();

+ 24 - 3
library/Zend/Tool/Project/Provider/Application.php

@@ -33,10 +33,21 @@ class Zend_Tool_Project_Provider_Application
     
     protected $_specialties = array('ClassNamePrefix');
     
-    public function changeClassNamePrefix($classNamePrefix, $force = false)
+    /**
+     * 
+     * @param $classNamePrefix Prefix of classes
+     * @param $force
+     */
+    public function changeClassNamePrefix($classNamePrefix /* , $force = false */)
     {
         $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
         
+        $originalClassNamePrefix = $classNamePrefix;
+        
+        if (substr($classNamePrefix, -1) != '_') {
+            $classNamePrefix .= '_';
+        }
+        
         $configFileResource = $profile->search('ApplicationConfigFile');
         $zc = $configFileResource->getAsZendConfig('production');
         if ($zc->appnamespace == $classNamePrefix) {
@@ -55,9 +66,19 @@ class Zend_Tool_Project_Provider_Application
         $applicationDirectory = $profile->search('ApplicationDirectory');
         $applicationDirectory->setClassNamePrefix($classNamePrefix);
 
+        $response = $this->_registry->getResponse();
+        
+        if ($originalClassNamePrefix !== $classNamePrefix) {
+            $response->appendContent(
+                'Note: the name provided "' . $originalClassNamePrefix . '" was'
+                    . ' altered to "' . $classNamePrefix . '" for correctness.',
+                array('color' => 'yellow')
+                );
+        } 
+        
         // 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'));
+        $response->appendContent('Note: All existing models will need to be altered to this new namespace by hand', array('color' => 'yellow'));
+        $response->appendContent('application.ini updated with new appnamespace ' . $classNamePrefix);
         
         // store profile
         $this->_storeProfile();

+ 29 - 13
library/Zend/Tool/Project/Provider/Controller.php

@@ -125,7 +125,12 @@ class Zend_Tool_Project_Provider_Controller
             throw new Zend_Tool_Project_Provider_Exception('Controller names should be camel cased.');
         }
         
-        $name = ucwords($name);
+        $originalName = $name;
+        $name = ucfirst($name);
+        
+        // get request & response
+        $request = $this->_registry->getRequest();
+        $response = $this->_registry->getResponse();
         
         try {
             $controllerResource = self::createResource($this->_loadedProfile, $name, $module);
@@ -138,39 +143,50 @@ class Zend_Tool_Project_Provider_Controller
             }
 
         } catch (Exception $e) {
-            $response = $this->_registry->getResponse();
             $response->setException($e);
             return;
         }
 
+        // determime if we need to note to the user about the name
+        if (($name !== $originalName)) {
+            $tense = (($request->isPretend()) ? 'would be' : 'is');
+            $response->appendContent(
+                'Note: The canonical controller name that ' . $tense
+                    . ' used with other providers is "' . $name . '";'
+                    . ' not "' . $originalName . '" as supplied',
+                array('color' => array('yellow'))
+                );
+            unset($tense);
+        }
+        
         // do the creation
-        if ($this->_registry->getRequest()->isPretend()) {
-
-            $this->_registry->getResponse()->appendContent('Would create a controller at '  . $controllerResource->getContext()->getPath());
+        if ($request->isPretend()) {
+            
+            $response->appendContent('Would create a controller at '  . $controllerResource->getContext()->getPath());
 
             if (isset($indexActionResource)) {
-                $this->_registry->getResponse()->appendContent('Would create an index action method in controller ' . $name);
-                $this->_registry->getResponse()->appendContent('Would create a view script for the index action method at ' . $indexActionViewResource->getContext()->getPath());
+                $response->appendContent('Would create an index action method in controller ' . $name);
+                $response->appendContent('Would create a view script for the index action method at ' . $indexActionViewResource->getContext()->getPath());
             }
-
+            
             if ($testControllerResource) {
-                $this->_registry->getResponse()->appendContent('Would create a controller test file at ' . $testControllerResource->getContext()->getPath());
+                $response->appendContent('Would create a controller test file at ' . $testControllerResource->getContext()->getPath());
             }
 
         } else {
 
-            $this->_registry->getResponse()->appendContent('Creating a controller at ' . $controllerResource->getContext()->getPath());
+            $response->appendContent('Creating a controller at ' . $controllerResource->getContext()->getPath());
             $controllerResource->create();
 
             if (isset($indexActionResource)) {
-                $this->_registry->getResponse()->appendContent('Creating an index action method in controller ' . $name);
+                $response->appendContent('Creating an index action method in controller ' . $name);
                 $indexActionResource->create();
-                $this->_registry->getResponse()->appendContent('Creating a view script for the index action method at ' . $indexActionViewResource->getContext()->getPath());
+                $response->appendContent('Creating a view script for the index action method at ' . $indexActionViewResource->getContext()->getPath());
                 $indexActionViewResource->create();
             }
 
             if ($testControllerResource) {
-                $this->_registry->getResponse()->appendContent('Creating a controller test file at ' . $testControllerResource->getContext()->getPath());
+                $response->appendContent('Creating a controller test file at ' . $testControllerResource->getContext()->getPath());
                 $testControllerResource->create();
             }
 

+ 2 - 2
library/Zend/Tool/Project/Provider/DbAdapter.php

@@ -75,8 +75,8 @@ class Zend_Tool_Project_Provider_DbAdapter
         
         if ($dsn) {
             $this->_configureViaDSN($dsn);
-        } elseif ($interactivelyPrompt) {
-            $this->_promptForConfig();
+        //} elseif ($interactivelyPrompt) {
+        //    $this->_promptForConfig();
         } else {
             $this->_registry->getResponse()->appendContent('Nothing to do!');
         }

+ 25 - 12
library/Zend/Tool/Project/Provider/DbTable.php

@@ -93,6 +93,14 @@ class Zend_Tool_Project_Provider_DbTable
     {
         $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
 
+        // Check that there is not a dash or underscore, return if doesnt match regex
+        if (preg_match('#[_-]#', $name)) {
+            throw new Zend_Tool_Project_Provider_Exception('DbTable names should be camel cased.');
+        }
+        
+        $originalName = $name;
+        $name = ucfirst($name);
+        
         if ($actualTableName == '') {
             throw new Zend_Tool_Project_Provider_Exception('You must provide both the DbTable name as well as the actual db table\'s name.');
         }
@@ -101,12 +109,21 @@ class Zend_Tool_Project_Provider_DbTable
             throw new Zend_Tool_Project_Provider_Exception('This project already has a DbTable named ' . $name);
         }
 
-        // Check that there is not a dash or underscore, return if doesnt match regex
-        if (preg_match('#[_-]#', $name)) {
-            throw new Zend_Tool_Project_Provider_Exception('DbTable names should be camel cased.');
-        }
+        // get request/response object
+        $request = $this->_registry->getRequest();
+        $response = $this->_registry->getResponse();
         
-        $name = ucwords($name);
+        // alert the user about inline converted names
+        $tense = (($request->isPretend()) ? 'would be' : 'is');
+        
+        if ($name !== $originalName) {
+            $response->appendContent(
+                'Note: The canonical model name that ' . $tense
+                    . ' used with other providers is "' . $name . '";'
+                    . ' not "' . $originalName . '" as supplied',
+                array('color' => array('yellow'))
+                );
+        }
         
         try {
             $tableResource = self::createResource($this->_loadedProfile, $name, $actualTableName, $module);
@@ -117,15 +134,11 @@ class Zend_Tool_Project_Provider_DbTable
         }
 
         // do the creation
-        if ($this->_registry->getRequest()->isPretend()) {
-
-            $this->_registry->getResponse()->appendContent('Would create a DbTable at '  . $tableResource->getContext()->getPath());
-
+        if ($request->isPretend()) {
+            $response->appendContent('Would create a DbTable at '  . $tableResource->getContext()->getPath());
         } else {
-
-            $this->_registry->getResponse()->appendContent('Creating a DbTable at ' . $tableResource->getContext()->getPath());
+            $response->appendContent('Creating a DbTable at ' . $tableResource->getContext()->getPath());
             $tableResource->create();
-
             $this->_storeProfile();
         }
     }

+ 28 - 11
library/Zend/Tool/Project/Provider/Model.php

@@ -100,20 +100,38 @@ class Zend_Tool_Project_Provider_Model extends Zend_Tool_Project_Provider_Abstra
     {
         $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
 
+        $originalName = $name;
+        
+        $name = ucwords($name);
+        
         // determine if testing is enabled in the project
         $testingEnabled = false; //Zend_Tool_Project_Provider_Test::isTestingEnabled($this->_loadedProfile);
         $testModelResource = null;
-        
-        if (self::hasResource($this->_loadedProfile, $name, $module)) {
-            throw new Zend_Tool_Project_Provider_Exception('This project already has a model named ' . $name);
-        }
 
         // Check that there is not a dash or underscore, return if doesnt match regex
         if (preg_match('#[_-]#', $name)) {
             throw new Zend_Tool_Project_Provider_Exception('Model names should be camel cased.');
         }
         
-        $name = ucwords($name);
+        if (self::hasResource($this->_loadedProfile, $name, $module)) {
+            throw new Zend_Tool_Project_Provider_Exception('This project already has a model named ' . $name);
+        }
+        
+        // get request/response object
+        $request = $this->_registry->getRequest();
+        $response = $this->_registry->getResponse();
+        
+        // alert the user about inline converted names
+        $tense = (($request->isPretend()) ? 'would be' : 'is');
+        
+        if ($name !== $originalName) {
+            $response->appendContent(
+                'Note: The canonical model name that ' . $tense
+                    . ' used with other providers is "' . $name . '";'
+                    . ' not "' . $originalName . '" as supplied',
+                array('color' => array('yellow'))
+                );
+        }
         
         try {
             $modelResource = self::createResource($this->_loadedProfile, $name, $module);
@@ -123,27 +141,26 @@ class Zend_Tool_Project_Provider_Model extends Zend_Tool_Project_Provider_Abstra
             }
 
         } catch (Exception $e) {
-            $response = $this->_registry->getResponse();
             $response->setException($e);
             return;
         }
 
         // do the creation
-        if ($this->_registry->getRequest()->isPretend()) {
+        if ($request->isPretend()) {
 
-            $this->_registry->getResponse()->appendContent('Would create a model at '  . $modelResource->getContext()->getPath());
+            $response->appendContent('Would create a model at '  . $modelResource->getContext()->getPath());
 
             if ($testModelResource) {
-                $this->_registry->getResponse()->appendContent('Would create a model test file at ' . $testModelResource->getContext()->getPath());
+                $response->appendContent('Would create a model test file at ' . $testModelResource->getContext()->getPath());
             }
 
         } else {
 
-            $this->_registry->getResponse()->appendContent('Creating a model at ' . $modelResource->getContext()->getPath());
+            $response->appendContent('Creating a model at ' . $modelResource->getContext()->getPath());
             $modelResource->create();
 
             if ($testModelResource) {
-                $this->_registry->getResponse()->appendContent('Creating a model test file at ' . $testModelResource->getContext()->getPath());
+                $response->appendContent('Creating a model test file at ' . $testModelResource->getContext()->getPath());
                 $testModelResource->create();
             }