/** * イベントを処理する * * @param Charcoal_IEventContext $context * * @return boolean */ public function processEvent($context) { $request = $context->getRequest(); // パラメータを取得 $database = us($request->getString('p2')); $table = us($request->getString('p3')); //======================================= // Confirm input parameters //======================================= if (!empty($database) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $database)) { print "Parameter 2(database name) is wrong: {$database}" . PHP_EOL; return b(true); } if (!empty($table) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $table)) { print "Parameter 3(table name) is wrong: {$table}" . PHP_EOL; return b(true); } //======================================= // Send new project event //======================================= /** @var Charcoal_IEvent $event */ $event_path = 'show_table_event@:charcoal:db:show:table'; $event = $context->createEvent($event_path, array($database, $table)); $context->pushEvent($event); return b(true); }
/** * process event * * @param Charcoal_IEventContext $context event context * * @return boolean */ public function processEvent($context) { $request = $context->getRequest(); // get command line options $cmd_path = us($request->getString('p2')); $options = array('@:help' => '[command_path]', '@:version' => '', '@:db:generate:model' => 'databse table [target directory]', '@:db:show:table' => 'databse table'); $examples1 = array('@:help' => '@:version => show "@:version" command help', '@:db:generate:model' => 'charcoal blog => generate "blog" table\'s model files in "charcoal" database' . '(model files are generated into current directory).', '@:db:show:table' => 'charcoal blog => show description about "blog" table in "charcoal" database.'); $examples2 = array('@:help' => 'list => show all supported commands("list" can be omitted)'); $descriptions = array('@:help' => 'show command help or list all command paths', '@:version' => 'show framework version.', '@:db:generate:model' => 'create model files into [target directory].', '@:db:show:table' => 'show table description'); if (empty($cmd_path) || $cmd_path == 'list') { // show all commands echo "Supported command list: "; foreach ($options as $path => $opt) { echo "\n " . $path; } } elseif (isset($options[$cmd_path])) { echo "How to use: "; echo "\n charcoal " . $cmd_path . ' ' . $options[$cmd_path]; if (isset($examples1[$cmd_path])) { echo "\nExample:"; echo "\n charcoal " . $cmd_path . ' ' . $examples1[$cmd_path]; if (isset($examples2[$cmd_path])) { echo "\n charcoal " . $cmd_path . ' ' . $examples2[$cmd_path]; } } if (isset($descriptions[$cmd_path])) { echo "\n\nThis command " . $descriptions[$cmd_path]; } } else { echo "Command not found: {$cmd_path}"; } echo "\n"; return b(true); }
/** * Process events * * @param Charcoal_IEventContext $context event context */ public function processEvent($context) { $request = $context->getRequest(); $response = $context->getResponse(); $sequence = $context->getSequence(); $procedure = $context->getProcedure(); $event = $context->getEvent(); // form token component $form_token = $context->getComponent(s('form_token@:charcoal:form')); if ($event instanceof Charcoal_SetupEvent) { $form_token->setupForm($sequence, $response); return b(TRUE); } elseif ($event instanceof Charcoal_AuthTokenEvent) { return $form_token->checkToken($sequence, $request); } return b(FALSE); }
/** * process event * * @param Charcoal_IEventContext $context event context * * @return boolean|Charcoal_Boolean * * @throws DivisionByZeroException */ public function processEvent($context) { $request = $context->getRequest(); // Get parameter from request $a = $request->getInteger('a', 0); $b = $request->getInteger('b', 0); $op = $request->getString('op', '+'); $a = ui($a); $b = ui($b); $op = us($op); $result = NULL; switch ($op) { case 'add': $result = $a + $b; break; case 'sub': $result = $a - $b; break; case 'mul': $result = $a * $b; break; case 'div': if ($b == 0) { throw new DivisionByZeroException(); } $result = $a / $b; break; } // show message if ($result) { echo "result:" . $result . eol(); } else { echo "<pre>USAGE:" . PHP_EOL; echo "http://" . $_SERVER['SERVER_NAME'] . "/calc/value1/value2/[add/sub/mul/div]" . PHP_EOL; echo "value1, value2: number" . eol(); echo "add: shows result of 'value1 + value2'" . PHP_EOL; echo "sub: shows result of 'value1 - value2'" . PHP_EOL; echo "mul: shows result of 'value1 * value2'" . PHP_EOL; echo "div: shows result of 'value1 / value2'" . PHP_EOL; echo "</pre>" . eol(); } // return TRUE if processing the procedure success. return TRUE; }
/** * process event * * @param Charcoal_IEventContext $context event context * * @return boolean */ public function processEvent($context) { $request = $context->getRequest(); // $response = $context->getResponse(); // $sequence = $context->getSequence(); // $procedure = $context->getProcedure(); // get paramter from command line $target_module = $request->getString('p1'); if (strlen($target_module) === 0) { echo 'target_module is needed.' . PHP_EOL; echo 'charcoal [target_module] [param1] [param2]...' . PHP_EOL; return TRUE; } $context->loadModule($target_module); // create shell_command event and push it into the event queue /** @var Charcoal_IEvent $event */ $event = $context->createEvent('shell_command'); $context->pushEvent($event); return b(true); }
/** * イベントを処理する * * @param Charcoal_IEventContext $context * * @return boolean */ public function processEvent($context) { $request = $context->getRequest(); // パラメータを取得 $database = us($request->getString('p2')); $table = us($request->getString('p3')); $out_dir = us($request->getString('p4')); //======================================= // Confirm input parameters //======================================= if (!empty($database) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $database)) { print "Parameter 2(database name) is wrong: {$database}" . PHP_EOL; return b(true); } if (!empty($table) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $table)) { print "Parameter 3(table name) is wrong: {$table}" . PHP_EOL; return b(true); } if (!empty($table) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $table)) { print "Parameter 4(output directory path) is wrong: {$out_dir}" . PHP_EOL; return b(true); } //======================================= // output directory //======================================= if (empty($out_dir)) { $out_dir = getcwd() ? getcwd() : Charcoal_ResourceLocator::getFrameworkPath('tmp'); } //======================================= // Send new project event //======================================= /** @var Charcoal_IEvent $event */ $event_path = 'generate_model_event@:charcoal:db:generate:model'; $event = $context->createEvent($event_path, array($database, $table, $out_dir)); $context->pushEvent($event); return b(true); }
/** * process event * * @param Charcoal_IEventContext $context event context * * @return Charcoal_Boolean|bool */ public function processEvent($context) { $request = $context->getRequest(); // $response = $context->getResponse(); // $sequence = $context->getSequence(); // $procedure = $context->getProcedure(); echo PHP_EOL; echo "==========================================" . PHP_EOL; echo "CharcoalPHP Test Runner" . PHP_EOL; echo " Framework Version:" . Charcoal_Framework::getVersion() . PHP_EOL; echo "==========================================" . PHP_EOL; // get paramter from command line $scenario = $request->getString('scenario'); $scenario = trim($scenario); log_debug("debug,scenario", "scenario: {$scenario}"); if ($scenario === NULL) { echo "actions or scenario parameter must be specified." . PHP_EOL; log_error("debug,error,scenario", "actions or scenario parameter must be specified."); return TRUE; } $scenario_file = $this->scenario_dir . '/' . $scenario . '.scenario.ini'; if (!is_file($scenario_file)) { echo "scenario file not found: {$scenario_file}" . PHP_EOL; log_error("debug,error,scenario", "scenario file not found: {$scenario_file}"); return TRUE; } $scenario_data = parse_ini_file($scenario_file, TRUE); log_debug("debug,scenario", "scenario_data: " . print_r($scenario_data, true)); if (empty($scenario_data)) { echo "couldn't read scenario file: {$scenario_file}" . PHP_EOL; log_error("debug,error,scenario", "couldn't read scenario file: {$scenario_file}"); return TRUE; } foreach ($scenario_data as $section => $data) { $target = isset($data['target']) ? $data['target'] : NULL; $actions = isset($data['actions']) ? $data['actions'] : NULL; $enabled = isset($data['enabled']) ? $data['enabled'] : TRUE; log_debug("debug,scenario", "target: {$target}"); log_debug("debug,scenario", "actions: {$actions}"); log_debug("debug,scenario", "enabled: {$enabled}"); if (in_array(strtolower($enabled), array('0', 'false', 'no'))) { echo "section[{$section}] is DISABLED. will skip." . PHP_EOL; log_warning("debug, scenario", "section[{$section}] is DISABLED."); continue; } if (empty($target)) { echo "[WARNING] 'target' is not found at section[{$section}]" . PHP_EOL; log_warning("debug, scenario", "'target' is not found at section[{$section}]"); continue; } if (empty($actions)) { echo "[WARNING] 'actions' is not found at section[{$section}]" . PHP_EOL; log_warning("debug, scenario", "'actions' is not found at section[{$section}]"); continue; } $target_path = new Charcoal_ObjectPath($target); $module_path = '@' . $target_path->getVirtualPath(); $context->loadModule($module_path); log_info("debug,scenario", "loaded module: {$module_path}"); $event_args = array($section, $target, $actions); /** @var Charcoal_IEvent $event */ $event = $context->createEvent('test', $event_args); $context->pushEvent($event); log_debug("debug,scenario", "event_args: " . print_r($event_args, true)); log_debug("debug,scenario", "pushed event: " . print_r($event, true)); } // request fo test summary /** @var Charcoal_IEvent $event */ $event = $context->createEvent('test_summary'); $context->pushEvent($event); return TRUE; }