Browse Source

[FEATURE] console add module:create command for creating very simple module structure

quickform
norbertnader 4 years ago
parent
commit
18e564cb7a
2 changed files with 76 additions and 0 deletions
  1. +2
    -0
      console.php
  2. +74
    -0
      console/Modules/CreateModuleCommand.php

+ 2
- 0
console.php View File

@@ -14,6 +14,7 @@ use Symfony\Component\Console\Application;
use Epesi\Console\Modules\ListModulesCommand;
use Epesi\Console\Modules\DisableModuleCommand;
use Epesi\Console\Modules\EnableModuleCommand;
use Epesi\Console\Modules\CreateModuleCommand;

ModuleManager::load_modules();

@@ -26,4 +27,5 @@ $application->add(new ThemeRebuildCommand());
$application->add(new MaintenanceStatusCommand());
$application->add(new InstallModuleCommand());
$application->add(new UninstallModuleCommand());
$application->add(new CreateModuleCommand());
$application->run();

+ 74
- 0
console/Modules/CreateModuleCommand.php View File

@@ -0,0 +1,74 @@
<?php

namespace Epesi\Console\Modules;
use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CreateModuleCommand extends Command
{
protected function configure(){
$this
->setName('module:create')
->setDescription('Install EPESI module')
->addArgument(
'type',
InputArgument::REQUIRED,
'Module type'
)
->addArgument(
'name',
InputArgument::REQUIRED,
'Module name'
)
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
$module_type = $input->getArgument('type');
$module_name = $input->getArgument('name');
shell_exec('mkdir '.EPESI_LOCAL_DIR.'/modules/'.$module_type.'/'.$module_name);
shell_exec('touch '.EPESI_LOCAL_DIR.'/modules/'.$module_type.'/'.$module_name.'/'.$module_name.'_0.php');
$fp = fopen(EPESI_LOCAL_DIR.'/modules/'.$module_type.'/'.$module_name.'/'.$module_name.'_0.php','w');
fwrite($fp,'<?php'.PHP_EOL);
fwrite($fp,''.PHP_EOL);
fwrite($fp,'defined("_VALID_ACCESS") || die(\'Direct access forbidden\');'.PHP_EOL);
fwrite($fp,''.PHP_EOL);
fwrite($fp,'class '.$module_type.'_'.$module_name.' extends Module'.PHP_EOL);
fwrite($fp,'{'.PHP_EOL);
fwrite($fp,'}'.PHP_EOL);
shell_exec('touch '.EPESI_LOCAL_DIR.'/modules/'.$module_type.'/'.$module_name.'/'.$module_name.'Common_0.php');
$fp = fopen(EPESI_LOCAL_DIR.'/modules/'.$module_type.'/'.$module_name.'/'.$module_name.'Common_0.php','w');
fwrite($fp,'<?php'.PHP_EOL);
fwrite($fp,''.PHP_EOL);
fwrite($fp,'defined("_VALID_ACCESS") || die(\'Direct access forbidden\');'.PHP_EOL);
fwrite($fp,''.PHP_EOL);
fwrite($fp,'class '.$module_type.'_'.$module_name.'Common extends ModuleCommon'.PHP_EOL);
fwrite($fp,'{'.PHP_EOL);
fwrite($fp,'}'.PHP_EOL);
shell_exec('touch '.EPESI_LOCAL_DIR.'/modules/'.$module_type.'/'.$module_name.'/'.$module_name.'Install.php');
$fp = fopen(EPESI_LOCAL_DIR.'/modules/'.$module_type.'/'.$module_name.'/'.$module_name.'Install.php','w');
fwrite($fp,'<?php'.PHP_EOL);
fwrite($fp,''.PHP_EOL);
fwrite($fp,'defined("_VALID_ACCESS") || die(\'Direct access forbidden\');'.PHP_EOL);
fwrite($fp,''.PHP_EOL);
fwrite($fp,'class '.$module_type.'_'.$module_name.'Install extends ModuleInstall'.PHP_EOL);
fwrite($fp,'{'.PHP_EOL);
fwrite($fp,' public function install()'.PHP_EOL);
fwrite($fp,' {'.PHP_EOL);
fwrite($fp,' return true;'.PHP_EOL);
fwrite($fp,' }'.PHP_EOL);
fwrite($fp,' public function uninstall()'.PHP_EOL);
fwrite($fp,' {'.PHP_EOL);
fwrite($fp,' return true;'.PHP_EOL);
fwrite($fp,' }'.PHP_EOL);
fwrite($fp,' public function requires($v)'.PHP_EOL);
fwrite($fp,' {'.PHP_EOL);
fwrite($fp,' return array();'.PHP_EOL);
fwrite($fp,' }'.PHP_EOL);
fwrite($fp,'}'.PHP_EOL);
$output->writeln($module_type.'/'.$module_name.' module created');
}
}

Loading…
Cancel
Save