/** * Process events * * @param Charcoal_IEventContext $context event context * * @return boolean */ public function processEvent($context) { $version = Charcoal_Framework::getVersion()->toString(); $this_year = date('Y'); echo "CharcoalPHP {$version}." . PHP_EOL; echo "Copyright (c)2008-{$this_year} CharcoalPHP team." . PHP_EOL; return b(true); }
/** * Output HTML * */ public function output($e) { Charcoal_ParamTrait::validateException(1, $e); $out = ''; $version = Charcoal_Framework::getVersion(); $out .= "=============================================================" . PHP_EOL; $out .= "CharcoalPHP Ver.{$version}: Exception stack trace " . PHP_EOL; $out .= "=============================================================" . PHP_EOL; $out .= PHP_EOL; $out .= "* Exception Stack *" . PHP_EOL; $out .= "-------------------------------------------------------------" . PHP_EOL; $first_exception = $e; $no = 1; while ($e) { // get exception info $clazz = get_class($e); $file = $e->getFile(); $line = $e->getLine(); $message = $e->getMessage(); // print exception info $out .= "[{$no}]{$clazz}" . PHP_EOL; $out .= " {$file}({$line})" . PHP_EOL; $out .= " {$message}" . PHP_EOL; // move to previous exception $e = method_exists($e, 'getPreviousException') ? $e->getPreviousException() : NULL; $no++; if ($e) { $out .= PHP_EOL; } } // get backtrace if ($first_exception instanceof Charcoal_CharcoalException) { $backtrace = $first_exception->getBackTrace(); $out .= PHP_EOL; $out .= "* Call Stack *" . PHP_EOL; $out .= "-------------------------------------------------------------" . PHP_EOL; // print backtrace $call_no = 0; foreach ($backtrace as $element) { $klass = isset($element['class']) ? $element['class'] : ''; $func = isset($element['function']) ? $element['function'] : ''; $type = isset($element['type']) ? $element['type'] : ''; $file = isset($element['file']) ? $element['file'] : ''; $line = isset($element['line']) ? $element['line'] : ''; if ($call_no > 0) { $out .= PHP_EOL; } $out .= "[{$call_no}]{$klass}{$type}{$func}()" . PHP_EOL; $out .= " {$file}({$line})" . PHP_EOL; $call_no++; } } return $out; }
/** * Output HTML * */ public function output($e) { Charcoal_ParamTrait::validateException(1, $e); $out = ''; $version = Charcoal_Framework::getVersion(); $out .= "=============================================================" . self::LOG_EOL; $out .= "CharcoalPHP Ver.{$version}: Exception stack trace " . self::LOG_EOL; $out .= "=============================================================" . self::LOG_EOL; $out .= self::LOG_EOL; $out .= "* Exception Stack *" . self::LOG_EOL; $out .= "-------------------------------------------------------------" . self::LOG_EOL; $no = 1; while ($e) { // get exception info $clazz = get_class($e); $file = $e->getFile(); $line = $e->getLine(); $message = $e->getMessage(); $backtrace = $e instanceof Charcoal_CharcoalException ? $e->getBackTrace() : NULL; // print exception info $out .= "[{$no}]{$clazz}" . self::LOG_EOL; $out .= " {$file}({$line})" . self::LOG_EOL; $out .= " {$message}" . self::LOG_EOL; // move to previous exception $e = method_exists($e, 'getPreviousException') ? $e->getPreviousException() : NULL; $no++; if ($e) { $out .= self::LOG_EOL; } } if ($backtrace === NULL || !is_array($backtrace)) { return $out; } $out .= self::LOG_EOL; $out .= "* Call Stack *" . self::LOG_EOL; $out .= "-------------------------------------------------------------" . self::LOG_EOL; // print backtrace $call_no = 0; foreach ($backtrace as $element) { $klass = isset($element['class']) ? $element['class'] : ''; $func = isset($element['function']) ? $element['function'] : ''; $type = isset($element['type']) ? $element['type'] : ''; $args = isset($element['args']) ? $element['args'] : array(); $file = isset($element['file']) ? $element['file'] : ''; $line = isset($element['line']) ? $element['line'] : ''; $args_disp = ''; foreach ($args as $arg) { if (strlen($args_disp) > 0) { $args_disp .= ','; } $args_disp .= Charcoal_System::toString($arg); } if ($call_no > 0) { $out .= self::LOG_EOL; } $out .= "[{$call_no}]{$klass}{$type}{$func}({$args_disp})" . self::LOG_EOL; $out .= " {$file}({$line})" . self::LOG_EOL; $call_no++; } return $out; }
/** * 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; }
/** * Print HTML Body */ private static function _makeHtmlBody($e, $title, $file, $line) { $html = ''; $html .= '<div id="charcoal">' . PHP_EOL; $html .= '<h1><div class="value">' . $title . '</div></h1>' . PHP_EOL; // PHP info $phpinfo = array('PHP_VERSION' => PHP_VERSION, 'date_default_timezone' => date_default_timezone_get()); $html .= '<h2><div class="value">PHP Info <a href="#" onclick="expand(\'phpinfo\');">(' . count($phpinfo) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="phpinfo" style="display:none">' . PHP_EOL; $no = 1; foreach ($phpinfo as $name => $value) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // php.ini info $php_ini = ini_get_all(); $html .= '<h2><div class="value">php.ini <a href="#" onclick="expand(\'php_ini\');">(' . count($php_ini) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="php_ini" style="display:none">' . PHP_EOL; $no = 1; foreach ($php_ini as $key => $item) { $local_value = isset($item['local_value']) ? $item['local_value'] : NULL; $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="key"><span class="value">' . $key . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="value"><span class="value">' . $local_value . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // Framework info $frameworkinfo = array('CharcoalPHP ver.' => Charcoal_Framework::getVersion()); $html .= '<h2><div class="value">Framework Info <a href="#" onclick="expand(\'frameworkinfo\');">(' . count($phpinfo) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="frameworkinfo" style="display:none">' . PHP_EOL; $no = 1; foreach ($frameworkinfo as $name => $value) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // $_SERVER variables $html .= '<h2><div class="value">$_SERVER variables <a href="#" onclick="expand(\'servervariables\');">(' . count($_SERVER) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="servervariables" style="display:none">' . PHP_EOL; $no = 1; foreach ($_SERVER as $name => $value) { if (is_array($value)) { $value = print_r($value, true); } $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // $_COOKIE variables $html .= '<h2><div class="value">$_COOKIE variables <a href="#" onclick="expand(\'cookievariables\');">(' . count($_COOKIE) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="cookievariables" style="display:none">' . PHP_EOL; $no = 1; foreach ($_COOKIE as $name => $value) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // $_ENV variables $html .= '<h2><div class="value">$_ENV variables <a href="#" onclick="expand(\'envvariables\');">(' . count($_ENV) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="envvariables" style="display:none">' . PHP_EOL; $no = 1; foreach ($_ENV as $name => $value) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // $_SESSION variables if (isset($_SESSION)) { $html .= '<h2><div class="value">$_SESSION variables <a href="#" onclick="expand(\'sessionvariables\');">(' . count($_SESSION) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="sessionvariables" style="display:none">' . PHP_EOL; $no = 1; foreach ($_SESSION as $name => $value) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="value"><span class="value"><pre>' . print_r(unserialize($value), true) . '</pre></span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; } // output loaded extensions $loaded_extensions = get_loaded_extensions(); $html .= '<h2><div class="value">Loaded Extensions <a href="#" onclick="expand(\'loaded_extensions\');">(' . count($loaded_extensions) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="loaded_extensions" style="display:none">' . PHP_EOL; $no = 1; foreach ($loaded_extensions as $name => $value) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="title"><span class="value">' . $value . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // output defined constants $declared_constants = Charcoal_System::getUserDefinedConstants(); $html .= '<h2><div class="value">User Declared Constants <a href="#" onclick="expand(\'declared_constants\');">(' . count($declared_constants) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="declared_constants" style="display:none">' . PHP_EOL; $no = 1; foreach ($declared_constants as $name => $value) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // output defined interfaces $declared_interfaces = get_declared_interfaces(); $interfaces = NULL; foreach ($declared_interfaces as $interface) { $interfaces[] = $interface; } sort($interfaces); $html .= '<h2><div class="value">Declared Interfaces <a href="#" onclick="expand(\'declared_interfaces\');">(' . count($interfaces) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="declared_interfaces" style="display:none">' . PHP_EOL; $no = 1; foreach ($interfaces as $interface) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="title"><span class="value">' . $interface . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // output defined functions $defined_functions = get_defined_functions(); $functions = NULL; foreach ($defined_functions['internal'] as $function) { $functions[] = '[core]' . $function; } foreach ($defined_functions['user'] as $function) { $functions[] = '[user]' . $function; } sort($functions); $html .= '<h2><div class="value">Declared Functions <a href="#" onclick="expand(\'defined_functions\');">(' . count($functions) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="defined_functions" style="display:none">' . PHP_EOL; $no = 1; foreach ($functions as $function) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="title"><span class="value">' . $function . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // output defined classes $declared_klasses = get_declared_classes(); $klasses = NULL; foreach ($declared_klasses as $klass) { $klasses[] = $klass; } sort($klasses); $html .= '<h2><div class="value">Declared Classes <a href="#" onclick="expand(\'declared_classes\');">(' . count($klasses) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="declared_classes" style="display:none">' . PHP_EOL; $no = 1; foreach ($klasses as $klass) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="title"><span class="value">' . $klass . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // output loaded files $files = Charcoal_Framework::getLoadedSourceFiles(); $html .= '<h2><div class="value">Loaded Source Files <a href="#" onclick="expand(\'source_files\');">(' . count($files) . ')</a></div></h2>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0" id="source_files" style="display:none">' . PHP_EOL; $no = 1; foreach ($files as $file) { $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="title"><span class="value">' . $file . '</span></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $no++; } $html .= '</table>' . PHP_EOL; // output exception stack $html .= '<h2><div class="value">Exception Stack</div></h2>' . PHP_EOL; $hash = sha1($file . $line); $src = new Charcoal_PhpSourceInfo(s($file), i($line), i(10)); $html .= '<div style="text-align: left;">' . PHP_EOL; $html .= ' <span class="value">' . $file . '(' . $line . ')' . ' <a href="#" onclick="return expand(\'' . $hash . '\')">View Source</a></span>' . PHP_EOL; $html .= ' <div class="value" id="' . $hash . '" style="display:none">' . $src . '</div>' . PHP_EOL; $html .= '</div>' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0">' . PHP_EOL; $no = 1; $backtrace = NULL; while ($e) { $clazz = get_class($e); $file = $e->getFile(); $line = $e->getLine(); $message = $e->getMessage(); $backtrace = $e instanceof Charcoal_CharcoalException ? $e->getBackTrace() : NULL; $src = new Charcoal_PhpSourceInfo(s($file), i($line), i(10)); $hash = s($file)->hash() . i($line)->hash(); $src_id = "'src" . $no . "'"; $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="3">' . $no . '</th>' . PHP_EOL; $html .= ' <td class="title">' . PHP_EOL; $html .= ' <span class="value">class:' . $clazz . '</span>' . PHP_EOL; $html .= ' <span class="value">file:' . $file . '(' . $line . ')</span>' . PHP_EOL; $html .= ' </td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="message"><div class="value">' . $message . '</div></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="message"><div class="value"><a href="#" onclick="return expand(\'' . $hash . '\')">View Source</a></span></div>' . PHP_EOL; $html .= ' <div class="value" id="' . $hash . '" style="display:none">' . $src . '</div>' . PHP_EOL; $html .= ' </td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $e = method_exists($e, 'getPreviousException') ? $e->getPreviousException() : NULL; $no++; } $html .= '</table>' . PHP_EOL; if ($backtrace === NULL || !is_array($backtrace)) { return $html; } // output call stack $html .= '<h2><div class="value">Call Stack</div></h2>' . PHP_EOL; $html .= '<table cellspacing="0" cellpadding="0">' . PHP_EOL; $call_no = 1; foreach ($backtrace as $element) { $klass = isset($element['class']) ? $element['class'] : ''; $func = isset($element['function']) ? $element['function'] : ''; $type = isset($element['type']) ? $element['type'] : ''; $args = isset($element['args']) ? $element['args'] : array(); $file = isset($element['file']) ? $element['file'] : ''; $line = isset($element['line']) ? $element['line'] : 0; if ($type == "::") { $ref_method = new ReflectionMethod($klass, $func); $modifiers = Reflection::getModifierNames($ref_method->getModifiers()); $modifiers = implode(" ", $modifiers); $params = $ref_method->getParameters(); $args_defs = ''; foreach ($params as $p) { if (strlen($args_defs) > 0) { $args_defs .= ','; } if ($p->isOptional()) { $args_defs .= '['; } if ($p->isArray()) { $args_defs .= 'array '; } $args_defs .= $p->getClass(); if ($p->isPassedByReference()) { $args_defs .= '&'; } $args_defs .= $p->getName(); if ($p->isDefaultValueAvailable()) { $args_defs .= '=' . $p->getDefaultValue(); } if ($p->isOptional()) { $args_defs .= ']'; } } $args_disp = '<table>'; $args_disp .= '<tr>'; $args_disp .= ' <th>No</th>'; $args_disp .= ' <th>value</th>'; $args_disp .= '</tr>'; foreach ($args as $key => $arg) { $args_disp .= '<tr>'; $args_disp .= ' <td>' . $key . '</td>'; $args_disp .= ' <td>' . Charcoal_System::toString($arg) . '</td>'; $args_disp .= '</tr>'; } $args_disp .= '</table>'; $message = "{$modifiers} {$klass}{$type}{$func}({$args_defs})<br>{$args_disp}"; } else { $args_disp = ''; foreach ($args as $arg) { if (strlen($args_disp) > 0) { $args_disp .= ','; } $args_disp .= '"' . Charcoal_System::toString($arg) . '"'; } $message = "{$klass}{$type}{$func}({$args_disp})"; } $src = new Charcoal_PhpSourceInfo(s($file), i($line), i(10)); $hash = s($file)->hash() . i($line)->hash(); $src_id = "'src" . $call_no . "'"; $html .= '<tr>' . PHP_EOL; $html .= ' <th class="no" rowspan="3">' . $call_no . '</th>' . PHP_EOL; $html .= ' <td class="title">' . PHP_EOL; $html .= ' <span class="value">class:' . $klass . '</span>' . PHP_EOL; $html .= ' <span class="value">file:' . $file . '(' . $line . ')</span>' . PHP_EOL; $html .= ' <a name="' . $hash . '"></a>' . PHP_EOL; $html .= ' </td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="message"><div class="value">' . $message . '</div></td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $html .= '<tr>' . PHP_EOL; $html .= ' <td class="message"><div class="value"><a href="#" onclick="return expand(\'' . $hash . '\')">View Source</a></span></div>' . PHP_EOL; $html .= ' <div class="value" id="' . $hash . '" style="display:none">' . $src . '</div>' . PHP_EOL; $html .= ' </td>' . PHP_EOL; $html .= '</tr>' . PHP_EOL; $call_no++; } $html .= '</table>' . PHP_EOL; return $html; }
/** * Process core hook message */ public function processMessage($stage, $data) { $stage_name = parent::getCoreHookStageName($stage); switch ($stage) { case Charcoal_EnumCoreHookStage::START_OF_BOOTSTRAP: // starting message echo "[core stage:{$stage_name}] Starting framework bootstrap process." . eol(); echo "[core stage:{$stage_name}] ===============================================" . eol(); $ver = Charcoal_Framework::getVersion(); echo "[core stage:{$stage_name}] CharcoalPHP Framwrork version: {$ver}" . eol(); echo "[core stage:{$stage_name}] PHP version: " . PHP_VERSION . eol(); echo "[core stage:{$stage_name}] default_timezone: " . date_default_timezone_get() . eol(); echo "[core stage:{$stage_name}] ===============================================" . eol(); echo "[core stage:{$stage_name}] profile=[" . CHARCOAL_PROFILE . "]" . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_INIT_FRAMEWORK: echo "[core stage:{$stage_name}] Starting framework initialization process." . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_INIT_FRAMEWORK: echo "[core stage:{$stage_name}] Finished framework initialization process." . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_REG_CLASS_LOADERS: echo "[core stage:{$stage_name}] Starting registering class loaders." . eol(); break; case Charcoal_EnumCoreHookStage::CREATE_FRAMEWORK_CLASS_LOADER: echo "[core stage:{$stage_name}] Created framework class loader." . eol(); break; case Charcoal_EnumCoreHookStage::REG_FRAMEWORK_CLASS_LOADER: echo "[core stage:{$stage_name}] Registered framework class loader." . eol(); break; case Charcoal_EnumCoreHookStage::CREATE_CLASS_LOADER: echo "[core stage:{$stage_name}] Created class loader: [{$data}]" . eol(); break; case Charcoal_EnumCoreHookStage::REG_CLASS_LOADER: echo "[core stage:{$stage_name}] Registered class loader: [{$data}]" . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_REG_CLASS_LOADERS: echo "[core stage:{$stage_name}] Finished registering class loaders." . eol(); break; /* case Charcoal_EnumCoreHookStage::BEFORE_REG_EXCEPTION_HANDLERS: echo "[core stage:$stage_name] Starting registering exception handlers.". eol(); break; case Charcoal_EnumCoreHookStage::CREATE_EXCEPTION_HANDLER: echo "[core stage:$stage_name] Registered exception handler: [$data]". eol(); break; case Charcoal_EnumCoreHookStage::AFTER_REG_EXCEPTION_HANDLERS: echo "[core stage:$stage_name] Finished registering exception handlers.". eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_REG_USER_LOGGERS: echo "[core stage:$stage_name] Starting registering loggers.". eol(); break; case Charcoal_EnumCoreHookStage::CREATE_USER_LOGGER: echo "[core stage:$stage_name] Registered logger: [" . $data . "]"); break; case Charcoal_EnumCoreHookStage::AFTER_REG_USER_LOGGERS: echo "[core stage:$stage_name] Finished registering loggers.". eol(); break; */ /* case Charcoal_EnumCoreHookStage::BEFORE_REG_EXCEPTION_HANDLERS: echo "[core stage:$stage_name] Starting registering exception handlers.". eol(); break; case Charcoal_EnumCoreHookStage::CREATE_EXCEPTION_HANDLER: echo "[core stage:$stage_name] Registered exception handler: [$data]". eol(); break; case Charcoal_EnumCoreHookStage::AFTER_REG_EXCEPTION_HANDLERS: echo "[core stage:$stage_name] Finished registering exception handlers.". eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_REG_USER_LOGGERS: echo "[core stage:$stage_name] Starting registering loggers.". eol(); break; case Charcoal_EnumCoreHookStage::CREATE_USER_LOGGER: echo "[core stage:$stage_name] Registered logger: [" . $data . "]"); break; case Charcoal_EnumCoreHookStage::AFTER_REG_USER_LOGGERS: echo "[core stage:$stage_name] Finished registering loggers.". eol(); break; */ case Charcoal_EnumCoreHookStage::BEFORE_REG_EXTLIB_DIR: echo "[core stage:{$stage_name}] Starting registering external library paths." . eol(); break; case Charcoal_EnumCoreHookStage::ADD_EXTLIB_DIR: echo "[core stage:{$stage_name}] Registered external library path: [{$data}]" . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_REG_EXTLIB_DIR: echo "[core stage:{$stage_name}] Finished registering external library paths." . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_SET_SESSION_HANDLER: echo "[core stage:{$stage_name}] Starting registering session handlers." . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_SET_SESSION_HANDLER: echo "[core stage:{$stage_name}] Finished registering session handlers." . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_START_SESSION: echo "[core stage:{$stage_name}] Starting session." . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_START_SESSION: echo "[core stage:{$stage_name}] Session started." . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_ROUTING_RULE: echo "[core stage:{$stage_name}] Starting creating routing rules." . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_ROUTING_RULE: echo "[core stage:{$stage_name}] Finished creating routing rules." . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_ROUTER: echo "[core stage:{$stage_name}] Starting routing." . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_ROUTER: echo "[core stage:{$stage_name}] Finished routing." . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_CREATE_PROCEDURE: echo "[core stage:{$stage_name}] Creating procedure: [{$data}]" . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_CREATE_PROCEDURE: echo "[core stage:{$stage_name}] Created procedure: [{$data}]" . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_PROCEDURE_FORWARD: echo "[core stage:{$stage_name}] Starting procedure forwarding process." . eol(); break; case Charcoal_EnumCoreHookStage::PRE_PROCEDURE_FORWARD: echo "[core stage:{$stage_name}] Executing procedure forwarding." . eol(); break; case Charcoal_EnumCoreHookStage::POST_PROCEDURE_FORWARD: echo "[core stage:{$stage_name}] Executed procedure forwarding." . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_PROCEDURE_FORWARD: echo "[core stage:{$stage_name}] Finished procedure forwarding process." . eol(); break; case Charcoal_EnumCoreHookStage::END_OF_BOOTSTRAP: $elapse = Charcoal_Benchmark::score(); echo "[core stage:{$stage_name}] Finished framework bootstrap process." . eol(); echo "[core stage:{$stage_name}] bootstrap processing time: [{$elapse}] msec" . eol(); break; case Charcoal_EnumCoreHookStage::PRE_EXECUTE_PROCEDURE: $proc_stack = Charcoal_Framework::getProcedureStack(); echo "[core stage:{$stage_name}] Executing procedure: [{$data}]" . eol(); echo "[core stage:{$stage_name}] procedure stack: [ " . Charcoal_System::implodeArray(",", $proc_stack) . " ]" . eol(); break; case Charcoal_EnumCoreHookStage::POST_EXECUTE_PROCEDURE: echo "[core stage:{$stage_name}] Executed procedure: [{$data}]" . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_EXECUTE_PROCEDURES: echo "[core stage:{$stage_name}] Finished procedure executing process." . eol(); break; case Charcoal_EnumCoreHookStage::START_OF_SHUTDOWN: echo "[core stage:{$stage_name}] Started framework shutdown process." . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_SAVE_SESSION: echo "[core stage:{$stage_name}] Starting saving session data." . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_SAVE_SESSION: echo "[core stage:{$stage_name}] Finished saving session data." . eol(); break; case Charcoal_EnumCoreHookStage::BEFORE_DESTROY_CONTAINER: echo "[core stage:{$stage_name}] Starting destroying container." . eol(); break; case Charcoal_EnumCoreHookStage::AFTER_DESTROY_CONTAINER: echo "[core stage:{$stage_name}] Finished destroying container." . eol(); break; /* case Charcoal_EnumCoreHookStage::BEFORE_TERMINATE_LOGGERS: echo "[core stage:$stage_name] Starting terminating loggers."); break; case Charcoal_EnumCoreHookStage::AFTER_TERMINATE_LOGGERS: echo "[core stage:$stage_name] Finished terminating loggers."); break; */ /* case Charcoal_EnumCoreHookStage::BEFORE_TERMINATE_LOGGERS: echo "[core stage:$stage_name] Starting terminating loggers."); break; case Charcoal_EnumCoreHookStage::AFTER_TERMINATE_LOGGERS: echo "[core stage:$stage_name] Finished terminating loggers."); break; */ case Charcoal_EnumCoreHookStage::END_OF_SHUTDOWN: echo "[core stage:{$stage_name}] Finished framework shutdown process." . eol(); if ($this->getSandbox()->isDebug()) { $peak_usage = memory_get_peak_usage(FALSE); $real_usage = memory_get_peak_usage(TRUE); $unit_peak = Charcoal_System::formatByteSize($peak_usage, 5); $unit_real = Charcoal_System::formatByteSize($real_usage, 5); echo "[core stage:{$stage_name}] memory peak usage: [{$unit_peak}] bytes" . eol(); echo "[core stage:{$stage_name}] memory real usage: [{$unit_real}] bytes" . eol(); } break; } }
/** * generate table model file * * @param string $table_name * @param string $table_model_class_name * @param string $config_key * @param string $out_dir */ private function generateTableConfigFile($table_name, $table_model_class_name, $config_key, $out_dir) { $file_name = $config_key . ".table_model.ini"; $lines = NULL; $lines[] = ";==================================================================="; $lines[] = "; (Auto Generated File)"; $lines[] = "; {$file_name}"; $lines[] = "; "; $lines[] = "; this file is configuration file for the DB table: {$table_name}"; $lines[] = "; "; $lines[] = "; generated by CharcoalPHP ver." . Charcoal_Framework::getVersion(); $lines[] = ";==================================================================="; $lines[] = ""; $lines[] = "class_name = {$table_model_class_name}"; $outfile = new Charcoal_File($file_name, $out_dir); Charcoal_FileSystemUtil::outputFile($outfile, $lines); print "{$outfile} was successfully generated." . PHP_EOL; }
/** * イベントを処理する */ 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); }