1*6cb05674SAndreas Gohr<?php 2*6cb05674SAndreas Gohr 3*6cb05674SAndreas Gohr 4*6cb05674SAndreas Gohr 5*6cb05674SAndreas Gohr 6*6cb05674SAndreas Gohr 7*6cb05674SAndreas Gohr 8*6cb05674SAndreas Gohr 9*6cb05674SAndreas Gohr 10*6cb05674SAndreas Gohr 11*6cb05674SAndreas Gohr 12*6cb05674SAndreas Gohr 13*6cb05674SAndreas Gohrnamespace Composer; 14*6cb05674SAndreas Gohr 15*6cb05674SAndreas Gohruse Composer\Autoload\ClassLoader; 16*6cb05674SAndreas Gohruse Composer\Semver\VersionParser; 17*6cb05674SAndreas Gohr 18*6cb05674SAndreas Gohr 19*6cb05674SAndreas Gohr 20*6cb05674SAndreas Gohr 21*6cb05674SAndreas Gohr 22*6cb05674SAndreas Gohr 23*6cb05674SAndreas Gohrclass InstalledVersions 24*6cb05674SAndreas Gohr{ 25*6cb05674SAndreas Gohrprivate static $installed = array ( 26*6cb05674SAndreas Gohr 'root' => 27*6cb05674SAndreas Gohr array ( 28*6cb05674SAndreas Gohr 'pretty_version' => 'dev-master', 29*6cb05674SAndreas Gohr 'version' => 'dev-master', 30*6cb05674SAndreas Gohr 'aliases' => 31*6cb05674SAndreas Gohr array ( 32*6cb05674SAndreas Gohr ), 33*6cb05674SAndreas Gohr 'reference' => '4ee6ddae660f9ec72c1f6e2ddb72d6b29d6d8900', 34*6cb05674SAndreas Gohr 'name' => 'splitbrain/dokuwiki', 35*6cb05674SAndreas Gohr ), 36*6cb05674SAndreas Gohr 'versions' => 37*6cb05674SAndreas Gohr array ( 38*6cb05674SAndreas Gohr 'aziraphale/email-address-validator' => 39*6cb05674SAndreas Gohr array ( 40*6cb05674SAndreas Gohr 'pretty_version' => '2.0.1', 41*6cb05674SAndreas Gohr 'version' => '2.0.1.0', 42*6cb05674SAndreas Gohr 'aliases' => 43*6cb05674SAndreas Gohr array ( 44*6cb05674SAndreas Gohr ), 45*6cb05674SAndreas Gohr 'reference' => 'fa25bc22c1c0b6491657c91473fae3e40719a650', 46*6cb05674SAndreas Gohr ), 47*6cb05674SAndreas Gohr 'geshi/geshi' => 48*6cb05674SAndreas Gohr array ( 49*6cb05674SAndreas Gohr 'pretty_version' => 'dev-master', 50*6cb05674SAndreas Gohr 'version' => 'dev-master', 51*6cb05674SAndreas Gohr 'aliases' => 52*6cb05674SAndreas Gohr array ( 53*6cb05674SAndreas Gohr 0 => '1.0.x-dev', 54*6cb05674SAndreas Gohr 1 => '9999999-dev', 55*6cb05674SAndreas Gohr ), 56*6cb05674SAndreas Gohr 'reference' => '3c12a7931d509c5e3557c5ed44c9a32e9c917c7d', 57*6cb05674SAndreas Gohr ), 58*6cb05674SAndreas Gohr 'marcusschwarz/lesserphp' => 59*6cb05674SAndreas Gohr array ( 60*6cb05674SAndreas Gohr 'pretty_version' => 'v0.5.5', 61*6cb05674SAndreas Gohr 'version' => '0.5.5.0', 62*6cb05674SAndreas Gohr 'aliases' => 63*6cb05674SAndreas Gohr array ( 64*6cb05674SAndreas Gohr ), 65*6cb05674SAndreas Gohr 'reference' => '77ba82b5218ff228267d3b0e5ec8697be75e86a7', 66*6cb05674SAndreas Gohr ), 67*6cb05674SAndreas Gohr 'openpsa/universalfeedcreator' => 68*6cb05674SAndreas Gohr array ( 69*6cb05674SAndreas Gohr 'pretty_version' => 'v1.8.4', 70*6cb05674SAndreas Gohr 'version' => '1.8.4.0', 71*6cb05674SAndreas Gohr 'aliases' => 72*6cb05674SAndreas Gohr array ( 73*6cb05674SAndreas Gohr ), 74*6cb05674SAndreas Gohr 'reference' => '099817dc9efef33ca2382b04daf9e191b77fed13', 75*6cb05674SAndreas Gohr ), 76*6cb05674SAndreas Gohr 'phpseclib/phpseclib' => 77*6cb05674SAndreas Gohr array ( 78*6cb05674SAndreas Gohr 'pretty_version' => '2.0.31', 79*6cb05674SAndreas Gohr 'version' => '2.0.31.0', 80*6cb05674SAndreas Gohr 'aliases' => 81*6cb05674SAndreas Gohr array ( 82*6cb05674SAndreas Gohr ), 83*6cb05674SAndreas Gohr 'reference' => '233a920cb38636a43b18d428f9a8db1f0a1a08f4', 84*6cb05674SAndreas Gohr ), 85*6cb05674SAndreas Gohr 'simplepie/simplepie' => 86*6cb05674SAndreas Gohr array ( 87*6cb05674SAndreas Gohr 'pretty_version' => '1.5.6', 88*6cb05674SAndreas Gohr 'version' => '1.5.6.0', 89*6cb05674SAndreas Gohr 'aliases' => 90*6cb05674SAndreas Gohr array ( 91*6cb05674SAndreas Gohr ), 92*6cb05674SAndreas Gohr 'reference' => '1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6', 93*6cb05674SAndreas Gohr ), 94*6cb05674SAndreas Gohr 'splitbrain/dokuwiki' => 95*6cb05674SAndreas Gohr array ( 96*6cb05674SAndreas Gohr 'pretty_version' => 'dev-master', 97*6cb05674SAndreas Gohr 'version' => 'dev-master', 98*6cb05674SAndreas Gohr 'aliases' => 99*6cb05674SAndreas Gohr array ( 100*6cb05674SAndreas Gohr ), 101*6cb05674SAndreas Gohr 'reference' => '4ee6ddae660f9ec72c1f6e2ddb72d6b29d6d8900', 102*6cb05674SAndreas Gohr ), 103*6cb05674SAndreas Gohr 'splitbrain/php-archive' => 104*6cb05674SAndreas Gohr array ( 105*6cb05674SAndreas Gohr 'pretty_version' => '1.2.1', 106*6cb05674SAndreas Gohr 'version' => '1.2.1.0', 107*6cb05674SAndreas Gohr 'aliases' => 108*6cb05674SAndreas Gohr array ( 109*6cb05674SAndreas Gohr ), 110*6cb05674SAndreas Gohr 'reference' => '211a2198b73b233d7d2b6159462e11cd9a91348a', 111*6cb05674SAndreas Gohr ), 112*6cb05674SAndreas Gohr 'splitbrain/php-cli' => 113*6cb05674SAndreas Gohr array ( 114*6cb05674SAndreas Gohr 'pretty_version' => '1.1.8', 115*6cb05674SAndreas Gohr 'version' => '1.1.8.0', 116*6cb05674SAndreas Gohr 'aliases' => 117*6cb05674SAndreas Gohr array ( 118*6cb05674SAndreas Gohr ), 119*6cb05674SAndreas Gohr 'reference' => '8c2c001b1b55d194402cf18aad2757049ac6d575', 120*6cb05674SAndreas Gohr ), 121*6cb05674SAndreas Gohr 'splitbrain/slika' => 122*6cb05674SAndreas Gohr array ( 123*6cb05674SAndreas Gohr 'pretty_version' => '1.0.4', 124*6cb05674SAndreas Gohr 'version' => '1.0.4.0', 125*6cb05674SAndreas Gohr 'aliases' => 126*6cb05674SAndreas Gohr array ( 127*6cb05674SAndreas Gohr ), 128*6cb05674SAndreas Gohr 'reference' => 'fda87e816eb150f3608282da962788b4ad509c11', 129*6cb05674SAndreas Gohr ), 130*6cb05674SAndreas Gohr ), 131*6cb05674SAndreas Gohr); 132*6cb05674SAndreas Gohrprivate static $canGetVendors; 133*6cb05674SAndreas Gohrprivate static $installedByVendor = array(); 134*6cb05674SAndreas Gohr 135*6cb05674SAndreas Gohr 136*6cb05674SAndreas Gohr 137*6cb05674SAndreas Gohr 138*6cb05674SAndreas Gohr 139*6cb05674SAndreas Gohr 140*6cb05674SAndreas Gohr 141*6cb05674SAndreas Gohrpublic static function getInstalledPackages() 142*6cb05674SAndreas Gohr{ 143*6cb05674SAndreas Gohr$packages = array(); 144*6cb05674SAndreas Gohrforeach (self::getInstalled() as $installed) { 145*6cb05674SAndreas Gohr$packages[] = array_keys($installed['versions']); 146*6cb05674SAndreas Gohr} 147*6cb05674SAndreas Gohr 148*6cb05674SAndreas Gohr 149*6cb05674SAndreas Gohrif (1 === \count($packages)) { 150*6cb05674SAndreas Gohrreturn $packages[0]; 151*6cb05674SAndreas Gohr} 152*6cb05674SAndreas Gohr 153*6cb05674SAndreas Gohrreturn array_keys(array_flip(\call_user_func_array('array_merge', $packages))); 154*6cb05674SAndreas Gohr} 155*6cb05674SAndreas Gohr 156*6cb05674SAndreas Gohr 157*6cb05674SAndreas Gohr 158*6cb05674SAndreas Gohr 159*6cb05674SAndreas Gohr 160*6cb05674SAndreas Gohr 161*6cb05674SAndreas Gohr 162*6cb05674SAndreas Gohr 163*6cb05674SAndreas Gohr 164*6cb05674SAndreas Gohrpublic static function isInstalled($packageName) 165*6cb05674SAndreas Gohr{ 166*6cb05674SAndreas Gohrforeach (self::getInstalled() as $installed) { 167*6cb05674SAndreas Gohrif (isset($installed['versions'][$packageName])) { 168*6cb05674SAndreas Gohrreturn true; 169*6cb05674SAndreas Gohr} 170*6cb05674SAndreas Gohr} 171*6cb05674SAndreas Gohr 172*6cb05674SAndreas Gohrreturn false; 173*6cb05674SAndreas Gohr} 174*6cb05674SAndreas Gohr 175*6cb05674SAndreas Gohr 176*6cb05674SAndreas Gohr 177*6cb05674SAndreas Gohr 178*6cb05674SAndreas Gohr 179*6cb05674SAndreas Gohr 180*6cb05674SAndreas Gohr 181*6cb05674SAndreas Gohr 182*6cb05674SAndreas Gohr 183*6cb05674SAndreas Gohr 184*6cb05674SAndreas Gohr 185*6cb05674SAndreas Gohr 186*6cb05674SAndreas Gohr 187*6cb05674SAndreas Gohr 188*6cb05674SAndreas Gohrpublic static function satisfies(VersionParser $parser, $packageName, $constraint) 189*6cb05674SAndreas Gohr{ 190*6cb05674SAndreas Gohr$constraint = $parser->parseConstraints($constraint); 191*6cb05674SAndreas Gohr$provided = $parser->parseConstraints(self::getVersionRanges($packageName)); 192*6cb05674SAndreas Gohr 193*6cb05674SAndreas Gohrreturn $provided->matches($constraint); 194*6cb05674SAndreas Gohr} 195*6cb05674SAndreas Gohr 196*6cb05674SAndreas Gohr 197*6cb05674SAndreas Gohr 198*6cb05674SAndreas Gohr 199*6cb05674SAndreas Gohr 200*6cb05674SAndreas Gohr 201*6cb05674SAndreas Gohr 202*6cb05674SAndreas Gohr 203*6cb05674SAndreas Gohr 204*6cb05674SAndreas Gohr 205*6cb05674SAndreas Gohrpublic static function getVersionRanges($packageName) 206*6cb05674SAndreas Gohr{ 207*6cb05674SAndreas Gohrforeach (self::getInstalled() as $installed) { 208*6cb05674SAndreas Gohrif (!isset($installed['versions'][$packageName])) { 209*6cb05674SAndreas Gohrcontinue; 210*6cb05674SAndreas Gohr} 211*6cb05674SAndreas Gohr 212*6cb05674SAndreas Gohr$ranges = array(); 213*6cb05674SAndreas Gohrif (isset($installed['versions'][$packageName]['pretty_version'])) { 214*6cb05674SAndreas Gohr$ranges[] = $installed['versions'][$packageName]['pretty_version']; 215*6cb05674SAndreas Gohr} 216*6cb05674SAndreas Gohrif (array_key_exists('aliases', $installed['versions'][$packageName])) { 217*6cb05674SAndreas Gohr$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); 218*6cb05674SAndreas Gohr} 219*6cb05674SAndreas Gohrif (array_key_exists('replaced', $installed['versions'][$packageName])) { 220*6cb05674SAndreas Gohr$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); 221*6cb05674SAndreas Gohr} 222*6cb05674SAndreas Gohrif (array_key_exists('provided', $installed['versions'][$packageName])) { 223*6cb05674SAndreas Gohr$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); 224*6cb05674SAndreas Gohr} 225*6cb05674SAndreas Gohr 226*6cb05674SAndreas Gohrreturn implode(' || ', $ranges); 227*6cb05674SAndreas Gohr} 228*6cb05674SAndreas Gohr 229*6cb05674SAndreas Gohrthrow new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 230*6cb05674SAndreas Gohr} 231*6cb05674SAndreas Gohr 232*6cb05674SAndreas Gohr 233*6cb05674SAndreas Gohr 234*6cb05674SAndreas Gohr 235*6cb05674SAndreas Gohr 236*6cb05674SAndreas Gohrpublic static function getVersion($packageName) 237*6cb05674SAndreas Gohr{ 238*6cb05674SAndreas Gohrforeach (self::getInstalled() as $installed) { 239*6cb05674SAndreas Gohrif (!isset($installed['versions'][$packageName])) { 240*6cb05674SAndreas Gohrcontinue; 241*6cb05674SAndreas Gohr} 242*6cb05674SAndreas Gohr 243*6cb05674SAndreas Gohrif (!isset($installed['versions'][$packageName]['version'])) { 244*6cb05674SAndreas Gohrreturn null; 245*6cb05674SAndreas Gohr} 246*6cb05674SAndreas Gohr 247*6cb05674SAndreas Gohrreturn $installed['versions'][$packageName]['version']; 248*6cb05674SAndreas Gohr} 249*6cb05674SAndreas Gohr 250*6cb05674SAndreas Gohrthrow new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 251*6cb05674SAndreas Gohr} 252*6cb05674SAndreas Gohr 253*6cb05674SAndreas Gohr 254*6cb05674SAndreas Gohr 255*6cb05674SAndreas Gohr 256*6cb05674SAndreas Gohr 257*6cb05674SAndreas Gohrpublic static function getPrettyVersion($packageName) 258*6cb05674SAndreas Gohr{ 259*6cb05674SAndreas Gohrforeach (self::getInstalled() as $installed) { 260*6cb05674SAndreas Gohrif (!isset($installed['versions'][$packageName])) { 261*6cb05674SAndreas Gohrcontinue; 262*6cb05674SAndreas Gohr} 263*6cb05674SAndreas Gohr 264*6cb05674SAndreas Gohrif (!isset($installed['versions'][$packageName]['pretty_version'])) { 265*6cb05674SAndreas Gohrreturn null; 266*6cb05674SAndreas Gohr} 267*6cb05674SAndreas Gohr 268*6cb05674SAndreas Gohrreturn $installed['versions'][$packageName]['pretty_version']; 269*6cb05674SAndreas Gohr} 270*6cb05674SAndreas Gohr 271*6cb05674SAndreas Gohrthrow new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 272*6cb05674SAndreas Gohr} 273*6cb05674SAndreas Gohr 274*6cb05674SAndreas Gohr 275*6cb05674SAndreas Gohr 276*6cb05674SAndreas Gohr 277*6cb05674SAndreas Gohr 278*6cb05674SAndreas Gohrpublic static function getReference($packageName) 279*6cb05674SAndreas Gohr{ 280*6cb05674SAndreas Gohrforeach (self::getInstalled() as $installed) { 281*6cb05674SAndreas Gohrif (!isset($installed['versions'][$packageName])) { 282*6cb05674SAndreas Gohrcontinue; 283*6cb05674SAndreas Gohr} 284*6cb05674SAndreas Gohr 285*6cb05674SAndreas Gohrif (!isset($installed['versions'][$packageName]['reference'])) { 286*6cb05674SAndreas Gohrreturn null; 287*6cb05674SAndreas Gohr} 288*6cb05674SAndreas Gohr 289*6cb05674SAndreas Gohrreturn $installed['versions'][$packageName]['reference']; 290*6cb05674SAndreas Gohr} 291*6cb05674SAndreas Gohr 292*6cb05674SAndreas Gohrthrow new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 293*6cb05674SAndreas Gohr} 294*6cb05674SAndreas Gohr 295*6cb05674SAndreas Gohr 296*6cb05674SAndreas Gohr 297*6cb05674SAndreas Gohr 298*6cb05674SAndreas Gohr 299*6cb05674SAndreas Gohrpublic static function getRootPackage() 300*6cb05674SAndreas Gohr{ 301*6cb05674SAndreas Gohr$installed = self::getInstalled(); 302*6cb05674SAndreas Gohr 303*6cb05674SAndreas Gohrreturn $installed[0]['root']; 304*6cb05674SAndreas Gohr} 305*6cb05674SAndreas Gohr 306*6cb05674SAndreas Gohr 307*6cb05674SAndreas Gohr 308*6cb05674SAndreas Gohr 309*6cb05674SAndreas Gohr 310*6cb05674SAndreas Gohr 311*6cb05674SAndreas Gohr 312*6cb05674SAndreas Gohrpublic static function getRawData() 313*6cb05674SAndreas Gohr{ 314*6cb05674SAndreas Gohrreturn self::$installed; 315*6cb05674SAndreas Gohr} 316*6cb05674SAndreas Gohr 317*6cb05674SAndreas Gohr 318*6cb05674SAndreas Gohr 319*6cb05674SAndreas Gohr 320*6cb05674SAndreas Gohr 321*6cb05674SAndreas Gohr 322*6cb05674SAndreas Gohr 323*6cb05674SAndreas Gohr 324*6cb05674SAndreas Gohr 325*6cb05674SAndreas Gohr 326*6cb05674SAndreas Gohr 327*6cb05674SAndreas Gohr 328*6cb05674SAndreas Gohr 329*6cb05674SAndreas Gohr 330*6cb05674SAndreas Gohr 331*6cb05674SAndreas Gohr 332*6cb05674SAndreas Gohr 333*6cb05674SAndreas Gohr 334*6cb05674SAndreas Gohr 335*6cb05674SAndreas Gohrpublic static function reload($data) 336*6cb05674SAndreas Gohr{ 337*6cb05674SAndreas Gohrself::$installed = $data; 338*6cb05674SAndreas Gohrself::$installedByVendor = array(); 339*6cb05674SAndreas Gohr} 340*6cb05674SAndreas Gohr 341*6cb05674SAndreas Gohr 342*6cb05674SAndreas Gohr 343*6cb05674SAndreas Gohr 344*6cb05674SAndreas Gohrprivate static function getInstalled() 345*6cb05674SAndreas Gohr{ 346*6cb05674SAndreas Gohrif (null === self::$canGetVendors) { 347*6cb05674SAndreas Gohrself::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); 348*6cb05674SAndreas Gohr} 349*6cb05674SAndreas Gohr 350*6cb05674SAndreas Gohr$installed = array(); 351*6cb05674SAndreas Gohr 352*6cb05674SAndreas Gohrif (self::$canGetVendors) { 353*6cb05674SAndreas Gohrforeach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { 354*6cb05674SAndreas Gohrif (isset(self::$installedByVendor[$vendorDir])) { 355*6cb05674SAndreas Gohr$installed[] = self::$installedByVendor[$vendorDir]; 356*6cb05674SAndreas Gohr} elseif (is_file($vendorDir.'/composer/installed.php')) { 357*6cb05674SAndreas Gohr$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; 358*6cb05674SAndreas Gohr} 359*6cb05674SAndreas Gohr} 360*6cb05674SAndreas Gohr} 361*6cb05674SAndreas Gohr 362*6cb05674SAndreas Gohr$installed[] = self::$installed; 363*6cb05674SAndreas Gohr 364*6cb05674SAndreas Gohrreturn $installed; 365*6cb05674SAndreas Gohr} 366*6cb05674SAndreas Gohr} 367