fix PHP-7.4 compat
authorMichael Wallner <mike@php.net>
Sat, 18 Jan 2020 15:05:57 +0000 (16:05 +0100)
committerMichael Wallner <mike@php.net>
Sat, 18 Jan 2020 15:05:57 +0000 (16:05 +0100)
mdref/Action.php
mdref/Entry.php
mdref/File.php
mdref/Structure.php
mdref/Tree.php
public/index.js

index 7e1307bffff70e85412e45a221a1589777cffa35..da3a4da871c5dd6c354af8990b8d66f879d9e1a0 100644 (file)
@@ -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();
+               }
        }
 
        /**
index 2ca35f52921db291389eb3017cd1be3a1fb36bff..152ba47232c38f9a2e8a2d6c25c494d5b9ef0047 100644 (file)
@@ -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 "_":
index 6add1d56b7221df4bba940c0fcbc4f96ad3a57f3..3c1ca0a6d276e37314178606f336d595ad3137c2 100644 (file)
@@ -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;
index dc871d1b960a8f3c00b762b88d27554016c8d8ac..2f1a184f1afb387f21287501be2ddf27fed038d3 100644 (file)
@@ -149,6 +149,7 @@ class Structure {
                static $pattern = '/
                        \*\s+
                        (?P<modifiers>\w+\s+)*
+                       (?:\((?P<usages>(?:(?:\w+)\s*)*)\))*\s*
                        (?P<type>[\\\\\w]+)\s+
                        (?<name>\$\w+)
                        (?:\s*=\s*(?P<defval>.+))?
@@ -208,7 +209,7 @@ class Structure {
                        \s*,?\s*
                        (?P<desc>(?:.|\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);
index 357f99174f52e6811eb09865bdfe29ef2758c699..fc12a1c4233713fcc2535d3a30b63ce261a216a4 100644 (file)
@@ -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;
                        }
 
index 5f0f34f0eb9da6a0e42524c1cb2a55f32970b267..45862d01bdb1c12cad8d98f404d0574d5f852b11 100644 (file)
@@ -244,5 +244,5 @@ $(function() {
        });
        setTimeout(function() {
                $("footer").addClass("hidden");
-       }, 1);
+       }, 1000);
 });