From: Michael Wallner Date: Sat, 18 Jan 2020 15:05:57 +0000 (+0100) Subject: fix PHP-7.4 compat X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=9e29e618d95d400ebcaa949ae06feb859a3a0562;p=mdref%2Fmdref fix PHP-7.4 compat --- diff --git a/mdref/Action.php b/mdref/Action.php index 7e1307b..da3a4da 100644 --- a/mdref/Action.php +++ b/mdref/Action.php @@ -31,6 +31,11 @@ class Action { */ private $response; + /** + * @var resource + */ + private $output; + /** * @var \http\Url */ @@ -39,11 +44,12 @@ class Action { /** * Initialize the reference */ - public function __construct(Reference $ref, Request $req, Response $res, BaseUrl $baseUrl) { + public function __construct(Reference $ref, Request $req, Response $res, BaseUrl $baseUrl, $output = null) { $this->reference = $ref; $this->request = $req; $this->response = $res; $this->baseUrl = $baseUrl; + $this->output = $output; ob_start($res); } @@ -84,7 +90,11 @@ class Action { private function serveCanonical(string $cnn) : void { $this->response->setHeader("Location", $this->baseUrl->mod(["path" => $cnn])); $this->response->setResponseCode(301); - $this->response->send(); + if (is_resource($this->output)) { + $this->response->send($this->output); + } else { + $this->response->send(); + } } /** @@ -93,7 +103,11 @@ class Action { private function serveStylesheet() : void { $this->response->setHeader("Content-Type", "text/css"); $this->response->setBody(new Body(\fopen(ROOT."/public/index.css", "r"))); - $this->response->send(); + if (is_resource($this->output)) { + $this->response->send($this->output); + } else { + $this->response->send(); + } } /** @@ -102,7 +116,11 @@ class Action { private function serveJavascript() : void { $this->response->setHeader("Content-Type", "application/javascript"); $this->response->setBody(new Body(\fopen(ROOT."/public/index.js", "r"))); - $this->response->send(); + if (is_resource($this->output)) { + $this->response->send($this->output); + } else { + $this->response->send(); + } } /** @@ -119,7 +137,11 @@ class Action { $this->response->setHeader("Content-Type", "application/x-php"); $this->response->setContentDisposition(["attachment" => ["filename" => "$name.stub.php"]]); $this->response->setBody(new Body(\fopen($stub, "r"))); - $this->response->send(); + if (is_resource($this->output)) { + $this->response->send($this->output); + } else { + $this->response->send(); + } } /** @@ -158,7 +180,11 @@ class Action { include ROOT."/views/layout.phtml"; $this->response->addHeader("Link", "<" . $this->baseUrl->path . "index.css>; rel=preload; as=style"); $this->response->addHeader("Link", "<" . $this->baseUrl->path . "index.js>; rel=preload; as=script"); - $this->response->send(); + if (is_resource($this->output)) { + $this->response->send($this->output); + } else { + $this->response->send(); + } } /** diff --git a/mdref/Entry.php b/mdref/Entry.php index 2ca35f5..152ba47 100644 --- a/mdref/Entry.php +++ b/mdref/Entry.php @@ -218,7 +218,7 @@ class Entry implements IteratorAggregate { */ public function isFunction() : bool { $base = end($this->list); - return $base{0} === "_" || ctype_lower($base{0}); + return $base[0] === "_" || ctype_lower($base[0]); } /** @@ -227,7 +227,7 @@ class Entry implements IteratorAggregate { */ public function isNsClass() : bool { $base = end($this->list); - return ctype_upper($base{0}); + return ctype_upper($base[0]); } /** @@ -265,12 +265,12 @@ class Entry implements IteratorAggregate { } $parent = end($parts); - switch ($myself{0}) { + switch ($myself[0]) { case ":": return "★" . substr($myself, 1); default: - if (!ctype_lower($myself{0}) || ctype_lower($parent{0})) { + if (!ctype_lower($myself[0]) || ctype_lower($parent[0])) { return $myself; } case "_": diff --git a/mdref/File.php b/mdref/File.php index 6add1d5..3c1ca0a 100644 --- a/mdref/File.php +++ b/mdref/File.php @@ -70,7 +70,7 @@ class File { public function readFullDescription() : ?string { $desc = $this->readDescription(); while (false !== ($line = fgets($this->fd))) { - if ($line{0} === "#") { + if ($line[0] === "#") { break; } else { $desc .= $line; diff --git a/mdref/Structure.php b/mdref/Structure.php index dc871d1..2f1a184 100644 --- a/mdref/Structure.php +++ b/mdref/Structure.php @@ -149,6 +149,7 @@ class Structure { static $pattern = '/ \*\s+ (?P\w+\s+)* + (?:\((?P(?:(?:\w+)\s*)*)\))*\s* (?P[\\\\\w]+)\s+ (?\$\w+) (?:\s*=\s*(?P.+))? @@ -208,7 +209,7 @@ class Structure { \s*,?\s* (?P(?:.|\n(?!\s*\*))*) /x'; - + $returns = $this->splitList($pattern, $this->getSection("Returns")); $retvals = []; foreach ($returns as list(, $type, $desc)) { @@ -294,7 +295,7 @@ abstract class StructureOf { return $type; break; default: - return ($type{0} === "\\" ? "":"\\") . $type; + return ($type[0] === "\\" ? "":"\\") . $type; break; } } @@ -466,6 +467,7 @@ class StructureOfVar extends StructureOf { public $type; public $desc; public $modifiers; + public $usages; public $defval; public $ref; @@ -475,7 +477,7 @@ class StructureOfVar extends StructureOf { printf(" = "); var_export(constant($this->defval)); } else if (strlen($this->defval)) { - if (false !== strchr($this->defval, "\\") && $this->defval{0} != "\\") { + if (false !== strchr($this->defval, "\\") && $this->defval[0] != "\\") { $this->defval = "\\" . $this->defval; } printf(" = %s", $this->defval); @@ -489,7 +491,7 @@ class StructureOfVar extends StructureOf { function formatAsProp($level) { $indent = str_repeat("\t", $level); $this->formatDesc($level, - preg_split('/\s+/', $this->modifiers, -1, PREG_SPLIT_NO_EMPTY) + preg_split('/\s+/', $this->modifiers ." " . $this->usages, -1, PREG_SPLIT_NO_EMPTY) + [-1 => "var " . $this->saneType($this->type)] ); printf("%s%s %s", $indent, $this->modifiers, $this->name); diff --git a/mdref/Tree.php b/mdref/Tree.php index 357f991..fc12a1c 100644 --- a/mdref/Tree.php +++ b/mdref/Tree.php @@ -61,7 +61,7 @@ class Tree implements RecursiveIterator { */ private function generateFilter(array $list) : \Closure { return function($v) use($list) { - if ($v{0} === ".") { + if ($v[0] === ".") { return false; } if (false !== array_search("$v.md", $list, true)) { @@ -85,11 +85,11 @@ class Tree implements RecursiveIterator { $ab = basename($a, ".md"); $bb = basename($b, ".md"); - if ($ab{0} === ":" && $bb{0} === ":") { + if ($ab[0] === ":" && $bb[0] === ":") { return strcmp($ab, $bb); - } elseif ($ab{0} === ":") { + } elseif ($ab[0] === ":") { return -1; - } elseif ($bb{0} === ":") { + } elseif ($bb[0] === ":") { return 1; } diff --git a/public/index.js b/public/index.js index 5f0f34f..45862d0 100644 --- a/public/index.js +++ b/public/index.js @@ -244,5 +244,5 @@ $(function() { }); setTimeout(function() { $("footer").addClass("hidden"); - }, 1); + }, 1000); });