ArrayDumper.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 'type',
  23. 'names',
  24. 'extra',
  25. 'installationSource' => 'installation-source',
  26. 'license',
  27. 'requires',
  28. 'conflicts',
  29. 'provides',
  30. 'replaces',
  31. 'recommends',
  32. 'suggests',
  33. 'autoload',
  34. 'repositories',
  35. );
  36. $data = array();
  37. $data['name'] = $package->getPrettyName();
  38. $data['version'] = $package->getPrettyVersion();
  39. if ($package->getTargetDir()) {
  40. $data['target-dir'] = $package->getTargetDir();
  41. }
  42. if ($package->getSourceType()) {
  43. $data['source']['type'] = $package->getSourceType();
  44. $data['source']['url'] = $package->getSourceUrl();
  45. $data['source']['reference'] = $package->getSourceReference();
  46. }
  47. if ($package->getDistType()) {
  48. $data['dist']['type'] = $package->getDistType();
  49. $data['dist']['url'] = $package->getDistUrl();
  50. $data['dist']['reference'] = $package->getDistReference();
  51. $data['dist']['shasum'] = $package->getDistSha1Checksum();
  52. }
  53. foreach ($keys as $method => $key) {
  54. if (is_numeric($method)) {
  55. $method = $key;
  56. }
  57. $getter = 'get'.ucfirst($method);
  58. $value = $package->$getter();
  59. if (null !== $value && !(is_array($value) && 0 === count($value))) {
  60. $data[$key] = $value;
  61. }
  62. }
  63. return $data;
  64. }
  65. }