87 lines
3 KiB
PHP
87 lines
3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
return new class extends \Lewp\Module {
|
||
|
|
|
||
|
|
private function createOptionsTable(array $options)
|
||
|
|
{
|
||
|
|
// create head row
|
||
|
|
$head_cells = [
|
||
|
|
$this->createElement("th", "Key"),
|
||
|
|
$this->createElement("th", "Value")
|
||
|
|
];
|
||
|
|
$head_row = $this->createElement("tr");
|
||
|
|
foreach ($head_cells as $cell) {
|
||
|
|
$head_row->appendChild($cell);
|
||
|
|
}
|
||
|
|
// create table body
|
||
|
|
$tbody = $this->createElement("tbody");
|
||
|
|
foreach ($options as $key => $value) {
|
||
|
|
$tr = $this->createElement("tr");
|
||
|
|
$td = $this->createElement("td", $key);
|
||
|
|
$tr->appendChild($td);
|
||
|
|
if (is_array($value)) {
|
||
|
|
$td = $this->createElement("td", "[".implode(", ", $value)."]");
|
||
|
|
} elseif ($value === true) {
|
||
|
|
$td = $this->createElement("td", "true");
|
||
|
|
} elseif ($value === false) {
|
||
|
|
$td = $this->createElement("td", "false");
|
||
|
|
} else {
|
||
|
|
$td = $this->createElement("td", $value);
|
||
|
|
}
|
||
|
|
$tr->appendChild($td);
|
||
|
|
$tbody->appendChild($tr);
|
||
|
|
}
|
||
|
|
// construct the table
|
||
|
|
$thead = $this->createElement("thead");
|
||
|
|
$thead->appendChild($head_row);
|
||
|
|
$thead->appendChild($tbody);
|
||
|
|
|
||
|
|
$table = $this->createElement("table", "", [
|
||
|
|
"class" => "table"
|
||
|
|
]);
|
||
|
|
$table->appendChild($thead);
|
||
|
|
$table->appendChild($tbody);
|
||
|
|
|
||
|
|
return $table;
|
||
|
|
}
|
||
|
|
|
||
|
|
private function addPageId() {
|
||
|
|
$div = $this->createElement("div", null, [
|
||
|
|
"class" => "page-id-wrapper"
|
||
|
|
]);
|
||
|
|
$h2 = $this->createElement("h2", "Current page id: \"".$this->getPageId()."\"");
|
||
|
|
$p = $this->createElement("p");
|
||
|
|
$text = $this->createTextNode("Click on this ");
|
||
|
|
$p->appendChild($text);
|
||
|
|
$href = "/".$this->getPageId()."/hello/dynamic_uri/123456";
|
||
|
|
$a = $this->createElement("a", "link (".$href.")", [
|
||
|
|
"href" => $href
|
||
|
|
]);
|
||
|
|
$p->appendChild($a);
|
||
|
|
$text = $this->createTextNode(" to see dynamic_uri_parts option at work.");
|
||
|
|
$p->appendChild($text);
|
||
|
|
$p->appendChild($this->createElement("br"));
|
||
|
|
$italic = $this->createElement("i", "Please notice that the separation of \"dynamic_uri\" is due to the file hierarchy convention. It is intended, not a bug.");
|
||
|
|
$p->appendChild($italic);
|
||
|
|
|
||
|
|
$div->appendChild($h2);
|
||
|
|
$div->appendChild($p);
|
||
|
|
return $div;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function run(array $options = []) : bool
|
||
|
|
{
|
||
|
|
$this->appendChild($this->addPageId());
|
||
|
|
$this->appendChild($this->createElement("h2", "\$options content"));
|
||
|
|
$this->appendChild($this->createOptionsTable($options));
|
||
|
|
$this->appendChild($this->createElement("h2", "\$this->configuration->get() content"));
|
||
|
|
$this->appendChild($this->createOptionsTable($this->configuration->get()));
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function onWebsocketRequest(
|
||
|
|
\Lewp\Websocket\Message $message
|
||
|
|
) : \Lewp\Websocket\Message {
|
||
|
|
}
|
||
|
|
};
|