AdapterAbstract.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * PHP Exif Reader Adapter Abstract: Common functionality for adapters
  4. *
  5. * @link http://github.com/miljar/PHPExif for the canonical source repository
  6. * @copyright Copyright (c) 2013 Tom Van Herreweghe <tom@theanalogguy.be>
  7. * @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
  8. * @category PHPExif
  9. * @package Reader
  10. */
  11. namespace PHPExif\Adapter;
  12. use PHPExif\Mapper\MapperInterface;
  13. use PHPExif\Hydrator\HydratorInterface;
  14. /**
  15. * PHP Exif Reader Adapter Abstract
  16. *
  17. * Implements common functionality for the reader adapters
  18. *
  19. * @category PHPExif
  20. * @package Reader
  21. */
  22. abstract class AdapterAbstract implements AdapterInterface
  23. {
  24. /**
  25. * @var string
  26. */
  27. protected $hydratorClass = '\\PHPExif\\Hydrator\\Mutator';
  28. /**
  29. * @var \PHPExif\Mapper\MapperInterface
  30. */
  31. protected $mapper;
  32. /**
  33. * @var \PHPExif\Hydrator\HydratorInterface
  34. */
  35. protected $hydrator;
  36. /**
  37. * @var string
  38. */
  39. protected $mapperClass = '';
  40. /**
  41. * Class constructor
  42. *
  43. * @param array $options Optional array of data to initialize the object with
  44. */
  45. public function __construct(array $options = array())
  46. {
  47. if (!empty($options)) {
  48. $this->setOptions($options);
  49. }
  50. }
  51. /**
  52. * Mutator for the data mapper
  53. *
  54. * @param \PHPExif\Mapper\MapperInterface $mapper
  55. * @return \PHPExif\Adapter\AdapterInterface
  56. */
  57. public function setMapper(MapperInterface $mapper)
  58. {
  59. $this->mapper = $mapper;
  60. return $this;
  61. }
  62. /**
  63. * Accessor for the data mapper
  64. *
  65. * @return \PHPExif\Mapper\MapperInterface
  66. */
  67. public function getMapper()
  68. {
  69. if (null === $this->mapper) {
  70. // lazy load one
  71. $mapper = new $this->mapperClass;
  72. $this->setMapper($mapper);
  73. }
  74. return $this->mapper;
  75. }
  76. /**
  77. * Mutator for the hydrator
  78. *
  79. * @param \PHPExif\Hydrator\HydratorInterface $hydrator
  80. * @return \PHPExif\Adapter\AdapterInterface
  81. */
  82. public function setHydrator(HydratorInterface $hydrator)
  83. {
  84. $this->hydrator = $hydrator;
  85. return $this;
  86. }
  87. /**
  88. * Accessor for the data hydrator
  89. *
  90. * @return \PHPExif\Hydrator\HydratorInterface
  91. */
  92. public function getHydrator()
  93. {
  94. if (null === $this->hydrator) {
  95. // lazy load one
  96. $hydrator = new $this->hydratorClass;
  97. $this->setHydrator($hydrator);
  98. }
  99. return $this->hydrator;
  100. }
  101. /**
  102. * Set array of options in the current object
  103. *
  104. * @param array $options
  105. * @return \PHPExif\Reader\AdapterAbstract
  106. */
  107. public function setOptions(array $options)
  108. {
  109. $hydrator = $this->getHydrator();
  110. $hydrator->hydrate($this, $options);
  111. return $this;
  112. }
  113. }