ArrayDumper.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Package\Dumper;
  12. use Composer\Package\PackageInterface;
  13. /**
  14. * @author Konstantin Kudryashiv <ever.zet@gmail.com>
  15. * @author Jordi Boggiano <j.boggiano@seld.be>
  16. */
  17. class ArrayDumper
  18. {
  19. public function dump(PackageInterface $package)
  20. {
  21. $keys = array(
  22. 'binaries' => 'bin',
  23. 'scripts',
  24. 'type',
  25. 'names',
  26. 'extra',
  27. 'installationSource' => 'installation-source',
  28. 'license',
  29. 'authors',
  30. 'description',
  31. 'homepage',
  32. 'keywords',
  33. 'autoload',
  34. 'repositories',
  35. );
  36. $data = array();
  37. $data['name'] = $package->getPrettyName();
  38. $data['version'] = $package->getPrettyVersion();
  39. $data['version_normalized'] = $package->getVersion();
  40. if ($package->getTargetDir()) {
  41. $data['target-dir'] = $package->getTargetDir();
  42. }
  43. if ($package->getReleaseDate()) {
  44. $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s');
  45. }
  46. if ($package->getSourceType()) {
  47. $data['source']['type'] = $package->getSourceType();
  48. $data['source']['url'] = $package->getSourceUrl();
  49. $data['source']['reference'] = $package->getSourceReference();
  50. }
  51. if ($package->getDistType()) {
  52. $data['dist']['type'] = $package->getDistType();
  53. $data['dist']['url'] = $package->getDistUrl();
  54. $data['dist']['reference'] = $package->getDistReference();
  55. $data['dist']['shasum'] = $package->getDistSha1Checksum();
  56. }
  57. foreach (array('require', 'conflict', 'provide', 'replace', 'suggest', 'recommend') as $linkType) {
  58. if ($links = $package->{'get'.ucfirst($linkType).'s'}()) {
  59. foreach ($links as $link) {
  60. $data[$linkType][$link->getTarget()] = $link->getPrettyConstraint();
  61. }
  62. }
  63. }
  64. foreach ($keys as $method => $key) {
  65. if (is_numeric($method)) {
  66. $method = $key;
  67. }
  68. $getter = 'get'.ucfirst($method);
  69. $value = $package->$getter();
  70. if (null !== $value && !(is_array($value) && 0 === count($value))) {
  71. $data[$key] = $value;
  72. }
  73. }
  74. return $data;
  75. }
  76. }