ArrayDumper.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\BasePackage;
  13. use Composer\Package\PackageInterface;
  14. /**
  15. * @author Konstantin Kudryashiv <ever.zet@gmail.com>
  16. * @author Jordi Boggiano <j.boggiano@seld.be>
  17. */
  18. class ArrayDumper
  19. {
  20. public function dump(PackageInterface $package)
  21. {
  22. $keys = array(
  23. 'binaries' => 'bin',
  24. 'scripts',
  25. 'type',
  26. 'extra',
  27. 'installationSource' => 'installation-source',
  28. 'license',
  29. 'authors',
  30. 'description',
  31. 'homepage',
  32. 'keywords',
  33. 'autoload',
  34. 'repositories',
  35. 'includePaths' => 'include-path',
  36. );
  37. $data = array();
  38. $data['name'] = $package->getPrettyName();
  39. $data['version'] = $package->getPrettyVersion();
  40. $data['version_normalized'] = $package->getVersion();
  41. if ($package->getTargetDir()) {
  42. $data['target-dir'] = $package->getTargetDir();
  43. }
  44. if ($package->getReleaseDate()) {
  45. $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s');
  46. }
  47. if ($package->getSourceType()) {
  48. $data['source']['type'] = $package->getSourceType();
  49. $data['source']['url'] = $package->getSourceUrl();
  50. $data['source']['reference'] = $package->getSourceReference();
  51. }
  52. if ($package->getDistType()) {
  53. $data['dist']['type'] = $package->getDistType();
  54. $data['dist']['url'] = $package->getDistUrl();
  55. $data['dist']['reference'] = $package->getDistReference();
  56. $data['dist']['shasum'] = $package->getDistSha1Checksum();
  57. }
  58. foreach (BasePackage::$supportedLinkTypes as $type => $opts) {
  59. if ($links = $package->{'get'.ucfirst($opts['method'])}()) {
  60. foreach ($links as $link) {
  61. $data[$type][$link->getTarget()] = $link->getPrettyConstraint();
  62. }
  63. }
  64. }
  65. if ($packages = $package->getSuggests()) {
  66. $data['suggest'] = $packages;
  67. }
  68. foreach ($keys as $method => $key) {
  69. if (is_numeric($method)) {
  70. $method = $key;
  71. }
  72. $getter = 'get'.ucfirst($method);
  73. $value = $package->$getter();
  74. if (null !== $value && !(is_array($value) && 0 === count($value))) {
  75. $data[$key] = $value;
  76. }
  77. }
  78. return $data;
  79. }
  80. }