ArrayDumper.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. */
  16. class ArrayDumper
  17. {
  18. public function dump(PackageInterface $package)
  19. {
  20. $keys = array(
  21. 'type',
  22. 'names',
  23. 'extra',
  24. 'installationSource',
  25. 'sourceType',
  26. 'sourceUrl',
  27. 'distType',
  28. 'distUrl',
  29. 'distSha1Checksum',
  30. 'version',
  31. 'license',
  32. 'requires',
  33. 'conflicts',
  34. 'provides',
  35. 'replaces',
  36. 'recommends',
  37. 'suggests'
  38. );
  39. $data = array();
  40. $data['name'] = $package->getPrettyName();
  41. foreach ($keys as $key) {
  42. $getter = 'get'.ucfirst($key);
  43. $value = $package->$getter();
  44. if (null !== $value && !(is_array($value) && 0 === count($value))) {
  45. $data[$key] = $value;
  46. }
  47. }
  48. return $data;
  49. }
  50. }