예제 #1
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();
     }
 }
예제 #2
0
 /**
  * create()
  *
  * @param string $name           Action name for controller, in camelCase format.
  * @param string $controllerName Controller name action should be applied to.
  * @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)
 {
     $this->_loadProfile();
     // get request/response object
     $request = $this->_registry->getRequest();
     $response = $this->_registry->getResponse();
     // 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 ($testingEnabled && !Zend_Tool_Project_Provider_Test::isPHPUnitAvailable()) {
         $testingEnabled = false;
         $response->appendContent('Note: PHPUnit is required in order to generate controller test stubs.', array('color' => array('yellow')));
     }
     // 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 . ')');
     }
     $actionMethodResource = self::createResource($this->_loadedProfile, $name, $controllerName, $module);
     if ($testingEnabled) {
         $testActionMethodResource = Zend_Tool_Project_Provider_Test::createApplicationResource($this->_loadedProfile, $controllerName, $name, $module);
     }
     // 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 ' . $actionMethodResource->getParentResource()->getContext()->getPath());
         if ($testActionMethodResource) {
             $response->appendContent('Would create an action test in ' . $testActionMethodResource->getParentResource()->getContext()->getPath());
         }
     } else {
         $response->appendContent('Creating an action named ' . $name . ' inside controller at ' . $actionMethodResource->getParentResource()->getContext()->getPath());
         $actionMethodResource->create();
         if ($testActionMethodResource) {
             $response->appendContent('Creating an action test in ' . $testActionMethodResource->getParentResource()->getContext()->getPath());
             $testActionMethodResource->create();
         }
         $this->_storeProfile();
     }
     if ($viewIncluded) {
         $viewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $name, $controllerName, $module);
         if ($this->_registry->getRequest()->isPretend()) {
             $response->appendContent('Would create a view script for the ' . $name . ' action method at ' . $viewResource->getContext()->getPath());
         } else {
             $response->appendContent('Creating a view script for the ' . $name . ' action method at ' . $viewResource->getContext()->getPath());
             $viewResource->create();
             $this->_storeProfile();
         }
     }
 }
예제 #3
0
파일: Form.php 프로젝트: basdog22/Qool
 /**
  * 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 = 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 form 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('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();
     }
 }
    protected function _getDefaultProfile()
    {
        $testAction = '';
        if (Zend_Tool_Project_Provider_Test::isPHPUnitAvailable()) {
            $testAction = '                    	<testApplicationActionMethod forActionName="index" />';
        }
        $version = Zend_Version::VERSION;
        $data = <<<EOS
<?xml version="1.0" encoding="UTF-8"?>
<projectProfile type="default" version="{$version}">
    <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>
        <docsDirectory>
            <file filesystemName="README.txt" defaultContentCallback="Zend_Tool_Project_Provider_Project::getDefaultReadmeContents"/>
        </docsDirectory>
        <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 />
            <testPHPUnitBootstrapFile />
            <testApplicationDirectory>
                <testApplicationControllerDirectory>
                    <testApplicationControllerFile filesystemName="IndexControllerTest.php" forControllerName="Index">
{$testAction}
                    </testApplicationControllerFile>
                </testApplicationControllerDirectory>
      \t    </testApplicationDirectory>
            <testLibraryDirectory />
        </testsDirectory>
    </projectDirectory>
</projectProfile>
EOS;
        return $data;
    }
예제 #5
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();
     }
 }