[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/composer/ -> InstalledVersions.php (source)

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