InformationDumper.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * This file is part of the PHPExiftool package.
  4. *
  5. * (c) Alchemy <support@alchemy.fr>
  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 PHPExiftool;
  11. use PHPExiftool\Exception\InvalidArgumentException;
  12. class InformationDumper
  13. {
  14. /**
  15. * For use with list option
  16. */
  17. const LISTTYPE_WRITABLE = 'w';
  18. /**
  19. * For use with list option
  20. */
  21. const LISTTYPE_SUPPORTED_FILEEXT = 'f';
  22. /**
  23. * For use with list option
  24. */
  25. const LISTTYPE_WRITABLE_FILEEXT = 'wf';
  26. /**
  27. * For use with list option
  28. */
  29. const LISTTYPE_SUPPORTED_XML = 'x';
  30. /**
  31. * For use with list option
  32. */
  33. const LISTTYPE_DELETABLE_GROUPS = 'd';
  34. /**
  35. * For use with list option
  36. */
  37. const LISTTYPE_GROUPS = 'g';
  38. const LISTOPTION_MWG = '-use MWG';
  39. private $exiftool;
  40. public function __construct(Exiftool $exiftool)
  41. {
  42. $this->exiftool = $exiftool;
  43. }
  44. /**
  45. * Return the result of a Exiftool -list* command
  46. *
  47. * @see http://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#item__2dlist_2c__2dlistw_2c__2dlistf_2c__2dlistr_2c__2d
  48. * @param string $type One of the LISTTYPE_* constants
  49. * @return type
  50. * @throws \Exception
  51. */
  52. public function listDatas($type = self::LISTTYPE_SUPPORTED_XML, array $options=array())
  53. {
  54. if ( ! is_array($options)) {
  55. throw new InvalidArgumentException('options must be an array');
  56. }
  57. $available = array(
  58. self::LISTTYPE_WRITABLE, self::LISTTYPE_SUPPORTED_FILEEXT
  59. , self::LISTTYPE_WRITABLE_FILEEXT, self::LISTTYPE_SUPPORTED_XML
  60. , self::LISTTYPE_DELETABLE_GROUPS, self::LISTTYPE_GROUPS,
  61. );
  62. if ( ! in_array($type, $available)) {
  63. throw new InvalidArgumentException('Unknown list attribute');
  64. }
  65. $command = "";
  66. $available = array(self::LISTOPTION_MWG);
  67. foreach($options as $option) {
  68. if ( ! in_array($option, $available)) {
  69. throw new InvalidArgumentException('Unknown option');
  70. }
  71. $command .= ($command?' ':'') . $option;
  72. }
  73. $command .= ($command?' ':'') . '-f -list' . $type;
  74. return $this->exiftool->executeCommand($command);
  75. }
  76. }