/** * イベントを処理する */ 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 function createDirectory($dir_path, $mode = 0777) { Charcoal_ParamTrait::validateString(1, $dir_path); Charcoal_ParamTrait::validateInteger(2, $mode); try { $obj = new Charcoal_File($dir_path, $this->_base_dir_obj); $obj->makeDirectory($mode, TRUE); return $obj; } catch (Exception $e) { _catch($e); _throw(new Charcoal_FileSystemComponentException(s('creating directory failed.'), $e)); } }
public function open() { // すでに開いているならなにもしない if ($this->open) { return; } $file_name = rtrim($this->logs_dir, ' /') . '/' . ltrim($this->file_name, ' /'); $dir = new Charcoal_File(dirname($file_name)); // ディレクトリを作成 try { $dir->makeDirectory(); } catch (Exception $e) { print "FATAL error occured while output log file:{$this->file_name} error={$e}" . PHP_EOL; } $this->fp = fopen($file_name, "a"); $this->open = $this->fp != FALSE; }
/** * render buffer * * @param Charcoal_String|string $buffer rendering data */ public function render($buffer) { Charcoal_ParamTrait::validateString(1, $buffer); $buffer = us($buffer); if (is_string($buffer)) { $dir = new Charcoal_File(dirname($this->file_path)); if (!$dir->exists()) { $dir->makeDirectory($this->dir_mode); } if (!$dir->isWriteable()) { _throw(new Charcoal_RenderTargetException("directory not writable: {$dir}")); } $result = @file_put_contents($this->file_path, $buffer, LOCK_EX); if ($result === FALSE) { $last_error = print_r(error_get_last(), true); _throw(new Charcoal_RenderTargetException("file_put_contents failed: {$this->file_path} last error: {$last_error}")); } } }
/** * イベントを処理する */ 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); }
/** * create directory * * @return Charcoal_File file object of created directory */ public function create() { try { $obj = new Charcoal_File(s($this->_dir_path)); $obj->makeDirectory($this->_mode, b(TRUE)); return $obj; } catch (Exception $e) { _catch($e); _throw(new Charcoal_TempDirComponentException(s('creating directory failed.'), $e)); } }
/** * イベントを処理する */ 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); }
/** * prepare output directory * * @param string $out_dir * * @return Charcoal_File */ private function prepareOutputDirectory($out_dir) { $out_dir = new Charcoal_File($out_dir); $out_dir->makeDirectory(self::DIR_MODE); }
/** * イベントを処理する */ 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); }