Last active
July 24, 2017 07:16
-
-
Save duggan/77d2075c0a2edb43e214 to your computer and use it in GitHub Desktop.
Get latest versions of a list of PHP PECL extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Usage: | |
* $ php check.php --extensions="apc memcached redis" | |
* apc: 3.1.13 | |
* memcached: 2.2.0 | |
* redis: 2.2.5 | |
*/ | |
class PHPExtensionUpdates { | |
function __construct() { | |
$this->longopts = getopt("", array( | |
'help::', | |
'extensions::', | |
)); | |
$this->extensions = array( | |
); | |
$this->upstream = array(); | |
$this->xml = array(); | |
$this->base_url = "http://pecl.php.net/feeds/pkg_{PACKAGE_NAME}.rss"; | |
} | |
function extensions() { | |
return $this->extensions; | |
} | |
function parseLongOpts() { | |
if (array_key_exists('extensions', $this->longopts)) { | |
$extensions = split(' ', $this->longopts['extensions']); | |
$this->extensions = array_merge($this->extensions, $extensions); | |
} | |
} | |
function run() { | |
$this->parseLongOpts(); | |
if (array_key_exists('help', $this->longopts)) { | |
$this->printHelp(); | |
} else { | |
foreach ($this->extensions() as $ext) { | |
$this->getFeed($ext); | |
$this->check($ext); | |
} | |
$this->printVersions(); | |
} | |
} | |
function getFeed($ext) { | |
if ( ! isset($this->xml[$ext]) ) { | |
$raw = file_get_contents(str_replace('{PACKAGE_NAME}', $ext, $this->base_url)); | |
if ($raw) { | |
$this->xml[$ext] = simplexml_load_string($raw); | |
} | |
} | |
} | |
function check($ext) { | |
if (array_key_exists($ext, $this->xml)) { | |
$title = $this->xml[$ext]->item[0]->title; | |
list($_, $version) = split(' ', $title); | |
$this->upstream[$ext] = $version; | |
} | |
} | |
function printVersions() { | |
foreach ( $this->upstream as $k => $v ) { | |
print("$k: $v\n"); | |
} | |
} | |
function printHelp() { | |
$filename = basename(__FILE__); | |
$helptext = <<<HELPTEXT | |
PHP Extension Update Checker | |
--help Show this help message. | |
--extensions Accepts a space separated list of extensions to check. | |
Example: php $filename --extensions="apc memcached redis" | |
HELPTEXT; | |
print($helptext); | |
} | |
} | |
try { | |
$runner = new PHPExtensionUpdates(); | |
$runner->run(); | |
} catch (Exception $e) { | |
print($e->getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment