/** * 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 $testingEnabled = Test::isTestingEnabled($this->_loadedProfile); if (self::hasResource($this->_loadedProfile, $name, $module)) { throw new Exception\RuntimeException('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 Exception\RuntimeException('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 = Action::createResource($this->_loadedProfile, 'index', $name, $module); $indexActionViewResource = View::createResource($this->_loadedProfile, 'index', $name, $module); } if ($testingEnabled) { $testControllerResource = 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(); } }
/** * Create a new form * * @param string $name * @param string $module */ public function create($name, $module = null) { $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); // determine if testing is enabled in the project $testingEnabled = Test::isTestingEnabled($this->_loadedProfile); if (self::hasResource($this->_loadedProfile, $name, $module)) { throw new Exception\RuntimeException('This project already has a form named ' . $name); } // Check that there is not a dash or underscore, return if doesnt match regex if (preg_match('#[_-]#', $name)) { throw new Exception\RuntimeException('Form names should be camel cased.'); } $name = ucwords($name); try { $formResource = self::createResource($this->_loadedProfile, $name, $module); if ($testingEnabled) { $testFormResource = null; // $testFormResource = 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 form at ' . $formResource->getContext()->getPath()); if ($testFormResource) { $this->_registry->getResponse()->appendContent('Would create a form test file at ' . $testFormResource->getContext()->getPath()); } } else { $this->_registry->getResponse()->appendContent('Creating a form at ' . $formResource->getContext()->getPath()); $formResource->create(); if ($testFormResource) { $this->_registry->getResponse()->appendContent('Creating a form test file at ' . $testFormResource->getContext()->getPath()); $testFormResource->create(); } $this->_storeProfile(); } }