HTMLを綺麗に、色んなテスト関係関数の修正
This commit is contained in:
@@ -56,7 +56,7 @@ $[audio/ogg](https://ass.technicalsuwako.moe/砕月着信音.ogg)\
|
|||||||
##### ケロケロ
|
##### ケロケロ
|
||||||
[076スタジオ合同会社](https://076.moe/)\
|
[076スタジオ合同会社](https://076.moe/)\
|
||||||
<諏訪子>(すわこ)\
|
<諏訪子>(すわこ)\
|
||||||
`int i = 0;`\
|
`int i = 0;`
|
||||||
|
|
||||||
###### ケロケロ
|
###### ケロケロ
|
||||||
1. アセンブリ言語
|
1. アセンブリ言語
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class DiffViewer {
|
|||||||
// 各ファイルにHTMLの出力の作成
|
// 各ファイルにHTMLの出力の作成
|
||||||
$html = '';
|
$html = '';
|
||||||
foreach ($fileDiffs as $fileName => $diff) {
|
foreach ($fileDiffs as $fileName => $diff) {
|
||||||
$html .= "<h2>ファイル: ".htmlspecialchars($fileName)."</h2>\n";
|
$html .= "\n <h2>ファイル: ".htmlspecialchars($fileName)."</h2>\n";
|
||||||
$html .= $this->generateHtml($diff['leftLines'], $diff['rightLines']);
|
$html .= $this->generateHtml($diff['leftLines'], $diff['rightLines']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,25 +106,25 @@ class DiffViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function generateHtml(array $leftLines, array $rightLines): string {
|
private function generateHtml(array $leftLines, array $rightLines): string {
|
||||||
$html = '<table class="diff-table">';
|
$html = " <p>\n <table class=\"diff-table\">\n";
|
||||||
$html .= '<tr class="diff-header"><th colspan="2">前</th><th colspan="2">新</th></tr>';
|
$html .= " <tr class=\"diff-header\"><th colspan=\"2\">前</th><th colspan=\"2\">新</th></tr>\n";
|
||||||
|
|
||||||
$maxLines = max(count($leftLines), count($rightLines));
|
$maxLines = max(count($leftLines), count($rightLines));
|
||||||
for ($i = 0; $i < $maxLines; $i++) {
|
for ($i = 0; $i < $maxLines; $i++) {
|
||||||
$left = isset($leftLines[$i]) ? $leftLines[$i] : ['content' => '', 'type' => 'empty', 'line' => ''];
|
$left = isset($leftLines[$i]) ? $leftLines[$i] : ['content' => '', 'type' => 'empty', 'line' => ''];
|
||||||
$right = isset($rightLines[$i]) ? $rightLines[$i] : ['content' => '', 'type' => 'empty', 'line' => ''];
|
$right = isset($rightLines[$i]) ? $rightLines[$i] : ['content' => '', 'type' => 'empty', 'line' => ''];
|
||||||
|
|
||||||
$html .= '<tr>';
|
$html .= " <tr>\n";
|
||||||
// 左(変更前)
|
// 左(変更前)
|
||||||
$html .= '<td class="line-number">' . ($left['line'] ?: ' ') . '</td>';
|
$html .= " <td class=\"line-number\">".($left['line'] ?: ' ')."</td>\n";
|
||||||
$html .= '<td class="' . $left['type'] . '">' . ($left['content'] ?: ' ') . '</td>';
|
$html .= " <td class=\"{$left['type']}\">".($left['content'] ?: ' ')."</td>\n";
|
||||||
// 右(変更後)
|
// 右(変更後)
|
||||||
$html .= '<td class="line-number">' . ($right['line'] ?: ' ') . '</td>';
|
$html .= " <td class=\"line-number\">".($right['line'] ?: ' ')."</td>\n";
|
||||||
$html .= '<td class="' . $right['type'] . '">' . ($right['content'] ?: ' ') . '</td>';
|
$html .= " <td class=\"{$right['type']}\">".($right['content'] ?: ' ')."</td>\n";
|
||||||
$html .= '</tr>';
|
$html .= " </tr>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= '</table>';
|
$html .= " </table>\n </p>\n";
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ class Markdown {
|
|||||||
if (preg_match('/^```(\w*)$/', $line, $matches)) {
|
if (preg_match('/^```(\w*)$/', $line, $matches)) {
|
||||||
if (!$this->inCodeBlock) {
|
if (!$this->inCodeBlock) {
|
||||||
if (!empty($currentParagraph)) {
|
if (!empty($currentParagraph)) {
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
$currentParagraph = [];
|
$currentParagraph = [];
|
||||||
}
|
}
|
||||||
$this->inCodeBlock = true;
|
$this->inCodeBlock = true;
|
||||||
@@ -121,7 +121,7 @@ class Markdown {
|
|||||||
// テーブルの処理
|
// テーブルの処理
|
||||||
if (preg_match('/^\|(.+)\|$/', $line)) {
|
if (preg_match('/^\|(.+)\|$/', $line)) {
|
||||||
if (!empty($currentParagraph)) {
|
if (!empty($currentParagraph)) {
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
$currentParagraph = [];
|
$currentParagraph = [];
|
||||||
}
|
}
|
||||||
$cells = array_map('trim', explode('|', trim($line, '|')));
|
$cells = array_map('trim', explode('|', trim($line, '|')));
|
||||||
@@ -145,17 +145,17 @@ class Markdown {
|
|||||||
// 水平線の処理
|
// 水平線の処理
|
||||||
if (preg_match('/^([\-\*\_])\1{2,}$/', $line)) {
|
if (preg_match('/^([\-\*\_])\1{2,}$/', $line)) {
|
||||||
if (!empty($currentParagraph)) {
|
if (!empty($currentParagraph)) {
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
$currentParagraph = [];
|
$currentParagraph = [];
|
||||||
}
|
}
|
||||||
$this->html[] = "<hr>";
|
$this->html[] = " <hr />\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 引用ブロックの処理
|
// 引用ブロックの処理
|
||||||
if (preg_match('/^>\s(.+)/', $line, $matches)) {
|
if (preg_match('/^>\s(.+)/', $line, $matches)) {
|
||||||
if (!empty($currentParagraph)) {
|
if (!empty($currentParagraph)) {
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
$currentParagraph = [];
|
$currentParagraph = [];
|
||||||
}
|
}
|
||||||
$inBlockquote = true;
|
$inBlockquote = true;
|
||||||
@@ -176,7 +176,7 @@ class Markdown {
|
|||||||
$inList = false;
|
$inList = false;
|
||||||
}
|
}
|
||||||
if (!empty($currentParagraph)) {
|
if (!empty($currentParagraph)) {
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
$currentParagraph = [];
|
$currentParagraph = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,19 +191,19 @@ class Markdown {
|
|||||||
$inList = false;
|
$inList = false;
|
||||||
}
|
}
|
||||||
if (!empty($currentParagraph)) {
|
if (!empty($currentParagraph)) {
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
$currentParagraph = [];
|
$currentParagraph = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$level = strlen($m[1]);
|
$level = strlen($m[1]);
|
||||||
$this->html[] = "<h{$level}>".$this->parseInline($m[2])."</h{$level}>";
|
$this->html[] = " <h{$level}>".$this->parseInline($m[2])."</h{$level}>";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 箇条書きリスト
|
// 箇条書きリスト
|
||||||
if (preg_match('/^(\s*)([\*\-])\s(.+)/', $line, $m)) {
|
if (preg_match('/^(\s*)([\*\-])\s(.+)/', $line, $m)) {
|
||||||
if (!empty($currentParagraph)) {
|
if (!empty($currentParagraph)) {
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
$currentParagraph = [];
|
$currentParagraph = [];
|
||||||
}
|
}
|
||||||
$inList = true;
|
$inList = true;
|
||||||
@@ -221,7 +221,7 @@ class Markdown {
|
|||||||
// 番号付きリスト
|
// 番号付きリスト
|
||||||
if (preg_match('/^(\s*)\d+\.\s(.+)/', $line, $m)) {
|
if (preg_match('/^(\s*)\d+\.\s(.+)/', $line, $m)) {
|
||||||
if (!empty($currentParagraph)) {
|
if (!empty($currentParagraph)) {
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
$currentParagraph = [];
|
$currentParagraph = [];
|
||||||
}
|
}
|
||||||
$inList = true;
|
$inList = true;
|
||||||
@@ -246,7 +246,7 @@ class Markdown {
|
|||||||
$parsedLine = $this->parseInline($line);
|
$parsedLine = $this->parseInline($line);
|
||||||
$currentParagraph[] = $parsedLine;
|
$currentParagraph[] = $parsedLine;
|
||||||
if ($hasBR) {
|
if ($hasBR) {
|
||||||
$currentParagraph[] = "<br />";
|
$currentParagraph[] = "<br />\n ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +254,7 @@ class Markdown {
|
|||||||
if ($inBlockquote) $this->html[] = $this->createBlockquote($blockquoteContent);
|
if ($inBlockquote) $this->html[] = $this->createBlockquote($blockquoteContent);
|
||||||
if ($inTable) $this->html[] = $this->createTable($tableHeaders, $tableRows);
|
if ($inTable) $this->html[] = $this->createTable($tableHeaders, $tableRows);
|
||||||
if (!empty($currentParagraph))
|
if (!empty($currentParagraph))
|
||||||
$this->html[] = " <p>".implode("", $currentParagraph)."</p>";
|
$this->html[] = " <p>\n ".implode("", $currentParagraph)."\n </p>";
|
||||||
|
|
||||||
return implode("\n", $this->html);
|
return implode("\n", $this->html);
|
||||||
}
|
}
|
||||||
@@ -456,11 +456,11 @@ class Markdown {
|
|||||||
$currentType = $item['type'];
|
$currentType = $item['type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= "<{$currentType}>\n";
|
$html .= " <p>\n <{$currentType}>\n";
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$html .= str_repeat(' ', $currentLevel)." <li>".$item['content']."</li>\n";
|
$html .= str_repeat(' ', $currentLevel)." <li>".$item['content']."</li>\n";
|
||||||
}
|
}
|
||||||
$html .= "</{$currentType}>";
|
$html .= " </{$currentType}>\n </p>";
|
||||||
|
|
||||||
while (!empty($listStack)) {
|
while (!empty($listStack)) {
|
||||||
$html .= str_repeat(' ', $currentLevel)."</".array_pop($listStack).">\n";
|
$html .= str_repeat(' ', $currentLevel)."</".array_pop($listStack).">\n";
|
||||||
@@ -478,7 +478,7 @@ class Markdown {
|
|||||||
private function createCodeBlock(): string {
|
private function createCodeBlock(): string {
|
||||||
$code = htmlspecialchars(implode("\n", $this->codeBlockContent));
|
$code = htmlspecialchars(implode("\n", $this->codeBlockContent));
|
||||||
$class = $this->codeBlockLanguage ? " class=\"language-{$this->codeBlockLanguage}\"" : '';
|
$class = $this->codeBlockLanguage ? " class=\"language-{$this->codeBlockLanguage}\"" : '';
|
||||||
return "<pre><code{$class}>{$code}</code></pre>";
|
return " <p>\n <pre><code{$class}>{$code}</code></pre>";
|
||||||
// $raw = implode("\n", $this->codeBlockContent);
|
// $raw = implode("\n", $this->codeBlockContent);
|
||||||
// $lang = $this->codeBlockLanguage ?: 'txt';
|
// $lang = $this->codeBlockLanguage ?: 'txt';
|
||||||
// $class = $lang === 'txt' ? '' : " class=\"language-{$lang}\"";
|
// $class = $lang === 'txt' ? '' : " class=\"language-{$lang}\"";
|
||||||
@@ -487,7 +487,7 @@ class Markdown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function createBlockquote(array $content): string {
|
private function createBlockquote(array $content): string {
|
||||||
return "<blockquote>\n <p>".implode("</p>\n <p>", $content)."</p>\n</blockquote>";
|
return " <p>\n <blockquote>\n ".implode("<br />\n ", $content)."\n </blockquote>\n </p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -498,31 +498,31 @@ class Markdown {
|
|||||||
* @return string HTMLのテーブル
|
* @return string HTMLのテーブル
|
||||||
*/
|
*/
|
||||||
private function createTable(array $headers, array $rows): string {
|
private function createTable(array $headers, array $rows): string {
|
||||||
$html = "<table>\n";
|
$html = " <p>\n <table>\n";
|
||||||
|
|
||||||
// ヘッダーを追加
|
// ヘッダーを追加
|
||||||
if (!empty($headers)) {
|
if (!empty($headers)) {
|
||||||
$html .= " <thead>\n <tr>\n";
|
$html .= " <thead>\n <tr>\n";
|
||||||
foreach ($headers as $header) {
|
foreach ($headers as $header) {
|
||||||
$html .= " <th>".$this->parseInline($header)."</th>\n";
|
$html .= " <th>".$this->parseInline($header)."</th>\n";
|
||||||
}
|
}
|
||||||
$html .= " </tr>\n </thead>\n";
|
$html .= " </tr>\n </thead>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 行を追加
|
// 行を追加
|
||||||
if (!empty($rows)) {
|
if (!empty($rows)) {
|
||||||
$html .= " <tbody>\n";
|
$html .= " <tbody>\n";
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$html .= " <tr>\n";
|
$html .= " <tr>\n";
|
||||||
foreach ($row as $cell) {
|
foreach ($row as $cell) {
|
||||||
$html .= " <td>".$this->parseInline($cell)."</td>\n";
|
$html .= " <td>".$this->parseInline($cell)."</td>\n";
|
||||||
}
|
}
|
||||||
$html .= " </tr>\n";
|
$html .= " </tr>\n";
|
||||||
}
|
}
|
||||||
$html .= " </tbody>\n";
|
$html .= " </tbody>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= "</table>";
|
$html .= " </table>\n </p>";
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class Mysql {
|
|||||||
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||||
if ($this->socket === false) {
|
if ($this->socket === false) {
|
||||||
$msg = 'ソケットの作成に失敗: '.socket_strerror(socket_last_error());
|
$msg = 'ソケットの作成に失敗: '.socket_strerror(socket_last_error());
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ class Mysql {
|
|||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
$msg = 'ソケットに接続に失敗: '
|
$msg = 'ソケットに接続に失敗: '
|
||||||
.socket_strerror(socket_last_error($this->socket));
|
.socket_strerror(socket_last_error($this->socket));
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ class Mysql {
|
|||||||
$code = unpack('v', substr($response, 1, 2))[1];
|
$code = unpack('v', substr($response, 1, 2))[1];
|
||||||
$mes = substr($response, 3);
|
$mes = substr($response, 3);
|
||||||
$msg = "認証応答に失敗: {$code} - {$mes}";
|
$msg = "認証応答に失敗: {$code} - {$mes}";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ class Mysql {
|
|||||||
$code = unpack('v', substr($res, 1, 2))[1];
|
$code = unpack('v', substr($res, 1, 2))[1];
|
||||||
$mes = substr($res, 3);
|
$mes = substr($res, 3);
|
||||||
$msg = "データベースの選択に失敗: {$code} - {$mes}";
|
$msg = "データベースの選択に失敗: {$code} - {$mes}";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ class Mysql {
|
|||||||
$code = unpack('v', substr($res, 1, 2))[1];
|
$code = unpack('v', substr($res, 1, 2))[1];
|
||||||
$mes = substr($res, 3);
|
$mes = substr($res, 3);
|
||||||
$msg = "準備に失敗: {$code} - {$mes}";
|
$msg = "準備に失敗: {$code} - {$mes}";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,14 +236,14 @@ class Mysql {
|
|||||||
|
|
||||||
if (!isset($this->prepared[$statementId])) {
|
if (!isset($this->prepared[$statementId])) {
|
||||||
$msg = "不正なステートメントID: {$statementId}";
|
$msg = "不正なステートメントID: {$statementId}";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmtInfo = $this->prepared[$statementId];
|
$stmtInfo = $this->prepared[$statementId];
|
||||||
if (count($params) != $stmtInfo['num_params']) {
|
if (count($params) != $stmtInfo['num_params']) {
|
||||||
$msg = "パラメータ数が一致しません: 期待 {$stmtInfo['num_params']}, 取得 ".count($params);
|
$msg = "パラメータ数が一致しません: 期待 {$stmtInfo['num_params']}, 取得 ".count($params);
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,7 +341,7 @@ class Mysql {
|
|||||||
$code = unpack('v', substr($res, 1, 2))[1];
|
$code = unpack('v', substr($res, 1, 2))[1];
|
||||||
$mes = substr($res, 3);
|
$mes = substr($res, 3);
|
||||||
$msg = "実行に失敗: {$code} - {$mes}";
|
$msg = "実行に失敗: {$code} - {$mes}";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +389,7 @@ class Mysql {
|
|||||||
$code = unpack('v', substr($res, 1, 2))[1];
|
$code = unpack('v', substr($res, 1, 2))[1];
|
||||||
$mes = substr($res, 3);
|
$mes = substr($res, 3);
|
||||||
$msg = "クエリに失敗: {$code} - {$mes}";
|
$msg = "クエリに失敗: {$code} - {$mes}";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +402,7 @@ class Mysql {
|
|||||||
// @todo LOCAL INFILEリクエストの処理を実装
|
// @todo LOCAL INFILEリクエストの処理を実装
|
||||||
if (ord($res[0]) === 0xFB) {
|
if (ord($res[0]) === 0xFB) {
|
||||||
$msg = "LOCAL INFOリクエストは未対応です";
|
$msg = "LOCAL INFOリクエストは未対応です";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,7 +490,7 @@ class Mysql {
|
|||||||
$mes = substr($res, 3);
|
$mes = substr($res, 3);
|
||||||
$this->close();
|
$this->close();
|
||||||
$msg = "認証に失敗: {$code} - {$mes}";
|
$msg = "認証に失敗: {$code} - {$mes}";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +518,7 @@ class Mysql {
|
|||||||
$eofPacket = $this->readPacket();
|
$eofPacket = $this->readPacket();
|
||||||
if (ord($eofPacket[0]) !== 0xFE) {
|
if (ord($eofPacket[0]) !== 0xFE) {
|
||||||
$msg = "フィールド説明の後にEOFパケットが期待されます";
|
$msg = "フィールド説明の後にEOFパケットが期待されます";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -664,7 +664,7 @@ class Mysql {
|
|||||||
private function parseOkPacket(string $packet): array {
|
private function parseOkPacket(string $packet): array {
|
||||||
if (strlen($packet) < 2) {
|
if (strlen($packet) < 2) {
|
||||||
$msg = "OKパケットが短すぎます: ".strlen($packet)."バイト";
|
$msg = "OKパケットが短すぎます: ".strlen($packet)."バイト";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,7 +678,7 @@ class Mysql {
|
|||||||
|
|
||||||
if (strlen($packet) < $pos + 2) {
|
if (strlen($packet) < $pos + 2) {
|
||||||
$msg = "OKパケットにサーバーステータス用のデータが不足しています";
|
$msg = "OKパケットにサーバーステータス用のデータが不足しています";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
$serverStatus = unpack('v', substr($packet, $pos, 2))[1];
|
$serverStatus = unpack('v', substr($packet, $pos, 2))[1];
|
||||||
@@ -686,7 +686,7 @@ class Mysql {
|
|||||||
|
|
||||||
if (strlen($packet) < $pos + 2) {
|
if (strlen($packet) < $pos + 2) {
|
||||||
$msg = "OKパケットに警告カウント用のデータが不足しています";
|
$msg = "OKパケットに警告カウント用のデータが不足しています";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
$warningCount = unpack('v', substr($packet, $pos, 2))[1];
|
$warningCount = unpack('v', substr($packet, $pos, 2))[1];
|
||||||
@@ -712,7 +712,7 @@ class Mysql {
|
|||||||
$bytesRead = socket_recv($this->socket, $header, 4, MSG_WAITALL);
|
$bytesRead = socket_recv($this->socket, $header, 4, MSG_WAITALL);
|
||||||
if ($bytesRead !== 4) {
|
if ($bytesRead !== 4) {
|
||||||
$msg = "パケットヘッダーの読み込みに失敗: 期待 4 バイト, 取得 {$bytesRead}";
|
$msg = "パケットヘッダーの読み込みに失敗: 期待 4 バイト, 取得 {$bytesRead}";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,7 +738,7 @@ class Mysql {
|
|||||||
if ($bytesRead === false) {
|
if ($bytesRead === false) {
|
||||||
$msg = "パケット内容の読み込みに失敗: エラー "
|
$msg = "パケット内容の読み込みに失敗: エラー "
|
||||||
.socket_strerror(socket_last_error($this->socket));
|
.socket_strerror(socket_last_error($this->socket));
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,7 +811,7 @@ class Mysql {
|
|||||||
$sent = socket_write($this->socket, $header, 4);
|
$sent = socket_write($this->socket, $header, 4);
|
||||||
if ($sent !== 4) {
|
if ($sent !== 4) {
|
||||||
$msg = "パケットヘッダーの送信に失敗";
|
$msg = "パケットヘッダーの送信に失敗";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -819,7 +819,7 @@ class Mysql {
|
|||||||
$sent = socket_write($this->socket, $data, $len);
|
$sent = socket_write($this->socket, $data, $len);
|
||||||
if ($sent !== $len) {
|
if ($sent !== $len) {
|
||||||
$msg = "パケットデータの送信に失敗";
|
$msg = "パケットデータの送信に失敗";
|
||||||
logger(\LogType::MySQL, $msg);
|
\logger(\LogType::MySQL, $msg);
|
||||||
throw new \Exception($msg);
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class Tester {
|
|||||||
private bool $colorOutput = true;
|
private bool $colorOutput = true;
|
||||||
private bool $verboseOutput = true;
|
private bool $verboseOutput = true;
|
||||||
private bool $stopOnFailure = false;
|
private bool $stopOnFailure = false;
|
||||||
|
private bool $skipCurrentDescribe = false;
|
||||||
private array $beforeEachCallbacks = [];
|
private array $beforeEachCallbacks = [];
|
||||||
private array $afterEachCallbacks = [];
|
private array $afterEachCallbacks = [];
|
||||||
private array $beforeAllCallbacks = [];
|
private array $beforeAllCallbacks = [];
|
||||||
@@ -119,6 +120,7 @@ class Tester {
|
|||||||
*/
|
*/
|
||||||
public function describe(string $description, callable $callback): Tester {
|
public function describe(string $description, callable $callback): Tester {
|
||||||
$this->currentTestCase = $description;
|
$this->currentTestCase = $description;
|
||||||
|
$this->skipCurrentDescribe = false;
|
||||||
$this->output($this->colorize('bold', "テストケース: {$description}"));
|
$this->output($this->colorize('bold', "テストケース: {$description}"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -149,6 +151,11 @@ class Tester {
|
|||||||
* @return Tester このインスタンス
|
* @return Tester このインスタンス
|
||||||
*/
|
*/
|
||||||
public function it(string $description, callable $callback): Tester {
|
public function it(string $description, callable $callback): Tester {
|
||||||
|
if ($this->skipCurrentDescribe) {
|
||||||
|
$this->skip($description, 'skipAll() が呼び出されました');
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
$this->currentTest = $description;
|
$this->currentTest = $description;
|
||||||
$this->testCount++;
|
$this->testCount++;
|
||||||
|
|
||||||
@@ -435,7 +442,42 @@ class Tester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a summary of the test results
|
* コレクションが指定された要素数を持つ事
|
||||||
|
*
|
||||||
|
* @param int $expoected 期待される要素数
|
||||||
|
* @param iterable $collection 配列または Traversable
|
||||||
|
* @param string|null $message 失敗時のカスタムメッセージ
|
||||||
|
* @return Tester
|
||||||
|
*
|
||||||
|
* @throws AssertionFailedException
|
||||||
|
*/
|
||||||
|
public function assertCount(int $expected, iterable $collection, ?string $message = null): Tester {
|
||||||
|
$actual = is_countable($collection) ? count($collection) : iterator_count($collection);
|
||||||
|
|
||||||
|
if ($actual !== $expected) {
|
||||||
|
$message ??= "要素数が {$expected} であることを期待しましたが、{$actual} でした";
|
||||||
|
throw new AssertionFailedException($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 現在の describe ブロック内の残りすべての it() をスキップ
|
||||||
|
*
|
||||||
|
* @param string $reason スキップ理由(出力に表示)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function skipAll(string $reason = 'このテストケースはスキップされました'): void {
|
||||||
|
$this->skipCurrentDescribe = true;
|
||||||
|
|
||||||
|
if ($this->verboseOutput) {
|
||||||
|
$this->output($this->colorize('cyan', " スキップAll: {$reason}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* テスト結果の詳細を表示する
|
||||||
*
|
*
|
||||||
* @return Tester
|
* @return Tester
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -62,3 +62,5 @@ $test->describe('プリペアドステートメント', function($test): void {
|
|||||||
echo 'エラー: '.$e->getMessage()."\n";
|
echo 'エラー: '.$e->getMessage()."\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$test->printSummary();
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__.DIRECTORY_SEPARATOR.'/autoload.php';
|
require_once __DIR__.DIRECTORY_SEPARATOR.'/autoload.php';
|
||||||
|
define('ROOT', realpath(__DIR__));
|
||||||
|
require_once __DIR__.DIRECTORY_SEPARATOR.'/config/config.php';
|
||||||
|
|
||||||
$testDir = __DIR__.DIRECTORY_SEPARATOR.'src/Site/Test';
|
$testDir = __DIR__.DIRECTORY_SEPARATOR.'src/Site/Test';
|
||||||
$testFiles = glob($testDir.'/*.php');
|
$testFiles = glob($testDir.'/*.php');
|
||||||
|
|||||||
30
util.php
30
util.php
@@ -61,3 +61,33 @@ function logger(LogType $section, mixed $arg): void {
|
|||||||
file_put_contents($logfile, $arg."\n", FILE_APPEND);
|
file_put_contents($logfile, $arg."\n", FILE_APPEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function to_money($amount, $lang) {
|
||||||
|
$amount = floatval($amount);
|
||||||
|
|
||||||
|
switch (strtolower($lang)) {
|
||||||
|
case 'ja':
|
||||||
|
if ($amount >= 100000000) {
|
||||||
|
$oku = $amount / 100000000;
|
||||||
|
return $oku.'億円';
|
||||||
|
} else if ($amount >= 10000) {
|
||||||
|
$man = $amount / 10000;
|
||||||
|
return $man.'万円';
|
||||||
|
}
|
||||||
|
return number_format($amount, 0).'円';
|
||||||
|
case 'en':
|
||||||
|
if ($amount >= 1000000000) {
|
||||||
|
$billion = $amount / 1000000000;
|
||||||
|
return '¥ '.$billion.' billion';
|
||||||
|
} else if ($amount >= 1000000) {
|
||||||
|
$million = $amount / 1000000;
|
||||||
|
return '¥ '.$million.' million';
|
||||||
|
} else if ($amount >= 1000) {
|
||||||
|
$thousand = $amount / 1000;
|
||||||
|
return '¥ '.$thousand.' thousand';
|
||||||
|
}
|
||||||
|
return '¥ '.number_format($amount, 0);
|
||||||
|
default:
|
||||||
|
return '¥ '.number_format($amount, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
{@ include(common/header) @}
|
{@ include(common/header) @}
|
||||||
{@ include(common/search) @}
|
{@ include(common/search) @}
|
||||||
|
|
||||||
<div class="news-article">
|
<div class="news-article">
|
||||||
{@ if (isset($meta->thumbnail) && $meta->thumbnail != '') @}
|
{@ if (isset($meta->thumbnail) && $meta->thumbnail != '') @}
|
||||||
<div class="thumbnail{{ isset($meta->thumborient) && $meta->thumborient != 'center' ? ' '.$meta->thumborient : '' }}">
|
<div class="thumbnail{{ isset($meta->thumborient) && $meta->thumborient != 'center' ? ' '.$meta->thumborient : '' }}">
|
||||||
@@ -12,16 +11,11 @@
|
|||||||
<div class="meta-author">{{ $meta->author }}</div>
|
<div class="meta-author">{{ $meta->author }}</div>
|
||||||
{@ if (isset($meta->category) && !empty($meta->category) && $meta->category[0] !== '') @}
|
{@ if (isset($meta->category) && !empty($meta->category) && $meta->category[0] !== '') @}
|
||||||
{@ foreach ($meta->category as $cat) @}
|
{@ foreach ($meta->category as $cat) @}
|
||||||
<div class="meta-category">
|
<div class="meta-category">{{ $cat }}</div>
|
||||||
{{ $cat }}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
{@ endforeach @}
|
{@ endforeach @}
|
||||||
{@ endif @}
|
{@ endif @}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h1 class="title">{{{ $meta->title }}}</h1>
|
<h1 class="title">{{{ $meta->title }}}</h1>
|
||||||
{{{ $article }}}
|
{{{ $article."\n" }}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{@ include(common/footer) @}
|
{@ include(common/footer) @}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
</main>
|
</main>
|
||||||
<footer>
|
<footer>
|
||||||
<address>Copyright{{ defined('COPYRIGHT_YEAR') ? ' '.COPYRIGHT_YEAR : '' }} © <a href="https://076.moe/">076スタジオ合同会社</a></address><br />
|
<address>
|
||||||
|
Copyright{{ defined('COPYRIGHT_YEAR') ? ' '.COPYRIGHT_YEAR : '' }} © <a href="https://076.moe/">076スタジオ合同会社</a><br />
|
||||||
Powered By <a href="https://technicalsuwako.moe/littlebeast">Little Beast</a>
|
Powered By <a href="https://technicalsuwako.moe/littlebeast">Little Beast</a>
|
||||||
|
</address>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -12,13 +12,15 @@
|
|||||||
{@ endforeach @}
|
{@ endforeach @}
|
||||||
{@ endif @}
|
{@ endif @}
|
||||||
{@ if (isset($meta)) @}
|
{@ if (isset($meta)) @}
|
||||||
|
{@ if (isset($meta->author)) @}
|
||||||
<meta name="author" content="{{ $meta->author }}" />
|
<meta name="author" content="{{ $meta->author }}" />
|
||||||
|
{@ endif @}
|
||||||
{@ if (isset($meta->thumbnail)) @}
|
{@ if (isset($meta->thumbnail)) @}
|
||||||
<meta name="thumbnail" content="/static/{{ $meta->thumbnail }}" />
|
<meta name="thumbnail" content="/static/{{ $meta->thumbnail }}" />
|
||||||
{@ endif @}
|
{@ endif @}
|
||||||
{@ endif @}
|
{@ endif @}
|
||||||
<meta name="description" content="{{ $description }}" />
|
<meta name="description" content="{{ $description }}" />
|
||||||
<meta name="keywords" content="{{ SITEINFO['tags'].',' }}{@ if (isset($meta)) @}{@ foreach ($meta->category as $cat) @}{{ $cat.',' }}{@ endforeach @}{@ endif @}" />
|
<meta name="keywords" content="{{ SITEINFO['tags'].(isset($meta->category) ? ',' : '') }}{@ if (isset($meta) && isset($meta->category)) @}{@ foreach ($meta->category as $k => $cat) @}{{ $cat.($k === array_key_last($meta->category) ? '' : ',') }}{@ endforeach @}{@ endif @}" />
|
||||||
|
|
||||||
<meta property="og:title" content="{{ SITEINFO['title'] }}: {{ $pagetit }}" />
|
<meta property="og:title" content="{{ SITEINFO['title'] }}: {{ $pagetit }}" />
|
||||||
<meta property="og:description" content="{{ $description }}" />
|
<meta property="og:description" content="{{ $description }}" />
|
||||||
@@ -46,7 +48,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<header>
|
<header>
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
{{ SITEINFO['title'] }}
|
{{ SITEINFO['title'] }}{{ "\n" }}
|
||||||
</div>
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
{@ foreach ($menu as $m) @}
|
{@ foreach ($menu as $m) @}
|
||||||
|
|||||||
Reference in New Issue
Block a user