InstalledVersions.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. namespace Composer;
  3. use Composer\Semver\VersionParser;
  4. class InstalledVersions
  5. {
  6. private static $installed = array (
  7. 'root' =>
  8. array (
  9. 'pretty_version' => 'dev-develop',
  10. 'version' => 'dev-develop',
  11. 'aliases' =>
  12. array (
  13. ),
  14. 'reference' => '092e26c2c6643e0e5a655fd77f7da8baaec48186',
  15. 'name' => 'getgrav/grav-plugin-admin',
  16. ),
  17. 'versions' =>
  18. array (
  19. 'getgrav/grav-plugin-admin' =>
  20. array (
  21. 'pretty_version' => 'dev-develop',
  22. 'version' => 'dev-develop',
  23. 'aliases' =>
  24. array (
  25. ),
  26. 'reference' => '092e26c2c6643e0e5a655fd77f7da8baaec48186',
  27. ),
  28. 'laminas/laminas-xml' =>
  29. array (
  30. 'pretty_version' => '1.3.1',
  31. 'version' => '1.3.1.0',
  32. 'aliases' =>
  33. array (
  34. ),
  35. 'reference' => '2eada592359aec9d9e55339270b621295cff3a4f',
  36. ),
  37. 'laminas/laminas-zendframework-bridge' =>
  38. array (
  39. 'pretty_version' => '1.4.0',
  40. 'version' => '1.4.0.0',
  41. 'aliases' =>
  42. array (
  43. ),
  44. 'reference' => 'bf180a382393e7db5c1e8d0f2ec0c4af9c724baf',
  45. ),
  46. 'miniflux/picofeed' =>
  47. array (
  48. 'replaced' =>
  49. array (
  50. 0 => '0.1.35',
  51. ),
  52. ),
  53. 'p3k/picofeed' =>
  54. array (
  55. 'pretty_version' => 'v0.1.40',
  56. 'version' => '0.1.40.0',
  57. 'aliases' =>
  58. array (
  59. ),
  60. 'reference' => '356fd66d48779193b10ac28532cb4a4e11bb801c',
  61. ),
  62. 'scssphp/scssphp' =>
  63. array (
  64. 'pretty_version' => 'v1.8.1',
  65. 'version' => '1.8.1.0',
  66. 'aliases' =>
  67. array (
  68. ),
  69. 'reference' => '5e37759a63caf54392a4b709358a39ac7425a69f',
  70. ),
  71. 'symfony/polyfill-php72' =>
  72. array (
  73. 'replaced' =>
  74. array (
  75. 0 => '*',
  76. ),
  77. ),
  78. 'symfony/polyfill-php73' =>
  79. array (
  80. 'replaced' =>
  81. array (
  82. 0 => '*',
  83. ),
  84. ),
  85. 'zendframework/zendxml' =>
  86. array (
  87. 'replaced' =>
  88. array (
  89. 0 => '^1.2.0',
  90. ),
  91. ),
  92. ),
  93. );
  94. public static function getInstalledPackages()
  95. {
  96. return array_keys(self::$installed['versions']);
  97. }
  98. public static function isInstalled($packageName)
  99. {
  100. return isset(self::$installed['versions'][$packageName]);
  101. }
  102. public static function satisfies(VersionParser $parser, $packageName, $constraint)
  103. {
  104. $constraint = $parser->parseConstraints($constraint);
  105. $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
  106. return $provided->matches($constraint);
  107. }
  108. public static function getVersionRanges($packageName)
  109. {
  110. if (!isset(self::$installed['versions'][$packageName])) {
  111. throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
  112. }
  113. $ranges = array();
  114. if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {
  115. $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];
  116. }
  117. if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {
  118. $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);
  119. }
  120. if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {
  121. $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);
  122. }
  123. if (array_key_exists('provided', self::$installed['versions'][$packageName])) {
  124. $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);
  125. }
  126. return implode(' || ', $ranges);
  127. }
  128. public static function getVersion($packageName)
  129. {
  130. if (!isset(self::$installed['versions'][$packageName])) {
  131. throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
  132. }
  133. if (!isset(self::$installed['versions'][$packageName]['version'])) {
  134. return null;
  135. }
  136. return self::$installed['versions'][$packageName]['version'];
  137. }
  138. public static function getPrettyVersion($packageName)
  139. {
  140. if (!isset(self::$installed['versions'][$packageName])) {
  141. throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
  142. }
  143. if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
  144. return null;
  145. }
  146. return self::$installed['versions'][$packageName]['pretty_version'];
  147. }
  148. public static function getReference($packageName)
  149. {
  150. if (!isset(self::$installed['versions'][$packageName])) {
  151. throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
  152. }
  153. if (!isset(self::$installed['versions'][$packageName]['reference'])) {
  154. return null;
  155. }
  156. return self::$installed['versions'][$packageName]['reference'];
  157. }
  158. public static function getRootPackage()
  159. {
  160. return self::$installed['root'];
  161. }
  162. public static function getRawData()
  163. {
  164. return self::$installed;
  165. }
  166. public static function reload($data)
  167. {
  168. self::$installed = $data;
  169. }
  170. }