FileEntity.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 Doctrine\Common\Cache\ArrayCache;
  12. use PHPExiftool\RDFParser;
  13. use PHPExiftool\FileEntity;
  14. use PHPExiftool\Driver\Value\ValueInterface;
  15. use PHPExiftool\Driver\Metadata\MetadataBag;
  16. /**
  17. *
  18. *
  19. * @author Romain Neutron - imprec@gmail.com
  20. * @license http://opensource.org/licenses/MIT MIT
  21. */
  22. class FileEntity implements \IteratorAggregate
  23. {
  24. /**
  25. *
  26. * @var \DOMDocument
  27. */
  28. private $dom;
  29. /**
  30. *
  31. * @var \SplFileInfo
  32. */
  33. private $file;
  34. /**
  35. *
  36. * @var ArrayCache
  37. */
  38. private $cache;
  39. /**
  40. *
  41. * @var RDFParser
  42. */
  43. private $parser;
  44. /**
  45. * Construct a new FileEntity
  46. *
  47. * @param string $file
  48. * @param \DOMDocument $dom
  49. * @param RDFParser $parser
  50. * @return FileEntity
  51. */
  52. public function __construct($file, \DOMDocument $dom, RDFParser $parser)
  53. {
  54. $this->dom = $dom;
  55. $this->file = $file;
  56. $this->cache = new ArrayCache();
  57. $this->parser = $parser->open($dom->saveXML());
  58. return $this;
  59. }
  60. public function getIterator()
  61. {
  62. return $this->getMetadatas()->getIterator();
  63. }
  64. /**
  65. *
  66. * @var string
  67. */
  68. public function getFile()
  69. {
  70. return $this->file;
  71. }
  72. /**
  73. *
  74. * @return MetadataBag
  75. */
  76. public function getMetadatas()
  77. {
  78. $key = realpath($this->file);
  79. if ($this->cache->contains($key)) {
  80. return $this->cache->fetch($key);
  81. }
  82. $metadatas = $this->parser->ParseMetadatas();
  83. $this->cache->save($key, $metadatas);
  84. return $metadatas;
  85. }
  86. /**
  87. * Execute a user defined query to retrieve metadata
  88. *
  89. * @param string $query
  90. *
  91. * @return ValueInterface
  92. */
  93. public function executeQuery($query)
  94. {
  95. return $this->parser->Query($query);
  96. }
  97. }