Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cabf6a3
Add Mutator Hydrator for hydrating Exif objects
Mar 29, 2015
8f6cdc0
Add separate mappers for mapping data to Exif object format
Mar 29, 2015
bf6ad93
AdapterAbstract now uses Hydrator for setOptions; Removed obsolete me…
Mar 29, 2015
bb6f4e2
Extracted mapping of ExifTool data to separate mapper & updated Exift…
Mar 29, 2015
ae92380
Extracted mapping of native data to separate mapper & updatd Native a…
Mar 29, 2015
0ba6276
Bugfixed some small inconsistencies
Mar 29, 2015
fb7763f
Added mutators to Exif class & updated unit tests
Mar 29, 2015
ec812d9
Removed blank lines to conform to PSR2
Mar 29, 2015
3c36d12
Add unit test for Exiftool::setNumeric
Mar 30, 2015
2daf6e1
Add extra unit tests for Reader class
Mar 30, 2015
a288667
Add some tests for Exif class
Mar 30, 2015
d16cacb
Remove strict coverage option
Mar 30, 2015
4e0ee69
Made coverage more explicit
Mar 30, 2015
5eb8ca5
Add @covers annotation for Exif tests
Mar 30, 2015
cf21a3f
Add unit tests for Mutator class
Apr 1, 2015
2b7fbc6
Add extra unit tests for AdapterAbstract
Apr 1, 2015
281aebd
Add coverage for interfaces & exceptions
Apr 1, 2015
8214151
Beter interface coverage?
Apr 1, 2015
f4eaad8
Add coverage ignore tags
Apr 1, 2015
836ac7c
Add unit test for Exif mutators
Apr 2, 2015
06a75fd
Improved coverage annotations on Exif class
Apr 2, 2015
52bbeef
Removed unnecessary initialization of variable in Reader class
Apr 2, 2015
8fca517
Removed indenting level in Native mapper class
Apr 2, 2015
5899952
Improved docblocks & removed unused variable
Apr 2, 2015
32b4358
Changed docblocks for AbstractAdapter constructor
Apr 2, 2015
874d645
Removed obsolete ; in docblocks
Apr 2, 2015
86c4dac
Unit tests for Exiftool mapper
Apr 2, 2015
7b16cd4
Removed incorrect coverage tag
Apr 2, 2015
a2a0272
Unit test for Native mapper
Apr 3, 2015
cc6fbb7
Exclude Interfaces from coverage report
Apr 3, 2015
6dbc594
Added @covers annotation for the NoAdapterException
Apr 3, 2015
a862bea
Tried mocking proc_open function for coverage
Apr 3, 2015
795fab5
Corrected stubbing of root function
Apr 3, 2015
476367b
Add GPS code
Apr 3, 2015
1e2e623
More unit tests for Exif (GPS added)
Apr 3, 2015
401686c
Unit tests for GPS stuff
Apr 3, 2015
1d4a96b
Covered extra paths for Exiftool mapper test
Apr 3, 2015
f29d0e5
Merge pull request #33 from Miljar/issues/#25
Miljar Apr 3, 2015
ff65183
New info in CHANGELOG & README
Apr 4, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
AdapterAbstract now uses Hydrator for setOptions; Removed obsolete me…
…thods

Signed-off-by: Tom Van Herreweghe <[email protected]>
  • Loading branch information
Tom Van Herreweghe committed Apr 3, 2015
commit bf6ad93a31e26d3234bdd69f2dcf3bf7d7cb3c38
110 changes: 58 additions & 52 deletions lib/PHPExif/Adapter/AdapterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace PHPExif\Adapter;

use PHPExif\Mapper\MapperInterface;
use PHPExif\Hydrator\HydratorInterface;

