/** * process event * * @param Charcoal_IEventContext $context * * @return boolean|Charcoal_Boolean */ public function processEvent($context) { /** @var GenerateModelEvent $event */ $event = $context->getEvent(); // get event parameters $db_name = $event->getDatabase(); /** @var Charcoal_SmartGateway $gw */ $gw = $context->getComponent('smart_gateway@:charcoal:db'); // find models in project/app path $find_path = Charcoal_EnumFindPath::FIND_PATH_PROJECT | Charcoal_EnumFindPath::FIND_PATH_APPLICATION; $models = $gw->listModels($find_path); // switch database $gw->selectDatabase($db_name); // create tables foreach ($models as $model_name => $model) { $table = $model->getTableName(); echo "creating table: [TABLE NAME]{$table} [MODEL NAME]{$model_name}\n"; $rows_affected = $gw->createTable(null, $model_name, true); if ($rows_affected) { echo "successfully created table[{$table}].\n"; } else { echo "failed to create table[{$table}].\n"; } } 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(); $event = $context->getEvent(); if ($event instanceof Charcoal_TestResultEvent) { /** @var Charcoal_TestResultEvent $event */ $section = $event->getSection(); $action = $event->getAction(); $result = $event->getSuccess(); $this->assertions++; if (!$result) { $this->failures++; } if (!isset($this->section_map[$section])) { $this->section_map[$section] = array(array(), 0, 0); } list($tests, $assertions, $failures) = $this->section_map[$section]; $assertions++; if (!$result) { $failures++; } if (!in_array($action, $tests)) { $tests[] = $action; $this->tests++; } $this->section_map[$section] = array($tests, $assertions, $failures); } else { if ($event instanceof Charcoal_TestSummaryEvent) { if (!$context->getEventQueue()->isEmpty()) { // 他にイベントが残っている場合は処理しない return FALSE; } echo PHP_EOL; echo "==========================================" . PHP_EOL; echo "Test Result Summary" . PHP_EOL; echo " --------------------------------------- " . PHP_EOL; echo " Tests/Assertions/Failures by section:" . PHP_EOL . PHP_EOL; foreach ($this->section_map as $section => $map) { list($tests, $assertions, $failures) = $map; echo " [{$section}] " . count($tests) . " / {$assertions} / {$failures}" . PHP_EOL; } echo " --------------------------------------- " . PHP_EOL; echo " Total:" . PHP_EOL . PHP_EOL; echo " Tests: " . $this->tests . PHP_EOL; echo " Assertions: " . $this->assertions . PHP_EOL; echo " Failures: " . $this->failures . PHP_EOL; echo "==========================================" . PHP_EOL; } } return TRUE; }
/** * process event * * @param Charcoal_IEventContext $context * * @return boolean|Charcoal_Boolean */ public function processEvent($context) { /** @var GenerateModelEvent $event */ $event = $context->getEvent(); // get event parameters $db_name = $event->getDatabase(); $table_name = $event->getTable(); $out_dir = $event->getTargetDir(); $entity = Charcoal_System::pascalCase($table_name); $config_key = Charcoal_System::snakeCase($table_name); $table_model_class_name = "{$entity}TableModel"; $table_dto_class_name = "{$entity}TableDTO"; $listing_dto_class_name = "{$entity}ListingDTO"; /** @var Charcoal_SmartGateway $gw */ $gw = $context->getComponent('smart_gateway@:charcoal:db'); //======================================= // Mmake output directory //======================================= $out_dir = $this->prepareOutputDirectory($out_dir); //======================================= // confirm if the table exists //======================================= $sql = "SELECT count(*) FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? "; $params = array($table_name, $db_name); $count = $gw->queryValue(NULL, $sql, $params); if ($count < 1) { print "[ERROR] Specified table '{$table_name}' does not exist in schema: '{$db_name}'. Please check your database settings." . PHP_EOL; return b(true); } //======================================= // Retrieve column information //======================================= $sql = "SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_KEY, COLUMN_DEFAULT, EXTRA, COLUMN_COMMENT "; $sql .= " FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? "; $params = array($table_name, $db_name); $colmn_attr_list = $gw->query(NULL, $sql, $params); //======================================= // Genarate table model file //======================================= $this->generateTableModelFile($table_name, $colmn_attr_list, $table_model_class_name, $table_dto_class_name, $out_dir); //======================================= // Genarate table DTO file //======================================= $this->generateTableDtolFile($table_name, $colmn_attr_list, $table_dto_class_name, $out_dir); //======================================= // Genarate listing DTO file //======================================= $this->generateListingDtolFile($table_name, $colmn_attr_list, $listing_dto_class_name, $out_dir); //======================================= // Genarate config file //======================================= $this->generateTableConfigFile($table_name, $table_model_class_name, $config_key, $out_dir); 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 events * * @param Charcoal_IEventContext $context event context * * @return boolean */ public function processEvent($context) { log_debug("smarty", "smarty=" . spl_object_hash($this->smarty), self::TAG); /** @var Charcoal_RenderLayoutEvent $event */ $event = $context->getEvent(); /** @var Charcoal_HttpResponse $response */ $response = $context->getResponse(); $sequence = $context->getSequence(); // output response headers // $response->flushHeaders(); // retrieve layout $layout = $event->getLayout(); log_debug("smarty", "Rendering by smarty. Layout:" . print_r($layout, true), self::TAG); log_debug("smarty", "caching=" . print_r($this->smarty->caching, true), self::TAG); log_debug("smarty", "template_dir=" . print_r($this->smarty->template_dir, true), self::TAG); log_debug("smarty", "compile_dir=" . print_r($this->smarty->compile_dir, true), self::TAG); log_debug("smarty", "config_dir=" . print_r($this->smarty->config_dir, true), self::TAG); log_debug("smarty", "cache_dir=" . print_r($this->smarty->cache_dir, true), self::TAG); log_debug("smarty", "plugins_dir=" . print_r($this->smarty->plugins_dir, true), self::TAG); $error_handler_old = NULL; try { $charcoal = array(); // page redirection if ($layout instanceof Charcoal_IRedirectLayout) { $url = $layout->makeRedirectURL(); $response->redirect(s($url)); log_debug("system, debug, smarty, redirect", "redirected to URL: {$url}", self::TAG); } elseif ($event instanceof Charcoal_URLRedirectEvent) { /** @var Charcoal_URLRedirectEvent $event */ $url = $event->getURL(); $response->redirect(s($url)); log_debug("system, debug, smarty, redirect", "redirected to URL: {$url}", self::TAG); } elseif ($event instanceof Charcoal_RenderLayoutEvent) { // Page information $page_info = $layout->getAttribute(s('page_info')); log_debug("smarty", "page_info=" . print_r($page_info, true), self::TAG); // Profile information $profile_config = $this->getSandbox()->getProfile()->getAll(); if ($profile_config && is_array($profile_config)) { foreach ($profile_config as $key => $value) { $charcoal['profile'][$key] = $value; } } // Cookie information if ($response instanceof Charcoal_HttpResponse) { $cookies = $response->getCookies(); if ($cookies && is_array($cookies)) { foreach ($cookies as $key => $value) { $charcoal['cookie'][$key] = $value; } } } $smarty = $this->smarty; // Assign variables if ($page_info && is_array($page_info)) { foreach ($page_info as $key => $value) { $smarty->assign($key, $value); } } // Sequence data $charcoal['sequence'] = $sequence; // Request ID and reauest path $charcoal['request']['id'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_ID%'); $charcoal['request']['path'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_PATH%'); // Assign all $smarty->assign('charcoal', $charcoal); // Assign all layout values $layout_values = $event->getValues(); if (!$layout_values) { // If layout values are not set, response values will be used instead. $layout_values = $response->getAll(); } foreach ($layout_values as $key => $value) { $smarty->assign($key, $value); } $smarty->assign('_smarty', $smarty); // render template $template = $layout->getAttribute(s('layout')); // set smarty error_reporting flags $this->smarty->error_reporting = E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE & ~8192; // rewrite error handler $error_handler_old = set_error_handler(array($this, "onUnhandledError")); // compile and output template log_debug("smarty", "template={$template}", self::TAG); $html = $smarty->fetch($template); log_debug("smarty", "html={$html}", self::TAG); // output to rendering target $render_target = $event->getRenderTarget(); if ($render_target) { $render_target->render($html); log_debug("smarty", "Rendered by render target: {$render_target}", self::TAG); } else { echo $html; log_debug("smarty", "Output by echo.", self::TAG); } } } catch (Exception $ex) { _catch($ex); _throw(new Charcoal_SmartyRendererTaskException("rendering failed", $ex)); } if ($error_handler_old) { set_error_handler($error_handler_old); } return b(TRUE); }
/** * Process events * * @param Charcoal_IEventContext $context event context * * @return Charcoal_Boolean|bool */ public function processEvent($context) { $this->context = $context; /** @var Charcoal_TestEvent $event */ $event = $context->getEvent(); $is_debug = $context->isDebug(); // パラメータを取得 $section = $event->getSection(); $target = $event->getTarget(); $actions = $event->getActions(); $this->section = $section; if ($is_debug) { log_debug("debug,event", "event section: {$section}"); } if ($is_debug) { log_debug("debug,event", "event target: {$target}"); } if ($is_debug) { log_debug("debug,event", "event actions: {$actions}"); } if ($is_debug) { log_debug("debug,event", "this object path: " . $this->getObjectPath()); } if ($target != $this->getObjectPath()) { if ($is_debug) { log_debug("debug,event", "not target: " . $event); } return FALSE; } if ($is_debug) { log_debug("debug,event", "target: " . $event); } $actions = explode(',', $actions); // アクションに対するテストが記述されているか確認する $total_actions = 0; if ($actions) { foreach ($actions as $action) { $action = trim($action); if (strlen($action) === 0) { continue; } if ($this->isValidAction($action)) { $total_actions++; } } } if ($total_actions === 0) { return TRUE; } // テスト実行 $this->tests = 0; $this->asserts = 0; $this->failures = 0; echo PHP_EOL . "===================================================" . PHP_EOL; echo "Section[{$section}](total actions:{$total_actions})" . PHP_EOL . PHP_EOL; foreach ($actions as $action) { $action = trim($action); if (strlen($action) === 0) { continue; } $this->action = $action; if (!$this->isValidAction($action)) { continue; } //echo "-------------------------------------" . PHP_EOL; echo "Doing action: [{$action}] ..." . PHP_EOL; try { $this->setUp($action, $context); } catch (Exception $e) { echo "Test execution failed while setup:" . $e . PHP_EOL; return TRUE; } try { $tested = $this->test($action, $context); if ($tested) { $this->tests++; } } catch (Exception $e) { echo "[Info]Caught exception:" . get_class($e) . PHP_EOL; if ($this->expected_exception) { if ($this->expected_exception != get_class($e)) { $expected = $this->expected_exception; $actual = get_class($e); $this->message2(get_class($e), "Expected", "Actual", $expected, $actual); } } else { echo "[Warning]Test execution failed while test:" . $e . PHP_EOL; } } try { $this->cleanUp($action, $context); } catch (Exception $e) { echo "Test execution failed while clean up:" . $e . PHP_EOL; return TRUE; } echo "Action finished: [{$action}]" . PHP_EOL . PHP_EOL; } // 終了メッセージ if ($this->tests > 0) { echo "Tests complete! : [{$section}]" . PHP_EOL . PHP_EOL; echo "Tests: {$this->tests} Assertions: {$this->asserts} Failures: {$this->failures}" . PHP_EOL; } else { echo "No tests were processed." . PHP_EOL; } echo "===================================================" . PHP_EOL . PHP_EOL; return TRUE; }
/** * Process events * * @param Charcoal_IEventContext $context event context */ public function processEvent($context) { $event = $context->getEvent(); $response = $context->getResponse(); $sequence = $context->getSequence(); // output response headers $response->flushHeaders(); // retrieve layout $layout = $event->getLayout(); // log_info( "system,renderer", "Rendering by smarty. Layout:" . print_r($layout,true) ); try { $charcoal = array(); // page redirection if ($layout instanceof Charcoal_IRedirectLayout) { $url = $layout->makeRedirectURL(); $response->redirect(s($url)); // log_info( "system,renderer", "renderer", "Redirected to: $url" ); } elseif ($event instanceof Charcoal_URLRedirectEvent) { $url = $event->getURL(); $response->redirect(s($url)); // log_info( "system,renderer", "renderer", "Redirected to: $url" ); } else { // Page information $page_info = $layout->getAttribute(s('page_info')); // Profile information $profile_config = Charcoal_Profile::getConfig(); if ($profile_config && is_array($profile_config)) { foreach ($profile_config as $key => $value) { $charcoal['profile'][$key] = $value; } } // Cookie information $cookies = $response->getCookies(); if ($cookies && is_array($cookies)) { foreach ($cookies as $key => $value) { $charcoal['cookie'][$key] = $value; } } // Assign variables if ($page_info && is_array($page_info)) { foreach ($page_info as $key => $value) { ${$key} = $value; } } // Sequence data $charcoal['sequence'] = $sequence; // Request ID and reauest path $charcoal['request']['id'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_ID%'); $charcoal['request']['path'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_PATH%'); // Assign all //$charcoal = $charcoal; // Assign all response values $keys = $response->getKeys(); foreach ($keys as $key) { $value = $response->get(s($key)); $smarty->assign($key, $value); } // render template $template = $layout->getAttribute(s('layout')); // log_info( "smarty", "template=$template" ); $html = $smarty->fetch($template); // log_info( "smarty", "html=$html" ); echo $html; } } catch (Exception $ex) { _catch($ex); _throw(new Charcoal_SmartyRendererTaskException("rendering failed", $ex)); } return b(TRUE); }
/** * process event * * @param Charcoal_IEventContext $context * * @return boolean|Charcoal_Boolean */ public function processEvent($context) { /** @var ShowTableEvent $event */ $event = $context->getEvent(); // get event parameters $db_name = $event->getDatabase(); $table_name = $event->getTable(); /** @var Charcoal_SmartGateway $gw */ $gw = $context->getComponent('smart_gateway@:charcoal:db'); //======================================= // confirm if the table exists //======================================= $sql = "SELECT count(*) FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? "; $params = array($table_name, $db_name); $count = $gw->queryValue(NULL, $sql, $params); if ($count < 1) { print "[ERROR] Specified table '{$table_name}' does not exist in schema: '{$db_name}'. Maybe table name is wrong?" . PHP_EOL; return b(true); } print "Showing table information." . PHP_EOL . PHP_EOL; print "=========================================" . PHP_EOL; print "Table description: {$table_name}" . PHP_EOL . PHP_EOL; //======================================= // Retrieve column information //======================================= $sql = "SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_KEY, COLUMN_DEFAULT, EXTRA, COLUMN_COMMENT "; $sql .= " FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? "; $params = array($table_name, $db_name); $colmn_attr_list = $gw->query(NULL, $sql, $params); // get max length $field_max_width = $this->getMaxLengthOfMeta($colmn_attr_list, 'COLUMN_NAME', 'Field Name'); $type_max_width = $this->getMaxLengthOfMeta($colmn_attr_list, 'COLUMN_TYPE', 'Type'); $null_max_width = $this->getMaxLengthOfMeta($colmn_attr_list, 'IS_NULLABLE', 'Null'); $key_max_width = $this->getMaxLengthOfMeta($colmn_attr_list, 'COLUMN_KEY', 'Key'); $default_max_width = $this->getMaxLengthOfMeta($colmn_attr_list, 'COLUMN_DEFAULT', 'Default'); $extra_max_width = $this->getMaxLengthOfMeta($colmn_attr_list, 'EXTRA', 'Extra'); $comment_max_width = $this->getMaxLengthOfMeta($colmn_attr_list, 'COLUMN_COMMENT', 'Comment'); print "null_max_width: {$null_max_width}\n"; print "key_max_width: {$key_max_width}\n"; print str_pad("Field Name", $field_max_width + 1) . " "; print str_pad("Type", $type_max_width + 1) . " "; print str_pad("Null", $null_max_width + 1) . " "; print str_pad("Key", $key_max_width + 1) . " "; print str_pad("Default", $default_max_width + 1) . " "; print str_pad("Extra", $extra_max_width + 1) . " "; print str_pad("Comment", $comment_max_width + 1) . PHP_EOL; $line_width = $field_max_width + $type_max_width + $null_max_width + $key_max_width + $default_max_width + $extra_max_width + $comment_max_width + 15; print str_repeat("-", $line_width) . PHP_EOL; $conv = Charcoal_EncodingConverter::fromString($this->getSandbox(), 'DB', 'CLI'); foreach ($colmn_attr_list as $colmn_attr) { $field = $colmn_attr['COLUMN_NAME']; $type = $colmn_attr['COLUMN_TYPE']; $null = $colmn_attr['IS_NULLABLE']; $key = $colmn_attr['COLUMN_KEY']; $default = $colmn_attr['COLUMN_DEFAULT']; $extra = $colmn_attr['EXTRA']; $comment = $colmn_attr['COLUMN_COMMENT']; $comment = $conv->convert($comment); $field = str_pad($field, $field_max_width + 1); $type = str_pad($type, $type_max_width + 1); $null = str_pad($null, $null_max_width + 1); $key = str_pad($key, $key_max_width + 1); $default = str_pad($default, $default_max_width + 1); $extra = str_pad($extra, $extra_max_width + 1); $comment = str_pad($comment, $comment_max_width + 1); print "{$field} {$type} {$null} {$key} {$default} {$extra} {$comment}" . PHP_EOL; } print PHP_EOL . "Done." . PHP_EOL; return b(true); }