File: extensions.xml.php

package info (click to toggle)
php-doc 20241205~git.dfcbb86%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 70,956 kB
  • sloc: xml: 968,269; php: 23,883; javascript: 671; sh: 177; makefile: 37
file content (190 lines) | stat: -rwxr-xr-x 5,828 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/php -q
<?php
/*
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2023 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.01 of the PHP license,      |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | https://www.php.net/license/3_01.txt.                                |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net, so we can mail you a copy immediately.              |
  +----------------------------------------------------------------------+
  | Authors:    Nuno Lopes <nlopess@php.net>                             |
  |             Gina Peter Banyard <girgias@php.net>                     |
  +----------------------------------------------------------------------+
  | Description: This file parses the manual to find all documented      |
  |              extensions, and create the extension reference page by  |
                 using its membership status and state.                  |
  |              Also used in CI to check the file is up to date         |
  +----------------------------------------------------------------------+
*/


/**
 * This script updates the appendices/extensions.xml file automatically based on
 * the tags placed in the 'book.xml' (and 'reference.xml' for pdo drivers) files:
<?phpdoc extension-membership="(core|bundled|bundledexternal|pecl)" ?>
<!-- State: (deprecated|experimental) -->
*/

$checkFile = false;

$opts = getopt('c', ['check']);
if (array_key_exists('c', $opts) || array_key_exists('check', $opts)) {
    $checkFile = true;
}


$basedir = dirname(__DIR__, 3);
$files   = array_merge(
    glob("$basedir/en/reference/*/book.xml"),
    glob("$basedir/en/reference/pdo_*/reference.xml"),
);
sort($files);
$Membership = $State = $Alphabetical = $debug = [];

// read the files and save the tags' info
foreach ($files as $filename) {

	$file = file_get_contents($filename);

	// get the extension's name
	preg_match('/<(?:reference|book)[^>]+(?:xml:)?id=[\'"]([^\'"]+)[\'"]/S', $file, $match);
	if (empty($match[1])) {
		$debug['unknown-extension'][] = $filename;
		continue;
	} else {
		$ext = $match[1];
	}
	$Alphabetical['alphabetical'][$ext] = 1;
	
	$m = '';
	if (preg_match('/<\?phpdoc extension-membership="([^"]+)" *\?>/S', $file, $match)) {
		$m = $match[1];
	}

	switch($m) {
        case '':
            $debug['membership'][] = $ext;
            // Add to PECL as a fallback
            $Membership['pecl'][$ext] = 1;
		case 'bundledexternal':
			$Membership['external'][$ext] = 1;
			break;
		case 'pecl':
		case 'bundled':
		case 'core':
			$Membership[$m][$ext] = 1;
			break;
		default:
			$debug['bogus-membership'][] = array($ext, $m);
	}

	if (preg_match('/<!-- State: (\w+)/S', $file, $match)) {
		switch ($match[1]) {
		case 'experimental':
		case 'deprecated':
			$State[$match[1]][$ext] = 1;
			break;
                default:
			$debug['bogus-state'][] = array($ext, $match[1]);
		}
	}
}


// ---------- generate the text to write -------------


$xml = file_get_contents("$basedir/en/appendices/extensions.xml");

if ($checkFile) {
    $originalXml = $xml;
}

// little hack to avoid loosing the entities
$xml = preg_replace('/&([^;]+);/', PHP_EOL.'<!--'.PHP_EOL.'entity: "$1"'.PHP_EOL.'-->'.PHP_EOL, $xml);


$simplexml = simplexml_load_string($xml);

foreach ($simplexml->children() as $node) {

	$tmp = explode('.', (string)$node->attributes('xml', true));
	$section = ucfirst($tmp[1]); // Alphabetical, State or Membership

	foreach (($section != 'Alphabetical' ? $node->section : array($node)) as $topnode) {
		$tmp     = explode('.', (string)$topnode->attributes('xml', true));
		$topname = $tmp[count($tmp)-1];

		$tmp = $$section;

		// we can get here as a father of 2 levels children
		if (empty($tmp[$topname])) continue;

		$topnode->itemizedlist = PHP_EOL; // clean the list

		foreach($tmp[$topname] as $ext => $dummy) {

			if ($section != 'Alphabetical') {
				$topnode->itemizedlist = $topnode->itemizedlist . <<< XML
    <listitem><para><xref linkend="$ext"/></para></listitem>

XML;
			} else {
				$topnode->itemizedlist = $topnode->itemizedlist . <<< XML
   <listitem><simpara><xref linkend="$ext"/></simpara></listitem>

XML;
			}
		}

		$topnode->itemizedlist = $topnode->itemizedlist . ($section != 'Alphabetical' ? '   ' : '  ');

	}
}


$xml = strtr(html_entity_decode($simplexml->asXML()), array("\r\n" => PHP_EOL, "\r" => PHP_EOL, "\n" => PHP_EOL));
// get the entities back again
$xml = preg_replace('/( *)[\r\n]*<!--\s+entity: "([^"]+)"\s+-->[\r\n]*/', '$1&$2;'.PHP_EOL.PHP_EOL, $xml);

if ($checkFile) {
    if ($xml !== $originalXml) {
        echo 'appendices/extensions.xml is not up to date.', \PHP_EOL;
        exit(1);
    }
} else {
    file_put_contents("$basedir/en/appendices/extensions.xml", $xml);
    echo "{$basedir}/en/appendices/extensions.xml has been updated, check it for details\n";
}

$status = 0;
// print the debug messages:
if (isset($debug['membership'])) {
	echo "\nExtensions Missing Membership:\n";
	$status = 2;
	print_r($debug['membership']);
}

if (isset($debug['bogus-membership'])) {
	echo "\nExtensions with bogus Membership:\n";
	$status = 2;
	print_r($debug['bogus-membership']);
}

if (isset($debug['bogus-state'])) {
	echo "\nExtensions with bogus State:\n";
	$status = 2;
	print_r($debug['bogus-state']);
}

if (isset($debug['unknown-extension'])) {
	echo "\nExtensions with unknown extension title:\n";
	$status = 2;
	print_r($debug['unknown-extension']);
}
exit($status);