X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fbin%2Fbuild-manual;h=432926ad3779c30380dced511a66f8cf3e950b0f;hb=052617e40b525f8b817d84c29b1c04951f427069;hp=e9ce518da29a310f62dd744ccc423941660407b3;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website
diff --git a/vendor/psy/psysh/bin/build-manual b/vendor/psy/psysh/bin/build-manual
index e9ce518da..432926ad3 100755
--- a/vendor/psy/psysh/bin/build-manual
+++ b/vendor/psy/psysh/bin/build-manual
@@ -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[] = 'Description:';
@@ -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 = [
'&' => '&',
'&true;' => 'true',
'&false;' => 'false',
'&null;' => 'null',
- );
+ ];
return strtr(strip_tags(strtr($text, $tagMap), ''), $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('&', '&', 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('&', '&', 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]);
}