You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.7 KiB
PHP
116 lines
3.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Composer.
|
|
*
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Composer\Repository;
|
|
|
|
use Composer\Package\CompletePackage;
|
|
use Composer\Package\Version\VersionParser;
|
|
|
|
/**
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
*/
|
|
class PlatformRepository extends ArrayRepository
|
|
{
|
|
protected function initialize()
|
|
{
|
|
parent::initialize();
|
|
|
|
$versionParser = new VersionParser();
|
|
|
|
try {
|
|
$prettyVersion = PHP_VERSION;
|
|
$version = $versionParser->normalize($prettyVersion);
|
|
} catch (\UnexpectedValueException $e) {
|
|
$prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION);
|
|
$version = $versionParser->normalize($prettyVersion);
|
|
}
|
|
|
|
$php = new CompletePackage('php', $version, $prettyVersion);
|
|
$php->setDescription('The PHP interpreter');
|
|
parent::addPackage($php);
|
|
|
|
$loadedExtensions = get_loaded_extensions();
|
|
|
|
// Extensions scanning
|
|
foreach ($loadedExtensions as $name) {
|
|
if (in_array($name, array('standard', 'Core'))) {
|
|
continue;
|
|
}
|
|
|
|
$reflExt = new \ReflectionExtension($name);
|
|
try {
|
|
$prettyVersion = $reflExt->getVersion();
|
|
$version = $versionParser->normalize($prettyVersion);
|
|
} catch (\UnexpectedValueException $e) {
|
|
$prettyVersion = '0';
|
|
$version = $versionParser->normalize($prettyVersion);
|
|
}
|
|
|
|
$ext = new CompletePackage('ext-'.$name, $version, $prettyVersion);
|
|
$ext->setDescription('The '.$name.' PHP extension');
|
|
parent::addPackage($ext);
|
|
}
|
|
|
|
// Another quick loop, just for possible libraries
|
|
// Doing it this way to know that functions or constants exist before
|
|
// relying on them.
|
|
foreach ($loadedExtensions as $name) {
|
|
switch ($name) {
|
|
case 'curl':
|
|
$curlVersion = curl_version();
|
|
$prettyVersion = $curlVersion['version'];
|
|
break;
|
|
|
|
case 'iconv':
|
|
$prettyVersion = ICONV_VERSION;
|
|
break;
|
|
|
|
case 'libxml':
|
|
$prettyVersion = LIBXML_DOTTED_VERSION;
|
|
break;
|
|
|
|
case 'openssl':
|
|
$prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
|
|
return $match[1] . (empty($match[2]) ? '' : '.'.(ord($match[2]) - 96));
|
|
}, OPENSSL_VERSION_TEXT);
|
|
break;
|
|
|
|
case 'pcre':
|
|
$prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION);
|
|
break;
|
|
|
|
case 'uuid':
|
|
$prettyVersion = phpversion('uuid');
|
|
break;
|
|
|
|
case 'xsl':
|
|
$prettyVersion = LIBXSLT_DOTTED_VERSION;
|
|
break;
|
|
|
|
default:
|
|
// None handled extensions have no special cases, skip
|
|
continue 2;
|
|
}
|
|
|
|
try {
|
|
$version = $versionParser->normalize($prettyVersion);
|
|
} catch (\UnexpectedValueException $e) {
|
|
continue;
|
|
}
|
|
|
|
$lib = new CompletePackage('lib-'.$name, $version, $prettyVersion);
|
|
$lib->setDescription('The '.$name.' PHP library');
|
|
parent::addPackage($lib);
|
|
}
|
|
}
|
|
}
|