public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $filter->filter($this->_controllerName) . 'Controller'; $codeGenFile = new ZendL_Tool_CodeGenerator_Php_File(array('classes' => array(new ZendL_Tool_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Controller_Action', 'methods' => array(new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'init', 'body' => ' /* Initialize action controller here */')), new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'indexAction', 'body' => ' /* Default action for action controller */')))))))); if ($className == 'ErrorController') { $codeGenFile = new ZendL_Tool_CodeGenerator_Php_File(array('classes' => array(new ZendL_Tool_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Controller_Action', 'methods' => array(new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'init', 'body' => <<<EOS \$errors = \$this->_getParam('error_handler'); switch (\$errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found \$this->getResponse()->setHttpResponseCode(404); \$this->view->message = 'Page not found'; break; default: // application error \$this->getResponse()->setHttpResponseCode(500); \$this->view->message = 'Application error'; break; } \$this->view->env = \$this->getInvokeArg('env'); \$this->view->exception = \$errors->exception; \$this->view->request = \$errors->request; EOS )))))))); } return $codeGenFile->generate(); }
public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $filter->filter($this->_controllerName) . 'Controller'; $codeGenFile = new ZendL_Tool_CodeGenerator_Php_File(array('classes' => array(new ZendL_Tool_CodeGenerator_Php_Class(array('name' => $className, 'methods' => array(new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'init', 'body' => ' /* Initialize action controller here */')), new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'indexAction', 'body' => ' /* Default action for action controller */')))))))); if ($className == 'ErrorController') { $classes = $codeGenFile->getClasses(); $classes['ErrorController']->setMethod(new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'errorAction', 'body' => ' // some errorAction stuff here'))); } return $codeGenFile->generate(); }
public function testFromReflection() { $tempFile = tempnam(sys_get_temp_dir(), 'UnitFile'); $codeGenFile = new ZendL_Tool_CodeGenerator_Php_File(array('class' => array('name' => 'SampleClass'))); file_put_contents($tempFile, $codeGenFile->generate()); require_once $tempFile; $codeGenFileFromDisk = ZendL_Tool_CodeGenerator_Php_File::fromReflection(new ZendL_Reflection_File($tempFile)); unlink($tempFile); $this->assertEquals(get_class($codeGenFileFromDisk), 'ZendL_Tool_CodeGenerator_Php_File'); $this->assertEquals(count($codeGenFileFromDisk->getClasses()), 1); }
public function getContents() { $codeGenerator = new ZendL_Tool_CodeGenerator_Php_File(array('body' => <<<EOS <?php // @see application/bootstrap.php \$bootstrap = true; require '../application/bootstrap.php'; // \$frontController is created in your boostrap file. Now we'll dispatch it, which dispatches your application. \$frontController->dispatch(); EOS )); return $codeGenerator->generate(); }
public function getContents() { $codeGenerator = new ZendL_Tool_CodeGenerator_Php_File(array('body' => <<<EOS <?php // ** Check to see if the environment is already setup ** if (isset(\$bootstrap) && \$bootstrap) { // Enable all errors so we'll know when something goes wrong. error_reporting(E_ALL | E_STRICT); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); // Add our {{library}} directory to the include path so that PHP can find the Zend Framework classes. // you may wish to add other paths here, or keep system paths: set_include_path('../library' . PATH_SEPARATOR . get_include_path() set_include_path('../library'); // Set up autoload. // This is a nifty trick that allows ZF to load classes automatically so that you don't have to litter your // code with 'include' or 'require' statements. require_once "Zend/Loader.php"; Zend_Loader::registerAutoload(); } // ** Get the front controller ** // The Zend_Front_Controller class implements the Singleton pattern, which is a design pattern used to ensure // there is only one instance of Zend_Front_Controller created on each request. \$frontController = Zend_Controller_Front::getInstance(); // Point the front controller to your action controller directory. \$frontController->setControllerDirectory('../application/controllers'); // Set the current environment // Set a variable in the front controller indicating the current environment -- // commonly one of development, staging, testing, production, but wholly // dependent on your organization and site's needs. \$frontController->setParam('env', 'development'); EOS )); return $codeGenerator->generate(); }
public function getContents() { $codeGenerator = new ZendL_Tool_CodeGenerator_Php_File(array('body' => 'include \'../bootstrap.php\';')); return $codeGenerator->generate(); }