Browse Source

ZF-6571
- Merging Zend_Tool incubator development from 15327:15529 to trunk

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

ralph 16 years ago
parent
commit
a4fa92e36e

+ 1 - 1
library/Zend/Tool/Framework/Client/Abstract.php

@@ -242,7 +242,7 @@ abstract class Zend_Tool_Framework_Client_Abstract implements Zend_Tool_Framewor
         $provider = $providerSignature->getProvider();
 
         // ensure that we can pretend if this is a pretend request
-        if ($request->isPretend() && (!$provider instanceof Zend_Tool_Project_Provider_Pretendable)) {
+        if ($request->isPretend() && (!$provider instanceof Zend_Tool_Framework_Provider_Pretendable)) {
             require_once 'Zend/Tool/Framework/Client/Exception.php';
             throw new Zend_Tool_Framework_Client_Exception('Dispatcher error - provider does not support pretend');  
         }

+ 1 - 1
library/Zend/Tool/Framework/Client/Console.php

@@ -152,7 +152,7 @@ class Zend_Tool_Framework_Client_Console
             require_once 'Zend/Tool/Framework/Client/Console/HelpSystem.php';
             $helpSystem = new Zend_Tool_Framework_Client_Console_HelpSystem();
             $helpSystem->setRegistry($this->_registry)
-                ->respondWithErrorMessage($response->getException()->getMessage())
+                ->respondWithErrorMessage($response->getException()->getMessage(), $response->getException())
                 ->respondWithSpecialtyAndParamHelp(
                     $request->getProviderName(),
                     $request->getActionName()

+ 9 - 2
library/Zend/Tool/Framework/Client/Console/ArgumentParser.php

@@ -389,6 +389,7 @@ class Zend_Tool_Framework_Client_Console_ArgumentParser implements Zend_Tool_Fra
 
         $getoptOptions = array();
         $wordArguments = array();
+        $longParamCanonicalNames = array();
 
         $actionableMethodLongParamsMetadataReference = $actionableMethodLongParamsMetadata->getReference();
         foreach ($actionableMethodLongParamsMetadata->getValue() as $parameterNameLong => $consoleParameterNameLong) {
@@ -415,6 +416,8 @@ class Zend_Tool_Framework_Client_Console_ArgumentParser implements Zend_Tool_Fra
             $wordArguments[$parameterInfo['position']]['optional']      = $parameterInfo['optional'];
             $wordArguments[$parameterInfo['position']]['type']          = $parameterInfo['type'];
 
+            // keep a translation of console to canonical names
+            $longParamCanonicalNames[$consoleParameterNameLong] = $parameterNameLong;
         }
 
 
@@ -456,12 +459,16 @@ class Zend_Tool_Framework_Client_Console_ArgumentParser implements Zend_Tool_Fra
         $getoptParser->parse();
         foreach ($getoptParser->getOptions() as $option) {
             $value = $getoptParser->getOption($option);
-            $this->_providerOptions[$option] = $value;
-            $this->_request->setProviderParameter($option, $value);
+            $providerParamOption = $longParamCanonicalNames[$option];
+            $this->_request->setProviderParameter($providerParamOption, $value);
         }
 
+        /*
         $this->_metadataProviderOptionsLong = $actionableMethodLongParamsMetadata;
         $this->_metadataProviderOptionsShort = $actionableMethodShortParamsMetadata;
+        */
+        
+        $this->_argumentsWorking = $getoptParser->getRemainingArgs();
 
         return;
     }

+ 6 - 1
library/Zend/Tool/Framework/Client/Console/HelpSystem.php

@@ -56,8 +56,9 @@ class Zend_Tool_Framework_Client_Console_HelpSystem
      * respondWithErrorMessage()
      *
      * @param string $errorMessage
+     * @param Exception $exception
      */
-    public function respondWithErrorMessage($errorMessage)
+    public function respondWithErrorMessage($errorMessage, Exception $exception = null)
     {
         // break apart the message into wrapped chunks
         $errorMessages = explode(PHP_EOL, wordwrap($errorMessage, 70, PHP_EOL, false));
@@ -70,6 +71,10 @@ class Zend_Tool_Framework_Client_Console_HelpSystem
             $this->_response->appendContent(' ' . $errorMessage . ' ', array('color' => array('white', 'bgRed')));
         }
         
+        if ($exception && $this->_registry->getRequest()->isDebug()) {
+            $this->_response->appendContent($exception->getTraceAsString());
+        }
+        
         $this->_response->appendContent(null, array('separator' => true));
         return $this;
     }

