Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /*
  3. * This file is part of the Fxp Composer Asset Plugin package.
  4. *
  5. * (c) François Pluchino <francois.pluchino@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Fxp\Composer\AssetPlugin\Repository;
  11. use Composer\DependencyResolver\Pool;
  12. use Composer\IO\IOInterface;
  13. use Composer\Repository\RepositoryInterface;
  14. use Composer\Repository\RepositoryManager;
  15. /**
  16. * Helper for Repository.
  17. *
  18. * @author François Pluchino <francois.pluchino@gmail.com>
  19. */
  20. class Util
  21. {
  22. /**
  23. * Add repository config.
  24. *
  25. * @param IOInterface $io The IO instance
  26. * @param RepositoryManager $rm The repository mamanger
  27. * @param array $repos The list of already repository added (passed by reference)
  28. * @param string $name The name of the new repository
  29. * @param array $repoConfig The config of the new repository
  30. * @param Pool|null $pool The pool
  31. */
  32. public static function addRepository(IOInterface $io, RepositoryManager $rm, array &$repos, $name, array $repoConfig, Pool $pool = null)
  33. {
  34. $repo = $rm->createRepository($repoConfig['type'], $repoConfig);
  35. static::addRepositoryInstance($io, $rm, $repos, $name, $repo, $pool);
  36. }
  37. /**
  38. * Add repository instance.
  39. *
  40. * @param IOInterface $io The IO instance
  41. * @param RepositoryManager $rm The repository mamanger
  42. * @param array $repos The list of already repository added (passed by reference)
  43. * @param string $name The name of the new repository
  44. * @param RepositoryInterface $repo The repository instance
  45. * @param Pool|null $pool The pool
  46. */
  47. public static function addRepositoryInstance(IOInterface $io, RepositoryManager $rm, array &$repos, $name, RepositoryInterface $repo, Pool $pool = null)
  48. {
  49. if (!isset($repos[$name])) {
  50. static::writeAddRepository($io, $name);
  51. $repos[$name] = $repo;
  52. $rm->addRepository($repo);
  53. if (null !== $pool) {
  54. $pool->addRepository($repo);
  55. }
  56. }
  57. }
  58. /**
  59. * Cleans the package name, removing the Composer prefix if present.
  60. *
  61. * @param string $name
  62. *
  63. * @return string
  64. */
  65. public static function cleanPackageName($name)
  66. {
  67. if (preg_match('/^[a-z]+\-asset\//', $name, $matches)) {
  68. $name = substr($name, strlen($matches[0]));
  69. }
  70. return $name;
  71. }
  72. /**
  73. * Converts the alias of asset package name by the real asset package name.
  74. *
  75. * @param string $name
  76. *
  77. * @return string
  78. */
  79. public static function convertAliasName($name)
  80. {
  81. if (preg_match('/([\w0-9\/_-]+)-\d+(.\d+)?.[\dxX]+$/', $name, $matches)) {
  82. return $matches[1];
  83. }
  84. return $name;
  85. }
  86. /**
  87. * Write the vcs repository name in output console.
  88. *
  89. * @param IOInterface $io The IO instance
  90. * @param string $name The vcs repository name
  91. */
  92. protected static function writeAddRepository(IOInterface $io, $name)
  93. {
  94. if ($io->isVerbose()) {
  95. $io->write('Adding VCS repository <comment>'.$name.'</comment>');
  96. }
  97. }
  98. }