diff --git a/modules/pulsestorm/magento1/generate/controller/module.php b/modules/pulsestorm/magento1/generate/controller/module.php
new file mode 100644
index 0000000..6bc856d
--- /dev/null
+++ b/modules/pulsestorm/magento1/generate/controller/module.php
@@ -0,0 +1,23 @@
+modules->{$fullName}->codePool;
+}
+
+function getBaseModuleDir($fullName) {
+ list($package, $module) = explode('_', $fullName);
+ $codePool = getModuleCodePool($fullName);
+ return getBaseMagentoDir() . '/app/code/' . $codePool . '/' .
+ $package . '/' . $module;
+}
+
+function getPathModuleConfigFile($fullName, $file='config.xml') {
+ return getBaseModuleDir($fullName) . '/etc/' . $file;
+}
+
+function getPathModule($fullName, $folder='') {
+ return getBaseModuleDir($fullName) . '/' . $folder;
+}
+
+function m1CreateClassTemplate($class, $extends=false, $implements=false, $includeUse=false) {
+ $contents = createClassTemplate($class, $extends, $implements, $includeUse);
+ return str_replace("namespace ;\n\n", '', $contents);
+}
+
+function createFrontendController($fullName, $path) {
+ $parts = explode('/',$path);
+ if(count($parts) !== 3) {
+ exitWithErrorMessage('please use full/three/part URL path');
+ }
+ list($module, $controller, $action) = $parts;
+
+ $parts = explode('_',$controller);
+ $parts = array_map(function($part){
+ return ucwords($part);
+ }, $parts);
+ $camelCasedController = implode('_', $parts);
+ $classContents = m1CreateClassTemplate(
+ $fullName . "_${camelCasedController}Controller",
+ 'Mage_Core_Controller_Front_Action'
+ );
+
+ $classContents = str_replace(
+ '<$body$>',
+ "\n
+ public function ${action}Action()
+ {
+ \$this->loadLayout();
+ \$this->renderLayout();
+ }
+",
+ $classContents
+ );
+ $pathControllers = getPathModule($fullName, 'controllers');
+ $parts = explode('_', $camelCasedController);
+ $last = array_pop($parts);
+ $camelCasedControllerPath = implode('_', $parts);
+ $camelCasedControllerPath .= ('/' . $last);
+
+ writeStringToFile(
+ $pathControllers . "/${camelCasedControllerPath}Controller.php",
+ $classContents,
+ false
+ );
+};
+
+/**
+* Not a command, just library functions
+* @command library
+*/
+function pestle_cli($argv)
+{
+}
diff --git a/modules/pulsestorm/magento1/generate/module/module.php b/modules/pulsestorm/magento1/generate/module/module.php
new file mode 100644
index 0000000..90c679e
--- /dev/null
+++ b/modules/pulsestorm/magento1/generate/module/module.php
@@ -0,0 +1,55 @@
+' . "\n" .
+"
+
+ <$fullModuleName>
+ 0.1.0
+ $fullModuleName>
+
+";
+}
+
+function generateModuleDeclarationFile($fullModuleName, $pool) {
+ return '' . "\n" .
+"
+
+ <$fullModuleName>
+ true
+ $pool
+
+ $fullModuleName>
+
+";
+}
+
+/**
+* One Line Description
+*
+* @command magento1:generate:module
+* @argument code_pool Code Pool [community]
+* @argument full_module_name Full Module Name [Pulsestorm_Helloworld]
+*/
+function pestle_cli($argv)
+{
+ list($package, $module) = explode('_', $argv['full_module_name']);
+
+ $pathEtc = getBaseMagentoDir() . '/app/etc/modules/' . $argv['full_module_name'] . '.xml';
+ $pathModule = getBaseMagentoDir() . '/app/code/' . $argv['code_pool'] . '/' . $package .
+ '/' . $module . '/etc/config.xml';
+
+ writeStringToFile($pathEtc, generateModuleDeclarationFile($argv['full_module_name'], $argv['code_pool']));
+ writeStringToFile($pathModule, generateConfigXml($argv['full_module_name']));
+
+ output('');
+ output('Generated Base Module Files:');
+ output(' ' . $pathEtc);
+ output(' ' . $pathModule);
+}
diff --git a/modules/pulsestorm/magento1/generate/route/module.php b/modules/pulsestorm/magento1/generate/route/module.php
new file mode 100644
index 0000000..aa51d53
--- /dev/null
+++ b/modules/pulsestorm/magento1/generate/route/module.php
@@ -0,0 +1,53 @@
+frontend->routers->{$fullNameLc})) {
+ output('frontend/routers/' . $fullNameLc . ' already exists');
+ exit;
+ }
+
+ $xpathModuleRouters = 'frontend/routers/' . strToLower($argv['full_module_name']);
+ $xmlModuleRouters = simpleXmlAddNodesXpath($config, $xpathModuleRouters);
+ $xmlUse = simpleXmlAddNodesXpath($config, $xpathModuleRouters . '/use');
+ simpleXmlAddNodesXpath($config, $xpathModuleRouters . '/args');
+ $xmlModule = simpleXmlAddNodesXpath($config, $xpathModuleRouters . '/args/module');
+ $xmlFrontName = simpleXmlAddNodesXpath($config, $xpathModuleRouters . '/args/frontName');
+
+ $xmlUse[0] = 'standard';
+ $xmlModule[0] = $argv['full_module_name'];
+ $xmlFrontName[0] = strToLower($argv['full_module_name']);
+
+ writeStringToFile(
+ $pathConfig,
+ formatXmlString($config->asXml())
+ );
+
+ createFrontendController(
+ $argv['full_module_name'],
+ 'pulsestorm_simplerest/index/index'
+ );
+
+ output('Done');
+}
diff --git a/modules/pulsestorm/pestle/library/module.php b/modules/pulsestorm/pestle/library/module.php
index 23e2935..01a8720 100644
--- a/modules/pulsestorm/pestle/library/module.php
+++ b/modules/pulsestorm/pestle/library/module.php
@@ -123,16 +123,22 @@ function getPartFromDeclaration($class, $part)
return null;
}
-function writeStringToFile($path, $contents)
+function writeStringToFile($path, $contents, $overwrite=true)
{
if(!is_dir(dirname($path)))
{
mkdir(dirname($path),0755,true);
}
+
+ if(file_exists($path) && !$overwrite) {
+ output('SKIPPING: file already exists ' . $path);
+ return;
+ }
+
$path_backup = $path . '.' . uniqid() . '.bak.php';
if(file_exists($path))
{
- output('Backing existing file: ' . $path_backup);
+ output('Backing up existing file: ' . $path_backup);
copy($path, $path_backup);
}
file_put_contents($path, $contents);
@@ -166,6 +172,21 @@ function getDocCommentAsString($function)
return trim( implode("\n", $lines) );
}
+function getBaseDir($path, $fileToTest) {
+ if($path && isAboveRoot($path))
+ {
+ output("Could not find base Magento directory");
+ exit;
+ }
+
+ $path = $path ? $path : getcwd();
+ if(file_exists($path . '/' . $fileToTest))
+ {
+ return realpath($path);
+ }
+ return getBaseDir($path . '/..', $fileToTest);
+}
+
function isAboveRoot($path)
{
$parts = explode('..', $path);
diff --git a/modules/pulsestorm/pestle/runner/module.php b/modules/pulsestorm/pestle/runner/module.php
index c68e9ae..b6c9a04 100644
--- a/modules/pulsestorm/pestle/runner/module.php
+++ b/modules/pulsestorm/pestle/runner/module.php
@@ -153,7 +153,7 @@ function getListOfDefinedCliFunctions()
}
$main = $namespace . '\\pestle_cli';
if(!function_exists($main)) {
- if(!in_array($main, ['zend\diactoros\pestle_cli'])) {
+ if(!in_array($main, ['zend\diactoros\pestle_cli','swoole\coroutine\pestle_cli','co\pestle_cli'])) {
output("Skipping $main -- no such function");
}
continue;