/**
* PHP Exif Reader Adapter Abstract
*
Expand All @@ -21,6 +24,21 @@
*/
abstract class AdapterAbstract implements AdapterInterface
{
/**
* @var string
*/
protected $hydratorClass = '\\PHPExif\\Hydrator\\Mutator';

/**
* @var \PHPExif\Mapper\MapperInterface
*/
protected $mapper;

/**
* @var \PHPExif\Hydrator\HydratorInterface
*/
protected $hydrator;

/**
* Class constructor
*
Expand All @@ -34,88 +52,76 @@ public function __construct(array $options = array())
}

/**
* Set array of options in the current object
* Mutator for the data mapper
*
* @param array $options
* @return \PHPExif\Reader\AdapterAbstract
* @param \PHPExif\Mapper\MapperInterface $mapper
* @return \PHPExif\Adapter\AdapterInterface;
*/
public function setOptions(array $options)
public function setMapper(MapperInterface $mapper)
{
foreach ($options as $property => $value) {
$setter = $this->determinePropertySetter($property);
if (method_exists($this, $setter)) {
$this->$setter($value);
}
}
$this->mapper = $mapper;

return $this;
}

/**
* Detemines the name of the getter method for given property name
* Accessor for the data mapper
*
* @param string $property The property to determine the getter for
* @return string The name of the getter method
* @return \PHPExif\Mapper\MapperInterface
*/
protected function determinePropertyGetter($property)
public function getMapper()
{
$method = 'get' . ucfirst($property);
return $method;
if (null === $this->mapper) {
// lazy load one
$mapper = new $this->mapperClass;

$this->setMapper($mapper);
}

return $this->mapper;
}

/**
* Detemines the name of the setter method for given property name
* Mutator for the hydrator
*
* @param string $property The property to determine the setter for
* @return string The name of the setter method
* @param \PHPExif\Hydrator\HydratorInterface $hydrator
* @return \PHPExif\Adapter\AdapterInterface;
*/
protected function determinePropertySetter($property)
public function setHydrator(HydratorInterface $hydrator)
{
$method = 'set' . ucfirst($property);
return $method;
$this->hydrator = $hydrator;

return $this;
}

/**
* Get a list of the class constants prefixed with given $type
* Accessor for the data hydrator
*
* @param string $type
* @return array
* @return \PHPExif\Hydrator\HydratorInterface
*/
public function getClassConstantsOfType($type)
public function getHydrator()
{
$class = new \ReflectionClass(get_called_class());
$constants = $class->getConstants();

$list = array();
$type = strtoupper($type) . '_';
foreach ($constants as $key => $value) {
if (strpos($key, $type) === 0) {
$list[$key] = $value;
}
if (null === $this->hydrator) {
// lazy load one
$hydrator = new $this->hydratorClass;

$this->setHydrator($hydrator);
}
return $list;

return $this->hydrator;
}

/**
* Returns an array notation of current instance
* Set array of options in the current object
*
* @return array
* @param array $options
* @return \PHPExif\Reader\AdapterAbstract
*/
public function toArray()
public function setOptions(array $options)
{
$rc = new \ReflectionClass(get_class($this));
$properties = $rc->getProperties();
$arrResult = array();

foreach ($properties as $rp) {
/* @var $rp \ReflectionProperty */
$getter = $this->determinePropertyGetter($rp->getName());
if (!method_exists($this, $getter)) {
continue;
}
$arrResult[$rp->getName()] = $this->$getter();
}
$hydrator = $this->getHydrator();
$hydrator->hydrate($this, $options);

return $arrResult;
return $this;
}
}
97 changes: 3 additions & 94 deletions tests/PHPExif/Adapter/AdapterAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,97 +12,6 @@ public function setUp()
$this->adapter = new \PHPExif\Adapter\Native();
}

/**
* @group adapter
* @covers \PHPExif\Adapter\AdapterAbstract::determinePropertyGetter
*/
public function testDeterminePropertyGetter()
{
$reflMethod = new \ReflectionMethod('\PHPExif\Adapter\Native', 'determinePropertyGetter');
$reflMethod->setAccessible(true);

$result = $reflMethod->invoke(
$this->adapter,
'foo'
);

$this->assertEquals('getFoo', $result);
}

