#!/usr/bin/env php values[] = $values; foreach ($values as $key => $value) { $length = strlen($value); if (isset($this->length[$key])) { $this->length[$key] = max($this->length[$key], $length); } else { $this->length[$key] = $length; } } } /** * @return string */ public function __toString() : string { $result = ''; foreach ($this->values as $values) { foreach ($values as $key => $value) { if ($key !== 0) { $result .= str_repeat(' ', $this->padding); } $result .= str_pad($value, $this->length[$key]); } $result .= "\n"; } return $result; } } $curlConstants = getCurlConstants(); $sourceConstants = getSourceConstants(); $notInPHP = []; // In cURL doc, but missing from PHP $notInCurl = []; // In the PHP source, but not in the cURL doc $outdated = []; // In the PHP source, but removed before the minimum supported cURL version foreach ($curlConstants as $name => [$introduced, $deprecated, $removed]) { $inPHP = in_array($name, $sourceConstants); if ($removed !== null) { if (version_compare($removed, MIN_SUPPORTED_CURL_VERSION) <= 0) { // constant removed before the minimum supported version continue; } } if (! $inPHP) { $notInPHP[$name] = [$introduced, $removed]; } } foreach ($sourceConstants as $name) { if (! isset($curlConstants[$name])) { $notInCurl[] = $name; continue; } $removed = $curlConstants[$name][2]; if ($removed === null) { continue; } if (version_compare($removed, MIN_SUPPORTED_CURL_VERSION) <= 0) { // constant removed before the minimum supported version $outdated[$name] = $removed; } } $allGood = true; if ($notInPHP) { uasort($notInPHP, function($a, $b) { return version_compare($a[0], $b[0]); }); $table = new AsciiTable(); $table->add('Constant', 'Introduced', '', 'Removed', ''); foreach ($notInPHP as $name => [$introduced, $removed]) { if ($removed === null) { $removed = ''; $removedHex = ''; } else { $removedHex = getHexVersion($removed); } $table->add($name, $introduced, getHexVersion($introduced), $removed, $removedHex); } echo "Constants missing from the PHP source:\n\n"; echo $table, "\n"; $allGood = false; } if ($notInCurl) { $table = new AsciiTable(); foreach ($notInCurl as $name) { $table->add($name); } echo "Constants defined in the PHP source, but absent from the cURL documentation:\n\n"; echo $table, "\n"; $allGood = false; } if ($outdated) { uasort($outdated, function($a, $b) { return version_compare($a, $b); }); $table = new AsciiTable(); $table->add('Constant', 'Removed'); foreach ($outdated as $name => $version) { $table->add($name, $version); } echo "Constants defined in the PHP source, but removed before the minimum supported cURL version:\n\n"; echo $table, "\n"; $allGood = false; } if ($allGood) { echo "All good! Source code and cURL documentation are in sync.\n"; } /** * Loads and parses the cURL constants from the online documentation. * * The result is an associative array where the key is the constant name, and the value is a numeric array with: * - the introduced version * - the deprecated version (nullable) * - the removed version (nullable) * * @return array */ function getCurlConstants() : array { $html = file_get_contents(CURL_DOC_FILE); // Extract the constant list from the HTML file (located in the only
tag in the page) preg_match('~