You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 satır
1.9KB

  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. * Utils for NPM package converter.
  13. *
  14. * @author François Pluchino <francois.pluchino@gmail.com>
  15. */
  16. abstract class NpmPackageUtil
  17. {
  18. /**
  19. * Convert the author section.
  20. *
  21. * @param string|null $value The current value
  22. *
  23. * @return array
  24. */
  25. public static function convertAuthor($value)
  26. {
  27. if (null !== $value) {
  28. $value = array($value);
  29. }
  30. return $value;
  31. }
  32. /**
  33. * Convert the contributors section.
  34. *
  35. * @param string|null $value The current value
  36. * @param string|null $prevValue The previous value
  37. *
  38. * @return array
  39. */
  40. public static function convertContributors($value, $prevValue)
  41. {
  42. $mergeValue = is_array($prevValue) ? $prevValue : array();
  43. $mergeValue = array_merge($mergeValue, is_array($value) ? $value : array());
  44. if (count($mergeValue) > 0) {
  45. $value = $mergeValue;
  46. }
  47. return $value;
  48. }
  49. /**
  50. * Convert the dist section.
  51. *
  52. * @param string|null $value The current value
  53. *
  54. * @return array
  55. */
  56. public static function convertDist($value)
  57. {
  58. if (is_array($value)) {
  59. $data = (array) $value;
  60. $value = array();
  61. foreach ($data as $type => $url) {
  62. if ('shasum' === $type) {
  63. $value[$type] = $url;
  64. } else {
  65. $value['type'] = 'tarball' === $type ? 'tar' : $type;
  66. $value['url'] = $url;
  67. }
  68. }
  69. }
  70. return $value;
  71. }
  72. }