/** * イベントを処理する */ public function processEvent($context) { $event = $context->getEvent(); // パラメータを取得 $app_name = $event->getAppName(); $project_name = $event->getProjectName(); $out_dir = $event->getTargetDir(); //======================================= // Confirm input parameters //======================================= if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $app_name)) { _throw(new Charcoal_InvalidArgumentException($app_name)); } if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $project_name)) { _throw(new Charcoal_InvalidArgumentException($project_name)); } //======================================= // Make output directory //======================================= $out_dir = new Charcoal_File($out_dir); $out_dir->makeDirectory(self::DIR_MODE); //======================================= // Make web_app directory //======================================= $webapp_dir = new Charcoal_File('web_app', $out_dir); $webapp_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project directory //======================================= $project_dir = new Charcoal_File($project_name, $webapp_dir); $project_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project/app directory //======================================= $project_app_dir = new Charcoal_File('app', $project_dir); $project_app_dir->makeDirectory(self::DIR_MODE); //======================================= // Make application directory //======================================= $application_dir = new Charcoal_File($app_name, $project_app_dir); $application_dir->makeDirectory(self::DIR_MODE); //======================================= // Make application/class directory //======================================= $app_class_dir = new Charcoal_File('class', $application_dir); $app_class_dir->makeDirectory(self::DIR_MODE); //======================================= // Make application/config directory //======================================= $app_config_dir = new Charcoal_File('config', $application_dir); $app_config_dir->makeDirectory(self::DIR_MODE); //======================================= // Make application/module directory //======================================= $module_dir = new Charcoal_File('module', $application_dir); $module_dir->makeDirectory(self::DIR_MODE); echo "Application[{$app_name}] created at: " . $application_dir->getAbsolutePath() . PHP_EOL; return b(true); }
public static function copyFile(Charcoal_File $src, Charcoal_File $dest) { // コピー元ファイルの確認 if (!$src->isFile()) { _throw(new Charcoal_FileSystemException('copy', $src->getAbsolutePath() . ' is not file')); } if (!$src->isReadable()) { _throw(new Charcoal_FileSystemException('copy', $src->getAbsolutePath() . ' is not readable')); } // コピー先の確認 $dir = $dest->getDir(); if (!$dir->isDir()) { _throw(new Charcoal_FileSystemException('copy', $dir->getAbsolutePath() . ' is not directory')); } $src = us($src->getPath()); $dest = us($dest->getPath()); $result = copy($src, $dest); if (false === $result) { _throw(new Charcoal_FileSystemException('copy', "[src]{$src} [dest]{$dest}")); } }
/** * イベントを処理する */ public function processEvent($context) { $event = $context->getEvent(); // パラメータを取得 $project_name = $event->getProjectName(); $out_dir = $event->getTargetDir(); //======================================= // Confirm input parameters //======================================= if (empty($project_name) || !preg_match('/^[0-9a-zA-Z_\\-]*$/', $project_name)) { _throw(new Charcoal_InvalidArgumentException($project_name)); } //======================================= // Make output directory //======================================= $out_dir = new Charcoal_File($out_dir); $out_dir->makeDirectory(self::DIR_MODE); //======================================= // Make public directory //======================================= $public_dir = new Charcoal_File('public_html', $out_dir); $public_dir->makeDirectory(self::DIR_MODE); //======================================= // Make ext_lib directory //======================================= $ext_lib_dir = new Charcoal_File('ext_lib', $out_dir); $ext_lib_dir->makeDirectory(self::DIR_MODE); //======================================= // Make logs directory //======================================= $logs_dir = new Charcoal_File('logs', $out_dir); $logs_dir->makeDirectory(self::DIR_MODE); //======================================= // Make sessions directory //======================================= $sessions_dir = new Charcoal_File('sessions', $out_dir); $sessions_dir->makeDirectory(self::DIR_MODE); //======================================= // Make cache directory //======================================= $cache_dir = new Charcoal_File('cache', $out_dir); $cache_dir->makeDirectory(self::DIR_MODE); //======================================= // Make tmp directory //======================================= $tmp_dir = new Charcoal_File('tmp', $out_dir); $tmp_dir->makeDirectory(self::DIR_MODE); //======================================= // Make web_app directory //======================================= $webapp_dir = new Charcoal_File('web_app', $out_dir); $webapp_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project directory //======================================= $project_dir = new Charcoal_File($project_name, $webapp_dir); $project_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project/app directory //======================================= $project_app_dir = new Charcoal_File('app', $project_dir); $project_app_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project/config directory //======================================= $project_config_dir = new Charcoal_File('config', $project_dir); $project_config_dir->makeDirectory(self::DIR_MODE); echo "Project[{$project_name}] created at: " . $project_dir->getAbsolutePath() . PHP_EOL; return b(true); }
/** * イベントを処理する */ public function processEvent($context) { $event = $context->getEvent(); // パラメータを取得 $module_path = $event->getModulePath(); $app_name = $event->getAppName(); $project_name = $event->getProjectName(); $out_dir = $event->getTargetDir(); //======================================= // Confirm input parameters //======================================= if (!preg_match('/^[@:0-9a-zA-Z_\\-]*$/', $module_path)) { _throw(new Charcoal_InvalidArgumentException($module_path)); } if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $app_name)) { _throw(new Charcoal_InvalidArgumentException($app_name)); } if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $project_name)) { _throw(new Charcoal_InvalidArgumentException($project_name)); } //======================================= // Make output directory //======================================= $out_dir = new Charcoal_File($out_dir); $out_dir->makeDirectory(self::DIR_MODE); //======================================= // Make web_app directory //======================================= $webapp_dir = new Charcoal_File('web_app', $out_dir); $webapp_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project directory //======================================= $project_dir = new Charcoal_File($project_name, $webapp_dir); $project_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project/app directory //======================================= $project_app_dir = new Charcoal_File('app', $project_dir); $project_app_dir->makeDirectory(self::DIR_MODE); //======================================= // Make application directory //======================================= $application_dir = new Charcoal_File($app_name, $project_app_dir); $application_dir->makeDirectory(self::DIR_MODE); //======================================= // Make application/module directory //======================================= $module_dir = new Charcoal_File('module', $application_dir); $module_dir->makeDirectory(self::DIR_MODE); //======================================= // Make target module directory //======================================= $module_path = new Charcoal_ObjectPath($module_path); $target_module_dir = new Charcoal_File($module_path->getRealPath(), $module_dir); $target_module_dir->makeDirectory(self::DIR_MODE); //======================================= // Make procedure.ini file //======================================= $lines = NULL; $lines[] = "debug_mode = false"; $lines[] = "class_name = Charcoal_SimpleProcedure"; $lines[] = "task_manager = default_task_manager"; $lines[] = "tasks = "; $lines[] = "modules = "; $lines[] = "events = "; $lines[] = "log_enabled = yes"; $lines[] = "log_level = E"; $lines[] = "log_loggers = error"; $outfile = new Charcoal_File('procedure.ini', $target_module_dir); Charcoal_FileSystemUtil::outputFile($outfile, $lines); echo "Module[{$module_path}] created at: " . $target_module_dir->getAbsolutePath() . PHP_EOL; return b(true); }
/** * イベントを処理する */ public function processEvent($context) { $event = $context->getEvent(); // パラメータを取得 $task_name = $event->getTaskName(); $module_path = $event->getModulePath(); $app_name = $event->getAppName(); $project_name = $event->getProjectName(); $out_dir = $event->getTargetDir(); //======================================= // Confirm input parameters //======================================= if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $task_name)) { _throw(new Charcoal_InvalidArgumentException($task_name)); } if (!preg_match('/^[@:0-9a-zA-Z_\\-]*$/', $module_path)) { _throw(new Charcoal_InvalidArgumentException($module_path)); } if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $app_name)) { _throw(new Charcoal_InvalidArgumentException($app_name)); } if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $project_name)) { _throw(new Charcoal_InvalidArgumentException($project_name)); } //======================================= // Make output directory //======================================= $out_dir = new Charcoal_File($out_dir); $out_dir->makeDirectory(self::DIR_MODE); //======================================= // Make web_app directory //======================================= $webapp_dir = new Charcoal_File('web_app', $out_dir); $webapp_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project directory //======================================= $project_dir = new Charcoal_File($project_name, $webapp_dir); $project_dir->makeDirectory(self::DIR_MODE); //======================================= // Make project/app directory //======================================= $project_app_dir = new Charcoal_File('app', $project_dir); $project_app_dir->makeDirectory(self::DIR_MODE); //======================================= // Make application directory //======================================= $application_dir = new Charcoal_File($app_name, $project_app_dir); $application_dir->makeDirectory(self::DIR_MODE); //======================================= // Make application/module directory //======================================= $module_dir = new Charcoal_File('module', $application_dir); $module_dir->makeDirectory(self::DIR_MODE); //======================================= // Make target module directory //======================================= $module_path = new Charcoal_ObjectPath($module_path); $target_module_dir = new Charcoal_File($module_path->getRealPath(), $module_dir); $target_module_dir->makeDirectory(self::DIR_MODE); //======================================= // Make task.ini file //======================================= $task_class_name = str_replace(' ', '', ucwords(str_replace('_', ' ', $task_name))) . 'Task'; $lines = NULL; $lines[] = "class_name = {$task_class_name}"; $lines[] = "event_filters = "; $outfile = new Charcoal_File($task_name . '_task.task.ini', $target_module_dir); Charcoal_FileSystemUtil::outputFile($outfile, $lines); //======================================= // Make task class file //======================================= $lines = NULL; $lines[] = "<?php"; $lines[] = "/**"; $lines[] = " * (Auto Generated Class)"; $lines[] = " * {$task_class_name} class"; $lines[] = " * "; $lines[] = " * generated by CharcoalPHP ver." . Charcoal_Framework::getVersion(); $lines[] = " * "; $lines[] = " * @author your name"; $lines[] = " * @copyright "; $lines[] = " */"; $lines[] = "class {$task_class_name} extends Charcoal_Task"; $lines[] = "{"; $lines[] = " /**"; $lines[] = " * Process user/system event"; $lines[] = " *"; $lines[] = " * @param Charcoal_EventContext \$context Event context"; $lines[] = " * "; $lines[] = " * @return bool|Charcoal_Boolean Return true if the event is processed. Or you can "; $lines[] = " * return false if another task should process the event."; $lines[] = " */"; $lines[] = " public function processEvent( \$context )"; $lines[] = " {"; $lines[] = " \$request = \$context->getRequest();"; $lines[] = " \$response = \$context->getResponse();"; $lines[] = " \$sequence = \$context->getSequence();"; $lines[] = " \$procedure = \$context->getProcedure();"; $lines[] = " "; $lines[] = " // TODO: write processing event code here"; $lines[] = " \$name = \$request->getString('name', 'john');"; $lines[] = " "; $lines[] = " return b(true);"; $lines[] = " }"; $lines[] = "}"; $outfile = new Charcoal_File($task_class_name . '.class.php', $target_module_dir); Charcoal_FileSystemUtil::outputFile($outfile, $lines); echo "Task[{$task_name}] created at: " . $target_module_dir->getAbsolutePath() . PHP_EOL; return b(true); }