public function writeln(Charcoal_LogMessage $msg) { // フォーマット $out = parent::formatMessage($msg) . PHP_EOL; // エンコーディング変換 $conv = Charcoal_EncodingConverter::fromString($this->getSandbox(), 'PHP', 'CLI'); $out = $conv->convert($out); // 画面出力 echo $out; }
public function writeln(Charcoal_String $level, Charcoal_String $message, Charcoal_String $file, Charcoal_Integer $line) { $level = $level->getValue(); $message = $message->getValue(); $file = $file->getValue(); $line = $line->getValue(); $window_id = $this->_window_id; if ($this->_window_open === FALSE) { $html_code = Profile::getString(s('HTML_CODE')); echo '<script language="JavaScript">' . PHP_EOL; echo "var w_{$window_id} = window.open('', {$window_id}, 'toolbar=no,scrollbars,width=600,height=650');" . PHP_EOL; echo "w_{$window_id}.document.writeln('<html><head>');" . PHP_EOL; echo "w_{$window_id}.document.writeln('<META http-equiv=\"Content-Type\" content=\"text/html; charset={$html_code}\">');" . PHP_EOL; echo "w_{$window_id}.document.writeln('<style type=\"text/css\">');" . PHP_EOL; echo "w_{$window_id}.document.writeln('* { font-family: Courier New; font-size: 8pt; }');" . PHP_EOL; echo "w_{$window_id}.document.writeln('td.b0 { background-color:#ffffff; }');" . PHP_EOL; echo "w_{$window_id}.document.writeln('td.b1 { background-color:#CFCFCF; }');" . PHP_EOL; echo "w_{$window_id}.document.writeln('th { border-bottom: #4169e1 3px solid; }');" . PHP_EOL; echo "w_{$window_id}.document.writeln('h2 { font-size: 14pt; font-weight: bold; }');" . PHP_EOL; echo "w_{$window_id}.document.writeln('</style>');" . PHP_EOL; echo "w_{$window_id}.document.writeln('</head><body>');" . PHP_EOL; echo "w_{$window_id}.document.writeln('<table border=0 cellspacing=0>');" . PHP_EOL; echo "w_{$window_id}.document.writeln('<tr><th>Date</th><th>Level</th><th>Message</th><th>File</th><th>Line</th></tr>');" . PHP_EOL; echo "</script>" . PHP_EOL; $this->_window_open = TRUE; } $time = date("y/m/d H:i:s"); $file = basename($file); // 変数展開(PHP5.2.0以前との互換のため) $message = System::toString($message); // エンコーディング変換 $conv = Charcoal_EncodingConverter::fromString($this->getSandbox(), 'PHP', 'HTML'); $message = $conv->convertEncoding(s($message)); // ¥を/に変換 $message = str_replace('\\', '/', $message); // 画面出力 $message = h($message); $clazz = 'b' . $this->_line % 2; $msg = '<tr>'; $msg .= '<td class="' . $clazz . '">' . $time . '</td>'; $msg .= '<td class="' . $clazz . '" style="text-align:center">' . $level . '</td>'; $msg .= '<td class="' . $clazz . '">' . $message . '</td>'; $msg .= '<td class="' . $clazz . '">' . $file . '</td>'; $msg .= '<td class="' . $clazz . '">' . $line . '</td>'; $msg .= '</tr>'; echo '<script language="JavaScript">' . PHP_EOL; echo "w_{$window_id}.document.writeln('{$msg}');" . PHP_EOL; echo '</script>' . PHP_EOL; $this->_line++; }
private function _prepareExecute(Charcoal_String $sql, Charcoal_Vector $params = NULL) { $timer_handle = Charcoal_Benchmark::start(); $flag = new Charcoal_ErrorReportingSwitcher(0, E_DEPRECATED); $sql = $sql->getValue(); //print "SQL:$sql start<BR>"; $conv = Charcoal_EncodingConverter::fromString($this->getSandbox(), 'DB', 'PHP'); $log_params = $conv->convertArray(v($params)); $log_message = "[SQL]" . $sql . ($params ? " [params]" . implode(",", $log_params) : ''); log_debug("sql,debug", $log_message); //print "SQL:$sql<BR>"; /* for( $i=0; $i<count($params); $i++ ){ $p1 = $params[$i]; if ( is_string($p1) ){ $params[$i] = $p1; } } */ $stmt = $this->_connection->prepareExecute($sql); if (DB::isError($stmt)) { $msg = $stmt->getMessage() . "(" . $stmt->getCode() . ")"; log_error("system", $msg); log_error("sql,debug", "...FAILED: {$msg}"); _throw(new Charcoal_DBDataSourceException($msg)); } $params = $params ? $params->toArray() : array(); $result = $this->_connection->execute($stmt, $params); if (DB::isError($result)) { $msg = $result->getMessage(); log_error("system", $msg); log_error("sql,debug", "...FAILED: {$msg}"); _throw(new Charcoal_DBDataSourceException($msg)); } if (is_object($result)) { $numRows = $result->numRows(); log_debug("sql,debug", "...success(numRows={$numRows})"); } else { $numRows = null; log_debug("sql,debug", "...success({$result})"); } // ログ $elapse = Charcoal_Benchmark::stop($timer_handle); log_debug('sql,debug', "prepareExecute() end. time=[{$elapse}]sec."); return $result; }
/** * 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); }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $this->log_format = $config->getString('log_format', self::DEFAULT_LOG_FORMAT); $this->converter = Charcoal_EncodingConverter::fromString($this->getSandbox(), 'PHP', 'LOG'); }
/** * generate table model file * * @param string $table_name * @param array $colmn_attr_list * @param string $table_model_class_name * @param string $table_dto_class_name * @param string $out_dir */ private function generateTableModelFile($table_name, $colmn_attr_list, $table_model_class_name, $table_dto_class_name, $out_dir) { $lines = NULL; $lines[] = "<?php"; $lines[] = "/**"; $lines[] = " * (Auto Generated Class)"; $lines[] = " * {$table_model_class_name} class"; $lines[] = " * "; $lines[] = " * this is a table mondel class for the DB table: {$table_name}"; $lines[] = " * "; $lines[] = " * generated by CharcoalPHP ver." . Charcoal_Framework::getVersion(); $lines[] = " */"; $lines[] = "class {$table_model_class_name} extends Charcoal_DefaultTableModel"; $lines[] = "{"; $lines[] = " public \$___table_name = '{$table_name}';"; $lines[] = ""; $conv = Charcoal_EncodingConverter::fromString($this->getSandbox(), 'DB', 'PHP'); 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']; $spaces = str_repeat(" ", self::SPACE_COUNT - strlen($field)); // make field spec $fieldspec = array('@field', '@type:' . $type); $is_nullable = strtolower($null) == 'yes' ? true : false; $has_default = strlen($default) !== 0 ? true : false; $is_primary_key = strtolower($key) == "pri" ? true : false; $is_auto_increment = strtolower($extra) == 'auto_increment' ? true : false; $is_created_date = strtolower($field) == 'created_date' ? true : false; $is_modified_date = strtolower($field) == 'modified_date' ? true : false; if (!$is_nullable) { $fieldspec[] = '@notnull'; } if ($has_default) { $fieldspec[] = '@default:' . $default; } if ($is_auto_increment) { $fieldspec[] = '@serial'; } if ($is_primary_key) { $fieldspec[] = '@pk'; $fieldspec[] = '@insert:' . ($is_auto_increment ? 'no' : 'value'); $fieldspec[] = '@update:no'; } elseif ($is_created_date) { $fieldspec[] = '@insert:function[now]'; $fieldspec[] = '@update:no'; } elseif ($is_modified_date) { $fieldspec[] = '@insert:function[now]'; $fieldspec[] = '@update:function[now]'; } else { $fieldspec[] = '@insert:value'; $fieldspec[] = '@update:value'; } if (!empty($comment)) { $fieldspec[] = '@comment:' . $conv->convert($comment); } // make line $line = " public \${$field}{$spaces}= '" . implode(' ', $fieldspec) . "';"; $lines[] = $line; } $lines[] = ""; $lines[] = " /**"; $lines[] = " * returns new DTO"; $lines[] = " * "; $lines[] = " * @param array \$values"; $lines[] = " * "; $lines[] = " * @return {$table_dto_class_name}"; $lines[] = " */"; $lines[] = " public function createDTO( \$values = array() )"; $lines[] = " {"; $lines[] = " return new {$table_dto_class_name}( \$values );"; $lines[] = " }"; $lines[] = "}"; $file_name = $table_model_class_name . ".class.php"; $outfile = new Charcoal_File($file_name, $out_dir); Charcoal_FileSystemUtil::outputFile($outfile, $lines); print "{$outfile} was successfully generated." . PHP_EOL; }