+ 1 - 1
library/Zend/Tool/Framework/Metadata/Dynamic.php

@@ -31,7 +31,7 @@ require_once 'Zend/Tool/Framework/Manifest/Metadata.php';
  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Tool_Framework_Metadata_Dynamic extends Zend_Tool_Framework_Metadata_Interface
+class Zend_Tool_Framework_Metadata_Dynamic implements Zend_Tool_Framework_Metadata_Interface
 {
     
     /**

+ 97 - 0
library/Zend/Tool/Project/Context/Zf/ModuleDirectory.php

@@ -0,0 +1,97 @@
+<?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
+ * @subpackage Framework
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Tool_Project_Context_Filesystem_Directory
+ */
+require_once 'Zend/Tool/Project/Context/Filesystem/Directory.php';
+
+/**
+ * This class is the front most class for utilizing Zend_Tool_Project
+ *
+ * A profile is a hierarchical set of resources that keep track of
+ * items within a specific project.
+ * 
+ * @category   Zend
+ * @package    Zend_Tool
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Tool_Project_Context_Zf_ModuleDirectory extends Zend_Tool_Project_Context_Filesystem_Directory 
+{
+    
+    /**
+     * @var string
+     */
+    protected $_moduleName = null;
+    
+    /**
+     * @var string
+     */
+    protected $_filesystemName = 'moduleDirectory';
+    
+    /**
+     * init()
+     *
+     * @return Zend_Tool_Project_Context_Zf_ControllerFile
+     */
+    public function init()
+    {
+        $this->_filesystemName = $this->_moduleName = $this->_resource->getAttribute('moduleName');
+        parent::init();
+        return $this;
+    }
+    
+    /**
+     * getName()
+     *
+     * @return string
+     */
+    public function getName()
+    {
+        return 'ModuleDirectory';
+    }
+    
+    /**
+     * getPersistentAttributes
+     *
+     * @return array
+     */
+    public function getPersistentAttributes()
+    {
+        return array(
+            'moduleName' => $this->getModuleName()
+            );
+    }
+    
+    /**
+     * getModuleName()
+     *
+     * @return string
+     */
+    public function getModuleName()
+    {
+        return $this->_moduleName;
+    }
+      
+    
+}

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

@@ -54,4 +54,4 @@ class Zend_Tool_Project_Context_Zf_ModulesDirectory extends Zend_Tool_Project_Co
         return 'ModulesDirectory';
     }
     
-}
+}

+ 2 - 2
library/Zend/Tool/Project/Profile.php

@@ -87,10 +87,10 @@ class Zend_Tool_Project_Profile extends Zend_Tool_Project_Profile_Resource_Conta
      */
     public function getIterator()
     {
-        require_once 'Zend/Tool/Project/Profile/Iterator/EnabledResource.php';
+        require_once 'Zend/Tool/Project/Profile/Iterator/EnabledResourceFilter.php';
 
         return new RecursiveIteratorIterator(
-            new Zend_Tool_Project_Profile_Iterator_EnabledResource($this),
+            new Zend_Tool_Project_Profile_Iterator_EnabledResourceFilter($this),
             RecursiveIteratorIterator::SELF_FIRST
             );
     }

+ 203 - 0
library/Zend/Tool/Project/Profile/Iterator/ContextFilter.php