/**
* @group adapter
* @covers \PHPExif\Adapter\AdapterAbstract::determinePropertySetter
*/
public function testDeterminePropertySetter()
{
$reflMethod = new \ReflectionMethod('\PHPExif\Adapter\Native', 'determinePropertySetter');
$reflMethod->setAccessible(true);

$result = $reflMethod->invoke(
$this->adapter,
'foo'
);

$this->assertEquals('setFoo', $result);
}

/**
* @group adapter
* @covers \PHPExif\Adapter\AdapterAbstract::getClassConstantsOfType
*/
public function testGetClassConstantsOfTypeAlwaysReturnsArray()
{
$result = $this->adapter->getClassConstantsOfType('sections');
$this->assertInternalType('array', $result);
$result = $this->adapter->getClassConstantsOfType('foo');
$this->assertInternalType('array', $result);
}

/**
* @group adapter
* @covers \PHPExif\Adapter\AdapterAbstract::getClassConstantsOfType
*/
public function testGetClassConstantsOfTypeReturnsCorrectData()
{
$expected = array(
'SECTIONS_AS_ARRAYS' => \PHPExif\Adapter\Native::SECTIONS_AS_ARRAYS,
'SECTIONS_FLAT' => \PHPExif\Adapter\Native::SECTIONS_FLAT,
);
$actual = $this->adapter->getClassConstantsOfType('sections');
$this->assertEquals($expected, $actual);
}

/**
* @group adapter
* @covers \PHPExif\Adapter\AdapterAbstract::toArray
*/
public function testToArrayReturnsPropertiesWithGetters()
{
$expected = array(
'requiredSections',
'includeThumbnail',
'sectionsAsArrays',
);
$result = $this->adapter->toArray();
$actual = array_keys($result);
$this->assertEquals($expected, $actual);
}

/**
* @group adapter
* @covers \PHPExif\Adapter\AdapterAbstract::toArray
*/
public function testToArrayOmmitsPropertiesWithoutGetters()
{
$expected = array(
'iptcMapping',
);
$result = $this->adapter->toArray();
$actual = array_keys($result);
$diff = array_diff($expected, $actual);
$this->assertEquals($expected, $diff);
}

/**
* @group adapter
* @covers \PHPExif\Adapter\AdapterAbstract::setOptions
Expand All @@ -127,7 +36,7 @@ public function testSetOptionsCorrectlySetsProperties()
$this->adapter->setOptions($expected);

foreach ($expected as $key => $value) {
$reflProp = new \ReflectionProperty('\PHPExif\Adapter\Native', $key);
$reflProp = new \ReflectionProperty('\\PHPExif\\Adapter\\Native', $key);
$reflProp->setAccessible(true);
$this->assertEquals($value, $reflProp->getValue($this->adapter));
}
Expand All @@ -145,7 +54,7 @@ public function testSetOptionsIgnoresPropertiesWithoutSetters()
$this->adapter->setOptions($expected);

foreach ($expected as $key => $value) {
$reflProp = new \ReflectionProperty('\PHPExif\Adapter\Native', $key);
$reflProp = new \ReflectionProperty('\\PHPExif\\Adapter\\Native', $key);
$reflProp->setAccessible(true);
$this->assertNotEquals($value, $reflProp->getValue($this->adapter));
}
Expand All @@ -166,7 +75,7 @@ public function testConstructorSetsOptions()
$adapter = new \PHPExif\Adapter\Native($expected);

foreach ($expected as $key => $value) {
$reflProp = new \ReflectionProperty('\PHPExif\Adapter\Native', $key);
$reflProp = new \ReflectionProperty('\\PHPExif\\Adapter\\Native', $key);
$reflProp->setAccessible(true);
$this->assertEquals($value, $reflProp->getValue($adapter));
}
Expand Down