function _createAction($actionName)
 {
     $response = $this->_registry->getResponse();
     $indexActionResource = Zend_Tool_Project_Provider_Action::createResource($this->_loadedProfile, $actionName, $this->_resourceName . 's', $this->_moduleName);
     $response->appendContent("Creating an {$actionName} action method in controller " . $this->_resourceName);
     $indexActionResource->create();
     $indexActionViewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $actionName, $this->_resourceName . 's', $this->_moduleName);
     $response->appendContent("Creating a view script for the {$actionName} action method at " . $indexActionViewResource->getContext()->getPath());
     $indexActionViewResource->create();
 }
Example #2
0
 /**
  * Create a new controller
  *
  * @param string $name The name of the controller to create, in camelCase.
  * @param bool $indexActionIncluded Whether or not to create the index action.
  */
 public function create($name, $indexActionIncluded = true, $module = null)
 {
     $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
     // determine if testing is enabled in the project
     require_once 'Zend/Tool/Project/Provider/Test.php';
     $testingEnabled = Zend_Tool_Project_Provider_Test::isTestingEnabled($this->_loadedProfile);
     if (self::hasResource($this->_loadedProfile, $name, $module)) {
         throw new Zend_Tool_Project_Provider_Exception('This project already has a controller 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('Controller names should be camel cased.');
     }
     $originalName = $name;
     $name = ucfirst($name);
     // get request & response
     $request = $this->_registry->getRequest();
     $response = $this->_registry->getResponse();
     try {
         $controllerResource = self::createResource($this->_loadedProfile, $name, $module);
         if ($indexActionIncluded) {
             $indexActionResource = Zend_Tool_Project_Provider_Action::createResource($this->_loadedProfile, 'index', $name, $module);
             $indexActionViewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, 'index', $name, $module);
         }
         if ($testingEnabled) {
             $testControllerResource = Zend_Tool_Project_Provider_Test::createApplicationResource($this->_loadedProfile, $name, 'index', $module);
         }
     } catch (Exception $e) {
         $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 ($request->isPretend()) {
         $response->appendContent('Would create a controller at ' . $controllerResource->getContext()->getPath());
         if (isset($indexActionResource)) {
             $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) {
             $response->appendContent('Would create a controller test file at ' . $testControllerResource->getContext()->getPath());
         }
     } else {
         $response->appendContent('Creating a controller at ' . $controllerResource->getContext()->getPath());
         $controllerResource->create();
         if (isset($indexActionResource)) {
             $response->appendContent('Creating an index action method in controller ' . $name);
             $indexActionResource->create();
             $response->appendContent('Creating a view script for the index action method at ' . $indexActionViewResource->getContext()->getPath());
             $indexActionViewResource->create();
         }
         if ($testControllerResource) {
             $response->appendContent('Creating a controller test file at ' . $testControllerResource->getContext()->getPath());
             $testControllerResource->create();
         }
         $this->_storeProfile();
     }
 }
Example #3
0
 /**
  * Enter description here...
  *
  * @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, $module = null)
 {
     $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
     // determine if testing is enabled in the project
     require_once 'Zend/Tool/Project/Provider/Test.php';
     $testingEnabled = Zend_Tool_Project_Provider_Test::isTestingEnabled($this->_loadedProfile);
     if (self::hasResource($this->_loadedProfile, $name, $module)) {
         throw new Zend_Tool_Project_Provider_Exception('This project already has a controller named ' . $name);
     }
     try {
         $controllerResource = self::createResource($this->_loadedProfile, $name, $module);
         if ($indexActionIncluded) {
             $indexActionResource = Zend_Tool_Project_Provider_Action::createResource($this->_loadedProfile, 'index', $name, $module);
             $indexActionViewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, 'index', $name, $module);
         }
         if ($testingEnabled) {
             $testControllerResource = Zend_Tool_Project_Provider_Test::createApplicationResource($this->_loadedProfile, $name, 'index', $module);
         }
     } catch (Exception $e) {
         $response = $this->_registry->getResponse();
         $response->setException($e);
         return;
     }
     // do the creation
     if ($this->_registry->getRequest()->isPretend()) {
         $this->_registry->getResponse()->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());
         }
         if ($testControllerResource) {
             $this->_registry->getResponse()->appendContent('Would create a controller test file at ' . $testControllerResource->getContext()->getPath());
         }
     } else {
         $this->_registry->getResponse()->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);
             $indexActionResource->create();
             $this->_registry->getResponse()->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());
             $testControllerResource->create();
         }
         $this->_storeProfile();
     }
 }
Example #4
0
 /**
  * Implements the create action for the controller-spec provider
  *
  * @param string $name 
  * @param string $commaSeparatedActions 
  * @param string $module 
  * @return void
  */
 public function create($name, $commaSeparatedActions = '', $module = null)
 {
     $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
     if (!is_dir('spec')) {
         throw new ProviderException('Please run zf generate phpspec, to create the environment');
     }
     $response = $this->_registry->getResponse();
     $request = $this->_registry->getRequest();
     $originalName = $name;
     $name = UCFirst::apply($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('Controller names should be camel cased.');
     }
     // alert the user about inline converted names
     $tense = $request->isPretend() ? 'would be' : 'is';
     if ($name !== $originalName) {
         $response->appendContent('Note: The canonical controller name that ' . $tense . ' used with other providers is "' . $name . '";' . ' not "' . $originalName . '" as supplied', array('color' => array('yellow')));
     }
     $actions = array();
     if (strlen(trim($commaSeparatedActions)) > 0) {
         $actions = array_unique(explode(',', $commaSeparatedActions));
     }
     try {
         $controllerResource = self::createResource($this->_loadedProfile, $name, $module);
     } catch (Exception $e) {
         $response->setException($e);
         return;
     }
     //controller spec
     $controllerPath = str_replace(basename($controllerResource->getContext()->getPath()), '', $controllerResource->getContext()->getPath());
     $basePath = realpath($controllerPath . '/../..');
     $controllerSpecPath = realpath($basePath . '/spec/controllers') . '/' . $name . 'ControllerSpec.php';
     $specContent = $this->_getSpecContent($name, $actions);
     if ($request->isPretend()) {
         $response->appendContent('Would create a controller at ' . $controllerResource->getContext()->getPath());
         foreach ($actions as $action) {
             $vowel = in_array($action[0], array('a', 'e', 'i', 'o', 'u'));
             $response->appendContent('Would create a' . ($vowel ? 'n' : '') . ' ' . $action . ' action method in controller ' . $name);
         }
         $response->appendContent('Would create a spec at ' . $controllerSpecPath);
     } else {
         $response->appendContent('Creating a controller at ' . $controllerResource->getContext()->getPath());
         $controllerResource->create();
         foreach ($actions as $action) {
             $vowel = in_array($action[0], array('a', 'e', 'i', 'o', 'u'));
             $actionResource = ActionProvider::createResource($this->_loadedProfile, $action, $name, $module);
             $response->appendContent('Creating a' . ($vowel ? 'n' : '') . ' ' . $action . ' action method in controller ' . $name);
             $actionResource->create();
         }
         $response->appendContent('Creating a spec at ' . $controllerSpecPath);
         file_put_contents($controllerSpecPath, $specContent);
     }
 }