Removed modules/contrib/media module to allow update to the core media module
[yaffs-website] / vendor / psy / psysh / bin / build-manual
index e9ce518da29a310f62dd744ccc423941660407b3..432926ad3779c30380dced511a66f8cf3e950b0f 100755 (executable)
@@ -27,7 +27,7 @@ function htmlwrap($text, $width = null)
 
     $len = strlen($text);
 
-    $return = array();
+    $return = [];
     $lastSpace = null;
     $inTag = false;
     $i = $tagWidth = 0;
@@ -53,8 +53,7 @@ function htmlwrap($text, $width = null)
 
             case '>':
                 $inTag = false;
-
-            default:
+                break;
         }
 
         if ($inTag) {
@@ -81,11 +80,11 @@ function htmlwrap($text, $width = null)
 
 function extract_paragraphs($element)
 {
-    $paragraphs = array();
+    $paragraphs = [];
     foreach ($element->getElementsByTagName('para') as $p) {
         $text = '';
         foreach ($p->childNodes as $child) {
-            // @todo: figure out if there's something we can do with tables.
+            // @todo figure out if there's something we can do with tables.
             if ($child instanceof DOMElement && $child->tagName === 'table') {
                 continue;
             }
@@ -108,7 +107,7 @@ function extract_paragraphs($element)
 
 function format_doc($doc)
 {
-    $chunks   = array();
+    $chunks   = [];
 
     if (!empty($doc['description'])) {
         $chunks[] = '<comment>Description:</comment>';
@@ -162,20 +161,20 @@ function format_doc($doc)
 
 function thunk_tags($text)
 {
-    $tagMap = array(
+    $tagMap = [
         'parameter>' => 'strong>',
         'function>'  => 'strong>',
         'literal>'   => 'return>',
         'type>'      => 'info>',
         'constant>'  => 'info>',
-    );
+    ];
 
-    $andBack = array(
+    $andBack = [
         '&amp;'       => '&',
         '&amp;true;'  => '<return>true</return>',
         '&amp;false;' => '<return>false</return>',
         '&amp;null;'  => '<return>null</return>',
-    );
+    ];
 
     return strtr(strip_tags(strtr($text, $tagMap), '<strong><return><info>'), $andBack);
 }
@@ -198,24 +197,9 @@ function find_type($xml, $paramName)
     }
 }
 
-$docs = array();
-foreach (glob($argv[1] . '/*/*/*.xml') as $function) {
-    $funcname = basename($function);
-    if ($funcname === 'main.xml' || strpos($funcname, 'entities.') === 0) {
-        continue;
-    }
-
-    $xmlstr = str_replace('&', '&amp;', file_get_contents($function));
-
-    $xml = new DOMDocument();
-    $xml->preserveWhiteSpace = false;
-
-    if (!@$xml->loadXml($xmlstr)) {
-        echo "XML Parse Error: $function\n";
-        continue;
-    }
-
-    $doc = array();
+function format_function_doc($xml)
+{
+    $doc = [];
     $refsect1s = $xml->getElementsByTagName('refsect1');
     foreach ($refsect1s as $refsect1) {
         $role = $refsect1->getAttribute('role');
@@ -239,15 +223,15 @@ foreach (glob($argv[1] . '/*/*/*.xml') as $function) {
                 break;
 
             case 'parameters':
-                $params = array();
+                $params = [];
                 $vars = $refsect1->getElementsByTagName('varlistentry');
                 foreach ($vars as $var) {
                     if ($name = $var->getElementsByTagName('parameter')->item(0)) {
-                        $params[] = array(
+                        $params[] = [
                             'name'        => '$' . $name->textContent,
                             'type'        => find_type($xml, $name->textContent),
                             'description' => extract_paragraphs($var),
-                        );
+                        ];
                     }
                 }
 
@@ -266,9 +250,52 @@ foreach (glob($argv[1] . '/*/*/*.xml') as $function) {
         $doc['description'] = trim($desc);
     }
 
-    $formatted = format_doc($doc);
+    $ids = [];
     foreach ($xml->getElementsByTagName('refname') as $ref) {
-        $docs[$ref->textContent] = $formatted;
+        $ids[] = $ref->textContent;
+    }
+
+    return [$ids, format_doc($doc)];
+}
+
+function format_class_doc($xml)
+{
+    // @todo implement this
+    return [[], null];
+}
+
+$dir = new RecursiveDirectoryIterator($argv[1]);
+$filter = new RecursiveCallbackFilterIterator($dir, function ($current, $key, $iterator) {
+    return $current->getFilename()[0] !== '.' &&
+        ($current->isDir() || $current->getExtension() === 'xml') &&
+        strpos($current->getFilename(), 'entities.') !== 0 &&
+        $current->getFilename() !== 'pdo_4d'; // Temporarily blacklist this one, the docs are weird.
+});
+$iterator = new RecursiveIteratorIterator($filter);
+
+$docs = [];
+foreach ($iterator as $file) {
+    $xmlstr = str_replace('&', '&amp;', file_get_contents($file));
+
+    $xml = new DOMDocument();
+    $xml->preserveWhiteSpace = false;
+
+    if (!@$xml->loadXml($xmlstr)) {
+        echo "XML Parse Error: $file\n";
+        continue;
+    }
+
+    if ($xml->getElementsByTagName('refentry')->length !== 0) {
+        list($ids, $doc) = format_function_doc($xml);
+    } elseif ($xml->getElementsByTagName('classref')->length !== 0) {
+        list($ids, $doc) = format_class_doc($xml);
+    } else {
+        $ids = [];
+        $doc = null;
+    }
+
+    foreach ($ids as $id) {
+        $docs[$id] = $doc;
     }
 }
 
@@ -281,5 +308,5 @@ $db = new PDO('sqlite:' . $argv[2]);
 $db->query('CREATE TABLE php_manual (id char(256) PRIMARY KEY, doc TEXT)');
 $cmd = $db->prepare('INSERT INTO php_manual (id, doc) VALUES (?, ?)');
 foreach ($docs as $id => $doc) {
-    $cmd->execute(array($id, $doc));
+    $cmd->execute([$id, $doc]);
 }