Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

88 lines
2.6KB

  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\Converter;
  11. /**
  12. * Converter for bower package to composer package.
  13. *
  14. * @author François Pluchino <francois.pluchino@gmail.com>
  15. */
  16. class BowerPackageConverter extends AbstractPackageConverter
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. protected function getMapKeys()
  22. {
  23. $assetType = $this->assetType;
  24. return array(
  25. 'name' => array('name', function ($value) use ($assetType) {
  26. return $assetType->formatComposerName($value);
  27. }),
  28. 'type' => array('type', function () use ($assetType) {
  29. return $assetType->getComposerType();
  30. }),
  31. 'version' => array('version', function ($value) use ($assetType) {
  32. return $assetType->getVersionConverter()->convertVersion($value);
  33. }),
  34. 'version_normalized' => 'version_normalized',
  35. 'description' => 'description',
  36. 'keywords' => 'keywords',
  37. 'license' => 'license',
  38. 'bin' => 'bin',
  39. );
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. protected function getMapExtras()
  45. {
  46. return array(
  47. 'main' => 'bower-asset-main',
  48. 'ignore' => 'bower-asset-ignore',
  49. 'private' => 'bower-asset-private',
  50. );
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. protected function convertDependency($dependency, $version, array &$vcsRepos = array(), array $composer)
  56. {
  57. list($dependency, $version) = $this->checkGithubRepositoryVersion($dependency, $version);
  58. return parent::convertDependency($dependency, $version, $vcsRepos, $composer);
  59. }
  60. /**
  61. * Checks if the version is a Github alias version of repository.
  62. *
  63. * @param string $dependency The dependency
  64. * @param string $version The version
  65. *
  66. * @return string[] The new dependency and the new version
  67. */
  68. protected function checkGithubRepositoryVersion($dependency, $version)
  69. {
  70. if (preg_match('/^[A-Za-z0-9\-_]+\/[A-Za-z0-9\-_.]+/', $version)) {
  71. $pos = strpos($version, '#');
  72. $pos = false === $pos ? strlen($version) : $pos;
  73. $realVersion = substr($version, $pos);
  74. $version = 'git://github.com/'.substr($version, 0, $pos).'.git'.$realVersion;
  75. }
  76. return array($dependency, $version);
  77. }
  78. }