InstalledVersions.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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' => '22b33105768561e48c79c283cb2e7d960f89558f',
  15. 'name' => 'getgrav/grav-plugin-email',
  16. ),
  17. 'versions' =>
  18. array (
  19. 'doctrine/lexer' =>
  20. array (
  21. 'pretty_version' => '1.2.1',
  22. 'version' => '1.2.1.0',
  23. 'aliases' =>
  24. array (
  25. ),
  26. 'reference' => 'e864bbf5904cb8f5bb334f99209b48018522f042',
  27. ),
  28. 'egulias/email-validator' =>
  29. array (
  30. 'pretty_version' => '2.1.25',
  31. 'version' => '2.1.25.0',
  32. 'aliases' =>
  33. array (
  34. ),
  35. 'reference' => '0dbf5d78455d4d6a41d186da50adc1122ec066f4',
  36. ),
  37. 'getgrav/grav-plugin-email' =>
  38. array (
  39. 'pretty_version' => 'dev-develop',
  40. 'version' => 'dev-develop',
  41. 'aliases' =>
  42. array (
  43. ),
  44. 'reference' => '22b33105768561e48c79c283cb2e7d960f89558f',
  45. ),
  46. 'swiftmailer/swiftmailer' =>
  47. array (
  48. 'pretty_version' => 'v6.2.5',
  49. 'version' => '6.2.5.0',
  50. 'aliases' =>
  51. array (
  52. ),
  53. 'reference' => '698a6a9f54d7eb321274de3ad19863802c879fb7',
  54. ),
  55. 'symfony/polyfill-iconv' =>
  56. array (
  57. 'pretty_version' => 'v1.22.0',
  58. 'version' => '1.22.0.0',
  59. 'aliases' =>
  60. array (
  61. ),
  62. 'reference' => 'b34bfb8c4c22650ac080d2662ae3502e5f2f4ae6',
  63. ),
  64. 'symfony/polyfill-intl-idn' =>
  65. array (
  66. 'pretty_version' => 'v1.22.0',
  67. 'version' => '1.22.0.0',
  68. 'aliases' =>
  69. array (
  70. ),
  71. 'reference' => '0eb8293dbbcd6ef6bf81404c9ce7d95bcdf34f44',
  72. ),
  73. 'symfony/polyfill-intl-normalizer' =>
  74. array (
  75. 'pretty_version' => 'v1.22.0',
  76. 'version' => '1.22.0.0',
  77. 'aliases' =>
  78. array (
  79. ),
  80. 'reference' => '6e971c891537eb617a00bb07a43d182a6915faba',
  81. ),
  82. 'symfony/polyfill-mbstring' =>
  83. array (
  84. 'pretty_version' => 'v1.22.0',
  85. 'version' => '1.22.0.0',
  86. 'aliases' =>
  87. array (
  88. ),
  89. 'reference' => 'f377a3dd1fde44d37b9831d68dc8dea3ffd28e13',
  90. ),
  91. 'symfony/polyfill-php72' =>
  92. array (
  93. 'pretty_version' => 'v1.22.0',
  94. 'version' => '1.22.0.0',
  95. 'aliases' =>
  96. array (
  97. ),
  98. 'reference' => 'cc6e6f9b39fe8075b3dabfbaf5b5f645ae1340c9',
  99. ),
  100. ),
  101. );
  102. public static function getInstalledPackages()
  103. {
  104. return array_keys(self::$installed['versions']);
  105. }
  106. public static function isInstalled($packageName)
  107. {
  108. return isset(self::$installed['versions'][$packageName]);
  109. }
  110. public static function satisfies(VersionParser $parser, $packageName, $constraint)
  111. {
  112. $constraint = $parser->parseConstraints($constraint);
  113. $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
  114. return $provided->matches($constraint);
  115. }
  116. public static function getVersionRanges($packageName)
  117. {
  118. if (!isset(self::$installed['versions'][$packageName])) {
  119. throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
  120. }
  121. $ranges = array();
  122. if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {
  123. $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];
  124. }
  125. if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {
  126. $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);
  127. }
  128. if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {
  129. $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);
  130. }
  131. if (array_key_exists('provided', self::$installed['versions'][$packageName])) {
  132. $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);
  133. }
  134. return implode(' || ', $ranges);
  135. }
  136. public static function getVersion($packageName)
  137. {
  138. if (!isset(self::$installed['versions'][$packageName])) {
  139. throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
  140. }
  141. if (!isset(self::$installed['versions'][$packageName]['version'])) {
  142. return null;
  143. }
  144. return self::$installed['versions'][$packageName]['version'];
  145. }
  146. public static function getPrettyVersion($packageName)
  147. {
  148. if (!isset(self::$installed['versions'][$packageName])) {
  149. throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
  150. }
  151. if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
  152. return null;
  153. }
  154. return self::$installed['versions'][$packageName]['pretty_version'];
  155. }
  156. public static function getReference($packageName)
  157. {
  158. if (!isset(self::$installed['versions'][$packageName])) {
  159. throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
  160. }
  161. if (!isset(self::$installed['versions'][$packageName]['reference'])) {
  162. return null;
  163. }
  164. return self::$installed['versions'][$packageName]['reference'];
  165. }
  166. public static function getRootPackage()
  167. {
  168. return self::$installed['root'];
  169. }
  170. public static function getRawData()
  171. {
  172. return self::$installed;
  173. }
  174. public static function reload($data)
  175. {
  176. self::$installed = $data;
  177. }
  178. }