@@ -0,0 +1,203 @@
+<?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
+ * @subpackage Framework
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * This class is an iterator that will iterate only over enabled resources
+ * 
+ * @category   Zend
+ * @package    Zend_Tool
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Tool_Project_Profile_Iterator_ContextFilter extends RecursiveFilterIterator
+{
+    
+    /**
+     * @var array 
+     */
+    protected $_acceptTypes = array();
+    
+    /**
+     * @var array 
+     */
+    protected $_denyTypes   = array();
+    
+    /**
+     * @var array 
+     */
+    protected $_acceptNames = array();
+    
+    /**
+     * @var array 
+     */
+    protected $_denyNames   = array();
+    
+    /**
+     * @var array 
+     */
+    protected $_rawOptions = array();
+    
+    /**
+     * __construct()
+     *
+     * @param RecursiveIterator $iterator
+     * @param array $options
+     */
+    public function __construct(RecursiveIterator $iterator, $options = array())
+    {
+        parent::__construct($iterator);
+        $this->_rawOptions = $options;
+        if ($options) {
+            $this->setOptions($options);
+        }
+    }
+    
+    /**
+     * setOptions()
+     *
+     * @param array $options
+     */
+    public function setOptions(Array $options)
+    {
+        foreach ($options as $optionName => $optionValue) {
+            if (substr($optionName, -1, 1) != 's') {
+                $optionName .= 's';
+            }
+            if (method_exists($this, 'set' . $optionName)) {
+                $this->{'set' . $optionName}($optionValue);
+            }
+        }
+    }
+    
+    /**
+     * setAcceptTypes()
+     *
+     * @param array|string $acceptTypes
+     * @return Zend_Tool_Project_Profile_Iterator_ContextFilter
+     */
+    public function setAcceptTypes($acceptTypes)
+    {
+        if (!is_array($acceptTypes)) {
+            $acceptTypes = array($acceptTypes);
+        }
+        
+        $this->_acceptTypes = $acceptTypes;
+        return $this;
+    }
+    
+    /**
+     * setDenyTypes()
+     *
+     * @param array|string $denyTypes
+     * @return Zend_Tool_Project_Profile_Iterator_ContextFilter
+     */
+    public function setDenyTypes($denyTypes)
+    {
+        if (!is_array($denyTypes)) {
+            $denyTypes = array($denyTypes);
+        }
+        
+        $this->_denyTypes = $denyTypes;
+        return $this;
+    }
+    
+    /**
+     * setAcceptNames()
+     *
+     * @param array|string $acceptNames
+     * @return Zend_Tool_Project_Profile_Iterator_ContextFilter
+     */
+    public function setAcceptNames($acceptNames)
+    {
+        if (!is_array($acceptNames)) {
+            $acceptNames = array($acceptNames);
+        }
+        
+        $this->_acceptNames = $acceptNames;
+        return $this;
+    }
+    
+    /**
+     * setDenyNames()
+     *
+     * @param array|string $denyNames
+     * @return Zend_Tool_Project_Profile_Iterator_ContextFilter
+     */
+    public function setDenyNames($denyNames)
+    {
+        if (!is_array($denyNames)) {
+            $denyNames = array($denyNames);
+        }
+        
+        $this->_denyNames = $denyNames;
+        return $this;
+    }
+    
+    /**
+     * accept() is required by teh RecursiveFilterIterator
+     *
+     * @return bool
+     */
+    public function accept()
+    {
+        $currentItem = $this->current();
+        
+        if (in_array($currentItem->getName(), $this->_acceptNames)) {
+            return true;
+        } elseif (in_array($currentItem->getName(), $this->_denyNames)) {
+            return false;
+        }
+        
+        foreach ($this->_acceptTypes as $acceptType) {
+            if ($currentItem->getContent() instanceof $acceptType) {
+                return true;
+            }
+        }
+        
+        foreach ($this->_denyTypes as $denyType) {
+            if ($currentItem->getContext() instanceof $denyType) {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+    
+    /**
+     * getChildren()
+     * 
+     * This is here due to a bug/design issue in PHP
+     * @link 
+     *
+     * @return unknown
+     */
+    function getChildren()
+    {
+
+        if (empty($this->ref)) {
+            $this->ref = new ReflectionClass($this);
+        }
+
+        return $this->ref->newInstance($this->getInnerIterator()->getChildren(), $this->_rawOptions);
+    }
+    
+}

+ 1 - 1
library/Zend/Tool/Project/Profile/Iterator/EnabledResource.php → library/Zend/Tool/Project/Profile/Iterator/EnabledResourceFilter.php

@@ -28,7 +28,7 @@
  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Tool_Project_Profile_Iterator_EnabledResource extends RecursiveFilterIterator
+class Zend_Tool_Project_Profile_Iterator_EnabledResourceFilter extends RecursiveFilterIterator
 {
     
     /**

+ 25 - 11
library/Zend/Tool/Project/Profile/Resource/Container.php

@@ -62,21 +62,31 @@ class Zend_Tool_Project_Profile_Resource_Container implements RecursiveIterator,
      * @param Zend_Tool_Project_Profile_Resource_SearchConstraints|string|array $searchParameters
      * @return Zend_Tool_Project_Profile_Resource
      */
-    public function search($searchConstraints)
+    public function search($matchSearchConstraints, $nonMatchSearchConstraints = null)
     {
-        if (!$searchConstraints instanceof Zend_Tool_Project_Profile_Resource_SearchConstraints) {
-            $searchConstraints = new Zend_Tool_Project_Profile_Resource_SearchConstraints($searchConstraints);
+        if (!$matchSearchConstraints instanceof Zend_Tool_Project_Profile_Resource_SearchConstraints) {
+            $matchSearchConstraints = new Zend_Tool_Project_Profile_Resource_SearchConstraints($matchSearchConstraints);
         }
-        
+                
         $this->rewind();
-        $riIterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
+        
+        /**
+         * @todo This should be re-written with better support for a filter iterator, its the way to go
+         */
+        
+        if ($nonMatchSearchConstraints) {
+            $filterIterator = new Zend_Tool_Project_Profile_Iterator_ContextFilter($this, array('denyNames' => $nonMatchSearchConstraints));
+            $riIterator = new RecursiveIteratorIterator($filterIterator, RecursiveIteratorIterator::SELF_FIRST);
+        } else {
+            $riIterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
+        }
         
         $foundResource     = false;
-        $currentConstraint = $searchConstraints->getConstraint();
+        $currentConstraint = $matchSearchConstraints->getConstraint();
         $foundDepth        = 0;
         
-        while ($currentResource = $riIterator->current()) {
-            
+        foreach ($riIterator as $currentResource) {
+        
             // if current depth is less than found depth, end
             if ($riIterator->getDepth() < $foundDepth) {
                 break;
@@ -89,6 +99,11 @@ class Zend_Tool_Project_Profile_Resource_Container implements RecursiveIterator,
                 // @todo check to ensure params match (perhaps)
                 if (count($currentConstraint->params) > 0) {
                     $currentResourceAttributes = $currentResource->getAttributes();
+                    if (!is_array($currentConstraint->params)) {
+                        require_once 'Zend/Tool/Project/Profile/Exception.php';
+                        throw new Zend_Tool_Project_Profile_Exception('Search parameter specifics must be in the form of an array for key "' 
+                            . $currentConstraint->name .'"');      
+                    }
                     foreach ($currentConstraint->params as $paramName => $paramValue) {
                         if (!isset($currentResourceAttributes[$paramName]) || $currentResourceAttributes[$paramName] != $paramValue) {
                             $paramsMatch = false;
@@ -100,7 +115,7 @@ class Zend_Tool_Project_Profile_Resource_Container implements RecursiveIterator,
                 if ($paramsMatch) {
                     $foundDepth = $riIterator->getDepth();
                     
-                    if (($currentConstraint = $searchConstraints->getConstraint()) == null) {
+                    if (($currentConstraint = $matchSearchConstraints->getConstraint()) == null) {
                         $foundResource = $currentResource;
                         break;
                     }
@@ -108,7 +123,6 @@ class Zend_Tool_Project_Profile_Resource_Container implements RecursiveIterator,
 
             }
             
-            $riIterator->next();
         }
         
         return $foundResource;
@@ -127,7 +141,7 @@ class Zend_Tool_Project_Profile_Resource_Container implements RecursiveIterator,
         if (!$appendResourceOrSearchConstraints instanceof Zend_Tool_Project_Profile_Resource_Container) {
             if (($parentResource = $this->search($appendResourceOrSearchConstraints)) == false) {
                 require_once 'Zend/Tool/Project/Profile/Exception.php';
-                throw new Zend_Tool_Project_Profile_Exception('No node was found to append to.');                
+                throw new Zend_Tool_Project_Profile_Exception('No node was found to append to.');
             }
         } else {
             $parentResource = $appendResourceOrSearchConstraints;

+ 13 - 5
library/Zend/Tool/Project/Provider/Action.php

@@ -26,12 +26,19 @@
 require_once 'Zend/Tool/Project/Provider/Abstract.php';
 
 /**
+ * @see Zend_Tool_Framework_Provider_Pretendable
+ */
+require_once 'Zend/Tool/Framework/Provider/Pretendable.php';
+
+/**
  * @category   Zend
  * @package    Zend_Tool
  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Tool_Project_Provider_Action extends Zend_Tool_Project_Provider_Abstract
+class Zend_Tool_Project_Provider_Action 
+    extends Zend_Tool_Project_Provider_Abstract
+    implements Zend_Tool_Framework_Provider_Pretendable
 {
 
     /**
@@ -98,7 +105,7 @@ class Zend_Tool_Project_Provider_Action extends Zend_Tool_Project_Provider_Abstr
         $profileSearchParams = array();
         
         if ($moduleName != null && is_string($moduleName)) {
-            $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => $moduleName);
+            $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
         }
         
         $profileSearchParams[] = 'controllersDirectory';
@@ -114,7 +121,7 @@ class Zend_Tool_Project_Provider_Action extends Zend_Tool_Project_Provider_Abstr
      * @param string $controllerName
      * @param bool $viewIncluded
      */
-    public function create($name, $controllerName = 'index', $viewIncluded = true)
+    public function create($name, $controllerName = 'index', $viewIncluded = true, $module = null)
     {
 
         $this->_loadProfile();
@@ -123,7 +130,7 @@ class Zend_Tool_Project_Provider_Action extends Zend_Tool_Project_Provider_Abstr
             throw new Zend_Tool_Project_Provider_Exception('This controller (' . $controllerName . ') already has an action named (' . $name . ')');
         }
         
-        $actionMethod = self::createResource($this->_loadedProfile, $name, $controllerName);
+        $actionMethod = self::createResource($this->_loadedProfile, $name, $controllerName, $module);
         
         if ($this->_registry->getRequest()->isPretend()) {
             $this->_registry->getResponse()->appendContent(
@@ -140,7 +147,7 @@ class Zend_Tool_Project_Provider_Action extends Zend_Tool_Project_Provider_Abstr
         }
         
         if ($viewIncluded) {
-            $viewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $controllerName, $name);
+            $viewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $name, $controllerName, $module);
             
             if ($this->_registry->getRequest()->isPretend()) {
                 $this->_registry->getResponse()->appendContent(
@@ -151,6 +158,7 @@ class Zend_Tool_Project_Provider_Action extends Zend_Tool_Project_Provider_Abstr
                     'Creating a view script for the ' . $name . ' action method at ' . $viewResource->getContext()->getPath()
                     );
                 $viewResource->create();
+                $this->_storeProfile();
             }
             
         }

+ 21 - 6
library/Zend/Tool/Project/Provider/Controller.php

@@ -41,12 +41,19 @@ require_once 'Zend/Tool/Project/Provider/View.php';
 require_once 'Zend/Tool/Project/Provider/Exception.php';
 
 /**
+ * @see Zend_Tool_Framework_Provider_Pretendable
+ */
+require_once 'Zend/Tool/Framework/Provider/Pretendable.php';
+
+/**
  * @category   Zend
  * @package    Zend_Tool
  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Tool_Project_Provider_Controller extends Zend_Tool_Project_Provider_Abstract
+class Zend_Tool_Project_Provider_Controller 
+    extends Zend_Tool_Project_Provider_Abstract
+    implements Zend_Tool_Framework_Provider_Pretendable
 {
 
     /**
@@ -65,7 +72,15 @@ class Zend_Tool_Project_Provider_Controller extends Zend_Tool_Project_Provider_A
             throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_Controller::createResource() expects \"controllerName\" is the name of a controller resource to create.');
         }
         
-        $controllersDirectory = self::_getControllersDirectoryResource($profile, $moduleName);
+        if (!($controllersDirectory = self::_getControllersDirectoryResource($profile, $moduleName))) {
+            if ($moduleName) {
+                $exceptionMessage = 'A controller directory for module "' . $moduleName . '" was not found.';
+            } else {
+                $exceptionMessage = 'A controller directory was not found.';
+            }
+            throw new Zend_Tool_Project_Provider_Exception($exceptionMessage);
+        }
+        
         $newController = $controllersDirectory->createResource('controllerFile', array('controllerName' => $controllerName));
 
         return $newController;
@@ -101,7 +116,7 @@ class Zend_Tool_Project_Provider_Controller extends Zend_Tool_Project_Provider_A
         $profileSearchParams = array();
 
         if ($moduleName != null && is_string($moduleName)) {
-            $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => $moduleName);
+            $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
         }
 
         $profileSearchParams[] = 'controllersDirectory';
@@ -115,7 +130,7 @@ class Zend_Tool_Project_Provider_Controller extends Zend_Tool_Project_Provider_A
      * @param string $name The name of the controller to create.
      * @param bool $indexActionIncluded Whether or not to create the index action.
      */
-    public function create($name, $indexActionIncluded = true)
+    public function create($name, $indexActionIncluded = true, $module = null)
     {
         $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
         
@@ -128,10 +143,10 @@ class Zend_Tool_Project_Provider_Controller extends Zend_Tool_Project_Provider_A
         }
         
         try {
-            $controllerResource = self::createResource($this->_loadedProfile, $name);
+            $controllerResource = self::createResource($this->_loadedProfile, $name, $module);
             if ($indexActionIncluded) {
                 $indexActionResource = Zend_Tool_Project_Provider_Action::createResource($this->_loadedProfile, 'index', $name);
-                $indexActionViewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $name, 'index');
+                $indexActionViewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, 'index', $name);
             }
             if ($testingEnabled) {
                 $testControllerResource = Zend_Tool_Project_Provider_Test::createApplicationResource($this->_loadedProfile, $name, 'index');

+ 6 - 0
library/Zend/Tool/Project/Provider/Manifest.php

@@ -51,6 +51,11 @@ require_once 'Zend/Tool/Project/Provider/Action.php';
 require_once 'Zend/Tool/Project/Provider/View.php';
 
 /**
+ * @see Zend_Tool_Project_Provider_Module
+ */
+require_once 'Zend/Tool/Project/Provider/Module.php';
+
+/**
  * @see Zend_Tool_Project_Provider_ProjectProvider
  */
 require_once 'Zend/Tool/Project/Provider/ProjectProvider.php';
@@ -78,6 +83,7 @@ class Zend_Tool_Project_Provider_Manifest implements
             new Zend_Tool_Project_Provider_Controller(),
             new Zend_Tool_Project_Provider_Action(),
             new Zend_Tool_Project_Provider_View(),
+            new Zend_Tool_Project_Provider_Module(),
             new Zend_Tool_Project_Provider_ProjectProvider()
         );
     }

+ 160 - 0
library/Zend/Tool/Project/Provider/Module.php

@@ -0,0 +1,160 @@
+<?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
+ * @subpackage Framework
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Tool_Project_Provider_Abstract
+ */
+require_once 'Zend/Tool/Project/Provider/Abstract.php';
+
+/**
+ * @see Zend_Tool_Framework_Provider_Pretendable
+ */
+require_once 'Zend/Tool/Framework/Provider/Pretendable.php';
+
+/**
+ * @see Zend_Tool_Project_Profile_Iterator_ContextFilter
+ */
+require_once 'Zend/Tool/Project/Profile/Iterator/ContextFilter.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Tool
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Tool_Project_Provider_Module 
+    extends Zend_Tool_Project_Provider_Abstract
+    implements Zend_Tool_Framework_Provider_Pretendable
+{
+
+    public static function createResources(Zend_Tool_Project_Profile $profile, $moduleName, Zend_Tool_Project_Profile_Resource $targetModuleResource = null)
+    {
+
+        // find the appliction directory, it will serve as our module skeleton
+        if ($targetModuleResource == null) {
+            $targetModuleResource = $profile->search('applicationDirectory');
+            $targetModuleEnabledResources = array(
+                'ControllersDirectory', 'ModelsDirectory', 'ViewsDirectory', 
+                'ViewScriptsDirectory', 'ViewHelpersDirectory', 'ViewFiltersDirectory'
+                );
+        }
+        
+        // find the actual modules directory we will use to house our module
+        $modulesDirectory = $profile->search('modulesDirectory');
+        
+        // if there is a module directory already, except
+        if ($modulesDirectory->search(array('moduleDirectory' => array('moduleName' => $moduleName)))) {
+            throw new Zend_Tool_Project_Provider_Exception('A module named "' . $moduleName . '" already exists.');
+        }
+        
+        // create the module directory
+        $moduleDirectory = $modulesDirectory->createResource('moduleDirectory', array('moduleName' => $moduleName));
+        
+        // create a context filter so that we can pull out only what we need from the module skeleton
+        $moduleContextFilterIterator = new Zend_Tool_Project_Profile_Iterator_ContextFilter(
+            $targetModuleResource, 
+            array(
+                'denyNames' => array('ModulesDirectory', 'ViewControllerScriptsDirectory'),
+                'denyType'  => 'Zend_Tool_Project_Context_Filesystem_File'
+                )
+            );
+        
+        // the iterator for the module skeleton
+        $targetIterator = new RecursiveIteratorIterator($moduleContextFilterIterator, RecursiveIteratorIterator::SELF_FIRST);
+        
+        // initialize some loop state information
+        $currentDepth = 0;
+        $parentResources = array();
+        $currentResource = $moduleDirectory;
+        
+        // loop through the target module skeleton
+        foreach ($targetIterator as $targetSubResource) {
+            
+            $depthDifference = $targetIterator->getDepth() - $currentDepth;
+            $currentDepth = $targetIterator->getDepth();
+            
+            if ($depthDifference === 1) {
+                // if we went down into a child, make note
+                array_push($parentResources, $currentResource);
+                // this will have always been set previously by another loop
+                $currentResource = $currentChildResource;
+            } elseif ($depthDifference < 0) {
+                // if we went up to a parent, make note
+                $i = $depthDifference;
+                do {
+                    // if we went out more than 1 parent, get to the correct parent
+                    $currentResource = array_pop($parentResources);
+                } while ($i-- > 0);
+            }
+
+            // get parameters for the newly created module resource
+            $params = $targetSubResource->getAttributes();
+            $currentChildResource = $currentResource->createResource($targetSubResource->getName(), $params);
+            
+            // based of the provided list (Currently up top), enable specific resources
+            if (isset($targetModuleEnabledResources)) {
+                $currentChildResource->setEnabled(in_array($targetSubResource->getName(), $targetModuleEnabledResources));
+            } else {
+                $currentChildResource->setEnabled($targetSubResource->isEnabled());
+            }
+
+        }
+        
+        return $moduleDirectory;
+    }
+    
+    /**
+     * create()
+     *
+     * @param string $name
+     */
+    public function create($name) //, $moduleProfile = null)
+    {
+        $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
+        
+        $resources = self::createResources($this->_loadedProfile, $name);
+        
+        $response = $this->_registry->getResponse();
+        
+        if ($this->_registry->getRequest()->isPretend()) {
+            $response->appendContent('I would create the following module and artifacts:');
+            foreach (new RecursiveIteratorIterator($resources, RecursiveIteratorIterator::SELF_FIRST) as $resource) {
+                if (is_callable(array($resource->getContext(), 'getPath'))) {
+                    $response->appendContent($resource->getContext()->getPath());
+                }
+            }
+        } else {
+            $response->appendContent('Creating the following module and artifacts:');
+            $enabledFilter = new Zend_Tool_Project_Profile_Iterator_EnabledResource($resources);
+            foreach (new RecursiveIteratorIterator($enabledFilter, RecursiveIteratorIterator::SELF_FIRST) as $resource) {
+                $response->appendContent($resource->getContext()->getPath());
+                $resource->create();
+            }
+            
+            // store changes to the profile
+            $this->_storeProfile();
+        }
+        
+    }
+    
+}
+

+ 12 - 9
library/Zend/Tool/Project/Provider/View.php

@@ -43,28 +43,31 @@ class Zend_Tool_Project_Provider_View extends Zend_Tool_Project_Provider_Abstrac
      * @param string $moduleName
      * @return Zend_Tool_Project_Profile_Resource
      */
-    public static function createResource(Zend_Tool_Project_Profile $profile, $controllerName, $actionName, $moduleName = null)
+    public static function createResource(Zend_Tool_Project_Profile $profile, $actionName, $controllerName, $moduleName = null)
     {
-        if (!is_string($controllerName)) {
+        if (!is_string($actionName)) {
             require_once 'Zend/Tool/Project/Provider/Exception.php';
-            throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"controllerName\" is the name of a controller resource to create.');
+            throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"actionName\" is the name of a controller resource to create.');
         }
         
-        if (!is_string($actionName)) {
+        if (!is_string($controllerName)) {
             require_once 'Zend/Tool/Project/Provider/Exception.php';
-            throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"actionName\" is the name of a controller resource to create.');
+            throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"controllerName\" is the name of a controller resource to create.');
         }
         
         $profileSearchParams = array();
         
         if ($moduleName) {
-            $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => $moduleName);
+            $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
+            $noModuleSearch = null;
+        } else {
+            $noModuleSearch = array('ModulesDirectory');
         }
         
         $profileSearchParams[] = 'viewsDirectory';
         $profileSearchParams[] = 'viewScriptsDirectory';
 
-        if (($viewScriptsDirectory = $profile->search($profileSearchParams)) === false) {
+        if (($viewScriptsDirectory = $profile->search($profileSearchParams, $noModuleSearch)) === false) {
             require_once 'Zend/Tool/Project/Provider/Exception.php';
             throw new Zend_Tool_Project_Provider_Exception('This project does not have a viewScriptsDirectory resource.');
         }
@@ -90,14 +93,14 @@ class Zend_Tool_Project_Provider_View extends Zend_Tool_Project_Provider_Abstrac
     public function create($controllerName, $actionNameOrSimpleName)
     {
         
-        if ($controllerName == '' || $actionName == '') {
+        if ($controllerName == '' || $actionNameOrSimpleName == '') {
             require_once 'Zend/Tool/Project/Provider/Exception.php';
             throw new Zend_Tool_Project_Provider_Exception('ControllerName and/or ActionName are empty.');
         }
         
         $profile = $this->_loadProfile();
         
-        $view = self::createResource($profile, $controllerName, $actionName);
+        $view = self::createResource($profile, $controllerName, $actionNameOrSimpleName);
         
         if ($this->_registry->getRequest()->isPretend()) {
             $this->_registry->getResponse(