Permalink
Browse files

Custom providers created for Zend Tool

In this commit custom providers added so developers can create
controllers, views, forms and models easily using shell commands.

To add support for custom providers, Zend-Framework-Skeleton/library
should be added to php include path using zf.ini:
php.include_path = "some_folders::/path/to/Zend-Framework-Skeleton/library"
basicloader.classes.0 = "App_Tool_Project_Provider_Manifest"
  • Loading branch information...
1 parent 8e346af commit e9f017e11c7c1790901fc3910279da1493bc7260 @milani milani committed Jul 23, 2011
View
@@ -7,6 +7,155 @@
<configsDirectory>
<applicationConfigFile type="ini"/>
</configsDirectory>
+ <controllersDirectory enabled="false"/>
+ <modelsDirectory enabled="false"/>
+ <viewsDirectory enabled="false"/>
+ <modulesDirectory>
+ <moduleDirectory moduleName="backoffice">
+ <apisDirectory enabled="false"/>
+ <configsDirectory enabled="false"/>
+ <controllersDirectory>
+ <controllerFile controllerName="Index">
+ <actionMethod actionName="index"/>
+ </controllerFile>
+ <controllerFile controllerName="System">
+ <actionMethod actionName="index"/>
+ <actionMethod actionName="example"/>
+ </controllerFile>
+ <controllerFile controllerName="Groups">
+ <actionMethod actionName="index"/>
+ <actionMethod actionName="add"/>
+ <actionMethod actionName="edit"/>
+ <actionMethod actionName="delete"/>
+ <actionMethod actionName="flippers"/>
+ </controllerFile>
+ <controllerFile controllerName="Users">
+ <actionMethod actionName="index"/>
+ <actionMethod actionName="add"/>
+ <actionMethod actionName="edit"/>
+ <actionMethod actionName="view"/>
+ <actionMethod actionName="delete"/>
+ </controllerFile>
+ <controllerFile controllerName="Flags">
+ <actionMethod actionName="index"/>
+ <actionMethod actionName="toggleprod"/>
+ <actionMethod actionName="toggledev"/>
+ </controllerFile>
+ <controllerFile controllerName="Privileges">
+ <actionMethod actionName="index"/>
+ <actionMethod actionName="add"/>
+ <actionMethod actionName="edit"/>
+ <actionMethod actionName="delete"/>
+ </controllerFile>
+ <controllerFile controllerName="Error">
+ <actionMethod actionName="error"/>
+ <actionMethod actionName="forbidden"/>
+ <actionMethod actionName="flagflippers"/>
+ </controllerFile>
+ </controllersDirectory>
+ <formsDirectory/>
+ <modelsDirectory/>
+ <viewsDirectory>
+ <viewScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Index">
+ <zfsViewScriptFile forActionName="index"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="System">
+ <zfsViewScriptFile forActionName="index"/>
+ <zfsViewScriptFile forActionName="example"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Groups">
+ <zfsViewScriptFile forActionName="index"/>
+ <zfsViewScriptFile forActionName="add"/>
+ <zfsViewScriptFile forActionName="edit"/>
+ <zfsViewScriptFile forActionName="delete"/>
+ <zfsViewScriptFile forActionName="flippers"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Users">
+ <zfsViewScriptFile forActionName="index"/>
+ <zfsViewScriptFile forActionName="add"/>
+ <zfsViewScriptFile forActionName="edit"/>
+ <zfsViewScriptFile forActionName="view"/>
+ <zfsViewScriptFile forActionName="delete"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Flags">
+ <zfsViewScriptFile forActionName="index"/>
+ <zfsViewScriptFile forActionName="toggleprod"/>
+ <zfsViewScriptFile forActionName="toggledev"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Privileges">
+ <zfsViewScriptFile forActionName="index"/>
+ <zfsViewScriptFile forActionName="add"/>
+ <zfsViewScriptFile forActionName="edit"/>
+ <zfsViewScriptFile forActionName="delete"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Error">
+ <zfsViewScriptFile forActionName="error"/>
+ <zfsViewScriptFile forActionName="forbidden"/>
+ <zfsViewScriptFile forActionName="flagflippers"/>
+ </viewControllerScriptsDirectory>
+ </viewScriptsDirectory>
+ </viewsDirectory>
+ </moduleDirectory>
+ <moduleDirectory moduleName="frontend">
+ <apisDirectory enabled="false"/>
+ <configsDirectory enabled="false"/>
+ <controllersDirectory>
+ <controllerFile controllerName="Index">
+ <actionMethod actionName="index"/>
+ <actionMethod actionName="static"/>
+ </controllerFile>
+ <controllerFile controllerName="Error">
+ <actionMethod actionName="error"/>
+ <actionMethod actionName="forbidden"/>
+ <actionMethod actionName="flagflippers"/>
+ </controllerFile>
+ </controllersDirectory>
+ <formsDirectory/>
+ <modelsDirectory/>
+ <viewsDirectory>
+ <viewScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Index">
+ <zfsViewScriptFile forActionName="index"/>
+ <zfsViewScriptFile forActionName="about"/>
+ <zfsViewScriptFile forActionName="faq"/>
+ <zfsViewScriptFile forActionName="help"/>
+ <zfsViewScriptFile forActionName="terms"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Error">
+ <zfsViewScriptFile forActionName="error"/>
+ <zfsViewScriptFile forActionName="forbidden"/>
+ <zfsViewScriptFile forActionName="flagflippers"/>
+ </viewControllerScriptsDirectory>
+ </viewScriptsDirectory>
+ </viewsDirectory>
+ </moduleDirectory>
+ </modulesDirectory>
</applicationDirectory>
+ <libraryDirectory>
+ <zfStandardLibraryDirectory/>
+ <appLibraryDirectory>
+ <zfsModelDirectory>
+ <zfsModelFile modelName="BackofficeUser"/>
+ <zfsModelFile modelName="BackofficeUserGroup"/>
+ <zfsModelFile modelName="BaseUser"/>
+ <zfsModelFile modelName="Flag"/>
+ <zfsModelFile modelName="Flipper"/>
+ <zfsModelFile modelName="Group"/>
+ <zfsModelFile modelName="Privilege"/>
+ </zfsModelDirectory>
+ <zfsTableDirectory>
+ <zfsTableFile tableName="BackofficeUser"/>
+ <zfsTableFile tableName="BackofficeUserGroup"/>
+ <zfsTableFile tableName="Flag"/>
+ <zfsTableFile tableName="Flipper"/>
+ <zfsTableFile tableName="Group"/>
+ <zfsTableFile tableName="Privilege"/>
+ </zfsTableDirectory>
+ </appLibraryDirectory>
+ </libraryDirectory>
+ <testsDirectory enabled="false">
+ <testPHPUnitConfigFile filesystemName="phpunit.xml"/>
+ </testsDirectory>
</projectDirectory>
</projectProfile>
@@ -0,0 +1,79 @@
+<?php
+/**
+ * @see Zend_Tool_Project_Context_Filesystem_Directory
+ */
+require_once 'Zend/Tool/Project/Context/Filesystem/Directory.php';
+
+/**
+ * This class is used for creating App directory in Zend-Framework-Skeleton
+ *
+ * @category App
+ * @package App_Tool
+ * @copyright Copyright company
+ */
+class App_Tool_Project_Context_ZFS_AppLibraryDirectory extends Zend_Tool_Project_Context_Filesystem_Directory
+{
+
+ /**
+ * @var string
+ */
+ protected $_filesystemName = 'App';
+
+ /**
+ * getName()
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return 'AppLibraryDirectory';
+ }
+
+ /**
+ * create()
+ *
+ */
+ public function create()
+ {
+ parent::create();
+ $zfPath = $this->_getZfPath();
+ if ($zfPath != false) {
+ $zfIterator = new RecursiveDirectoryIterator($zfPath);
+ foreach ($rii = new RecursiveIteratorIterator($zfIterator, RecursiveIteratorIterator::SELF_FIRST) as $file) {
+ $relativePath = preg_replace('#^'.preg_quote(realpath($zfPath), '#').'#', '', realpath($file->getPath())) . DIRECTORY_SEPARATOR . $file->getFilename();
+ if (strpos($relativePath, DIRECTORY_SEPARATOR . '.') !== false) {
+ continue;
+ }
+
+ if ($file->isDir()) {
+ mkdir($this->getBaseDirectory() . DIRECTORY_SEPARATOR . $this->getFilesystemName() . $relativePath);
+ } else {
+ copy($file->getPathname(), $this->getBaseDirectory() . DIRECTORY_SEPARATOR . $this->getFilesystemName() . $relativePath);
+ }
+
+ }
+ }
+ }
+
+ /**
+ * _getZfPath()
+ *
+ * @return string|false
+ */
+ protected function _getZfPath()
+ {
+ require_once 'Zend/Loader.php';
+ foreach (Zend_Loader::explodeIncludePath() as $includePath) {
+ if (!file_exists($includePath) || $includePath[0] == '.') {
+ continue;
+ }
+
+ if (realpath($checkedPath = rtrim($includePath, '\\/') . '/Zend/Loader.php') !== false && file_exists($checkedPath)) {
+ return dirname($checkedPath);
+ }
+ }
+
+ return false;
+ }
+
+}
@@ -0,0 +1,129 @@
+<?php
+/**
+ * This class creates a Zend-Framework-Skeleton controller
+ *
+ * @category App
+ * @package App_Tool
+ * @copyright Copyright company
+ */
+class App_Tool_Project_Context_ZFS_ZfsControllerFile extends Zend_Tool_Project_Context_Zf_ControllerFile
+{
+
+ public function getName(){
+ return 'ZfsControllerFile';
+ }
+
+ /**
+ * getContents()
+ *
+ * @return string
+ */
+ public function getContents()
+ {
+ $filter = new Zend_Filter_Word_DashToCamelCase();
+ $moduleName = ucfirst($this->_moduleName);
+ $className = ucfirst($this->_controllerName) . 'Controller';
+
+ $codeGenFile = new Zend_CodeGenerator_Php_File(array(
+ 'fileName' => $this->getPath(),
+ 'classes' => array(
+ new Zend_CodeGenerator_Php_Class(array(
+ 'name' => $className,
+ 'extendedClass' => 'App_'.$moduleName.'_Controller',
+ 'methods' => array(
+ new Zend_CodeGenerator_Php_Method(array(
+ 'name' => 'init',
+ 'body' => '/* Initialize action controller here */',
+ ))
+ )
+ ))
+ )
+ ));
+
+
+ if ($className == 'ErrorController') {
+
+ $codeGenFile = new Zend_CodeGenerator_Php_File(array(
+ 'fileName' => $this->getPath(),
+ 'classes' => array(
+ new Zend_CodeGenerator_Php_Class(array(
+ 'name' => $className,
+ 'extendedClass' => 'App_'.$moduleName.'_Controller',
+ 'properties' => array(
+ new Zend_CodeGenerator_Php_Property(array(
+ 'name' => '_dispatch404s',
+ 'visibility' => Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED,
+ 'defaultValue' => array(
+ Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE,
+ Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER,
+ Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION
+ ),
+ ))
+ ),
+ 'methods' => array(
+ new Zend_CodeGenerator_Php_Method(
+ array(
+ 'name' => 'init',
+ 'body' => <<<EOS
+parent::init();
+
+\$this->_helper->layout()->setLayout('layout');
+EOS
+ )),
+ new Zend_CodeGenerator_Php_Method(array(
+ 'name' => 'errorAction',
+ 'body' => <<<EOS
+\$errorInfo = \$this->_getParam('error_handler');
+
+if (in_array(\$errorInfo->type, \$this->_dispatch404s)) {
+ \$this->_dispatch404();
+ return;
+}
+
+\$this->getResponse()->setRawHeader('HTTP/1.1 500 Internal Server Error');
+
+\$this->title = 'Internal Server Error';
+
+\$this->view->exception = \$errorInfo->exception;
+EOS
+ )),
+ new Zend_CodeGenerator_Php_Method(array(
+ 'name' => 'flagflippersAction',
+ 'body' => <<<EOS
+if (Zend_Registry::get('IS_DEVELOPMENT')) {
+ \$this->title = 'Flag and Flipper not found';
+
+ \$this->view->originalController = \$this->_getParam('originalController');
+ \$this->view->originalAction = \$this->_getParam('originalAction');
+} else {
+ \$this->_dispatch404();
+}
+EOS
+ )),
+ new Zend_CodeGenerator_Php_Method(array(
+ 'name' => 'forbiddenAction',
+ 'body' => '$this->title = \'Forbidden\';'
+ )),
+ new Zend_CodeGenerator_Php_Method(array(
+ 'name' => '_dispatch404',
+ 'visibility' => Zend_CodeGenerator_Php_Method::VISIBILITY_PROTECTED,
+ 'body' => <<<EOS
+\$this->title = 'Page not found';
+\$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
+
+\$this->render('error-404');
+EOS
+ )),
+ )
+ ))
+ )
+ ));
+
+ }
+
+ // store the generator into the registry so that the addAction command can use the same object later
+ Zend_CodeGenerator_Php_File::registerFileCodeGenerator($codeGenFile); // REQUIRES filename to be set
+ return $codeGenFile->generate();
+ }
+
+}
Oops, something went wrong.

0 comments on commit e9f017e

Please sign in to comment.