Skip to content

Commit 000ecde

Browse files
committed
#reader-interface added reader interface
1 parent 73f0d27 commit 000ecde

File tree

13 files changed

+179
-135
lines changed

13 files changed

+179
-135
lines changed

lib/PHPExif/Reader/AdapterAbstract.php renamed to lib/PHPExif/Adapter/AdapterAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @package Reader
1010
*/
1111

12-
namespace PHPExif\Reader;
12+
namespace PHPExif\Adapter;
1313

1414
/**
1515
* PHP Exif Reader Adapter Abstract

lib/PHPExif/Reader/AdapterInterface.php renamed to lib/PHPExif/Adapter/AdapterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @package Reader
1010
*/
1111

12-
namespace PHPExif\Reader;
12+
namespace PHPExif\Adapter;
1313

1414
/**
1515
* PHP Exif Reader Adapter

lib/PHPExif/Reader/Adapter/Exiftool.php renamed to lib/PHPExif/Adapter/Exiftool.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
* @package Reader
1010
*/
1111

12-
namespace PHPExif\Reader\Adapter;
12+
namespace PHPExif\Adapter;
1313

14-
use PHPExif\Reader\AdapterAbstract;
1514
use PHPExif\Exif;
16-
use \InvalidArgumentException;
17-
use \RuntimeException;
18-
use \DateTime;
15+
use InvalidArgumentException;
16+
use RuntimeException;
17+
use DateTime;
1918

2019
/**
2120
* PHP Exif Exiftool Reader Adapter
@@ -45,7 +44,7 @@ class Exiftool extends AdapterAbstract
4544
* Setter for the exiftool binary path
4645
*
4746
* @param string $path The path to the exiftool binary
48-
* @return \PHPExif\Reader\Adapter\Exiftool Current instance
47+
* @return \PHPExif\Adapter\Exiftool Current instance
4948
* @throws \InvalidArgumentException When path is invalid
5049
*/
5150
public function setToolPath($path)

lib/PHPExif/Reader/Adapter/Native.php renamed to lib/PHPExif/Adapter/Native.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
* @package Reader
1010
*/
1111

12-
namespace PHPExif\Reader\Adapter;
12+
namespace PHPExif\Adapter;
1313

14-
use PHPExif\Reader\AdapterAbstract;
1514
use PHPExif\Exif;
16-
use \DateTime;
15+
use DateTime;
1716

1817
/**
1918
* PHP Exif Native Reader Adapter

lib/PHPExif/Reader/NoAdapterException.php renamed to lib/PHPExif/Adapter/NoAdapterException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* @package Reader
1010
*/
1111

12-
namespace PHPExif\Reader;
12+
namespace PHPExif\Adapter;
1313

14-
use \Exception;
14+
use Exception;
1515

1616
/**
1717
* PHP Exif Reader Adapter
@@ -23,5 +23,5 @@
2323
*/
2424
class NoAdapterException extends Exception
2525
{
26-
26+
//empty
2727
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace PHPExif\Reader;
4+
5+
use Exception;
6+
7+
class ImmutableException extends Exception
8+
{
9+
//empty
10+
}

lib/PHPExif/Reader.php renamed to lib/PHPExif/Reader/Reader.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
* @package Reader
1010
*/
1111

12-
namespace PHPExif;
12+
namespace PHPExif\Reader;
1313

14-
use PHPExif\Reader\AdapterInterface;
15-
use PHPExif\Reader\NoAdapterException;
14+
use PHPExif\Adapter\AdapterInterface;
15+
use PHPExif\Adapter\NoAdapterException;
16+
use PHPExif\Adapter\Exiftool as ExiftoolAdapter;
17+
use PHPExif\Adapter\Native as NativeAdapter;
1618

1719
/**
1820
* PHP Exif Reader
@@ -23,22 +25,22 @@
2325
* @package Reader
2426
* @
2527
*/
26-
class Reader
28+
class Reader implements ReaderInterface
2729
{
2830
const TYPE_NATIVE = 'native';
2931
const TYPE_EXIFTOOL = 'exiftool';
3032

3133
/**
3234
* The current adapter
3335
*
34-
* @var \PHPExif\Reader\AdapterInterface
36+
* @var \PHPExif\Adapter\AdapterInterface
3537
*/
3638
protected $adapter;
3739

3840
/**
3941
* Reader constructor
4042
*
41-
* @param \PHPExif\Reader\AdapterInterface $adapter
43+
* @param \PHPExif\Adapter\AdapterInterface $adapter
4244
*/
4345
public function __construct(AdapterInterface $adapter = null)
4446
{
@@ -50,11 +52,15 @@ public function __construct(AdapterInterface $adapter = null)
5052
/**
5153
* Setter for the reader adapter
5254
*
53-
* @param \PHPExif\Reader\AdapterInterface $adapter
54-
* @return \PHPExif\Reader Current instance for chaining
55+
* @param \PHPExif\Adapter\AdapterInterface $adapter
56+
* @return $this Current instance for chaining
57+
* @throws ImmutableException when adapter is already set
5558
*/
5659
public function setAdapter(AdapterInterface $adapter)
5760
{
61+
if (isset($this->adapter)) {
62+
throw new ImmutableException('cannot override adapter');
63+
}
5864
$this->adapter = $adapter;
5965

6066
return $this;
@@ -63,7 +69,7 @@ public function setAdapter(AdapterInterface $adapter)
6369
/**
6470
* Getter for the reader adapter
6571
*
66-
* @return \PHPExif\Reader\AdapterInterface
72+
* @return \PHPExif\Adapter\AdapterInterface
6773
* @throws NoAdapterException When no adapter is set
6874
*/
6975
public function getAdapter()
@@ -79,28 +85,33 @@ public function getAdapter()
7985
* Factory for the reader
8086
*
8187
* @param string $type
82-
* @return \PHPExif\Reader
88+
* @return $this
8389
* @throws \InvalidArgumentException When given type is invalid
8490
*/
8591
public static function factory($type)
8692
{
93+
/**
94+
* @var $result $this
95+
*/
8796
$classname = get_called_class();
88-
8997
$adapter = null;
9098
switch ($type) {
9199
case self::TYPE_NATIVE:
92-
$adapter = new Reader\Adapter\Native();
100+
$adapter = new NativeAdapter();
93101
break;
94102
case self::TYPE_EXIFTOOL:
95-
$adapter = new Reader\Adapter\Exiftool();
103+
$adapter = new ExiftoolAdapter();
96104
break;
97105
default:
98106
throw new \InvalidArgumentException(
99107
sprintf('Unknown type "%1$s"', $type)
100108
);
101109
break;
102110
}
103-
return new $classname($adapter);
111+
$result = new $classname();
112+
$result->setAdapter($adapter);
113+
114+
return $result;
104115
}
105116

106117
/**
@@ -109,7 +120,7 @@ public static function factory($type)
109120
* @param string $file
110121
* @return \PHPExif\Exif Instance of Exif object with data
111122
*/
112-
public function getExifFromFile($file)
123+
public function read($file)
113124
{
114125
return $this->getAdapter()->getExifFromFile($file);
115126
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace PHPExif\Reader;
4+
5+
interface ReaderInterface
6+
{
7+
/**
8+
* Reads & parses the EXIF data from given file
9+
*
10+
* @param string $file
11+
* @return \PHPExif\Exif Instance of Exif object with data
12+
*/
13+
public function read($file);
14+
}

tests/PHPExif/ExifTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
class ExifTest extends \PHPUnit_Framework_TestCase
34
{
45
/**
@@ -406,8 +407,8 @@ public function testAdapterConsistency()
406407
PHPEXIF_TEST_ROOT . '/files/dsc_5794.jpg'
407408
);
408409

409-
$adapter_exiftool = new \PHPExif\Reader\Adapter\Exiftool();
410-
$adapter_native = new \PHPExif\Reader\Adapter\Native();
410+
$adapter_exiftool = new \PHPExif\Adapter\Exiftool();
411+
$adapter_native = new \PHPExif\Adapter\Native();
411412

412413
foreach ($testfiles as $file) {
413414
$result_exiftool = $adapter_exiftool->getExifFromFile($file);

tests/PHPExif/Reader/Adapter/ExiftoolTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
class ExiftoolTest extends \PHPUnit_Framework_TestCase
33
{
44
/**
5-
* @var \PHPExif\Reader\Adapter\Exiftool
5+
* @var \PHPExif\Adapter\Exiftool
66
*/
77
protected $adapter;
88

99
public function setUp()
1010
{
11-
$this->adapter = new \PHPExif\Reader\Adapter\Exiftool();
11+
$this->adapter = new \PHPExif\Adapter\Exiftool();
1212
}
1313

1414
/**
1515
* @group exiftool
16-
* @covers \PHPExif\Reader\Adapter\Exiftool::getToolPath
16+
* @covers \PHPExif\Adapter\Exiftool::getToolPath
1717
*/
1818
public function testGetToolPathFromProperty()
1919
{
20-
$reflProperty = new \ReflectionProperty('\PHPExif\Reader\Adapter\Exiftool', 'toolPath');
20+
$reflProperty = new \ReflectionProperty('\PHPExif\Adapter\Exiftool', 'toolPath');
2121
$reflProperty->setAccessible(true);
2222
$expected = '/foo/bar/baz';
2323
$reflProperty->setValue($this->adapter, $expected);
@@ -27,11 +27,11 @@ public function testGetToolPathFromProperty()
2727

2828
/**
2929
* @group exiftool
30-
* @covers \PHPExif\Reader\Adapter\Exiftool::setToolPath
30+
* @covers \PHPExif\Adapter\Exiftool::setToolPath
3131
*/
3232
public function testSetToolPathInProperty()
3333
{
34-
$reflProperty = new \ReflectionProperty('\PHPExif\Reader\Adapter\Exiftool', 'toolPath');
34+
$reflProperty = new \ReflectionProperty('\PHPExif\Adapter\Exiftool', 'toolPath');
3535
$reflProperty->setAccessible(true);
3636

3737
$expected = '/tmp';
@@ -42,7 +42,7 @@ public function testSetToolPathInProperty()
4242

4343
/**
4444
* @group exiftool
45-
* @covers \PHPExif\Reader\Adapter\Exiftool::setToolPath
45+
* @covers \PHPExif\Adapter\Exiftool::setToolPath
4646
* @expectedException InvalidArgumentException
4747
*/
4848
public function testSetToolPathThrowsException()
@@ -53,7 +53,7 @@ public function testSetToolPathThrowsException()
5353

5454
/**
5555
* @group exiftool
56-
* @covers \PHPExif\Reader\Adapter\Exiftool::getToolPath
56+
* @covers \PHPExif\Adapter\Exiftool::getToolPath
5757
*/
5858
public function testGetToolPathLazyLoadsPath()
5959
{
@@ -62,7 +62,7 @@ public function testGetToolPathLazyLoadsPath()
6262

6363
/**
6464
* @group exiftool
65-
* @covers \PHPExif\Reader\Adapter\Exiftool::getExifFromFile
65+
* @covers \PHPExif\Adapter\Exiftool::getExifFromFile
6666
*/
6767
public function testGetExifFromFile()
6868
{
@@ -73,7 +73,7 @@ public function testGetExifFromFile()
7373

7474
/**
7575
* @group exiftool
76-
* @covers \PHPExif\Reader\Adapter\Exiftool::mapData
76+
* @covers \PHPExif\Adapter\Exiftool::mapData
7777
*/
7878
public function testMapDataReturnsArray()
7979
{
@@ -82,7 +82,7 @@ public function testMapDataReturnsArray()
8282

8383
/**
8484
* @group exiftool
85-
* @covers \PHPExif\Reader\Adapter\Exiftool::mapData
85+
* @covers \PHPExif\Adapter\Exiftool::mapData
8686
*/
8787
public function testMapDataReturnsArrayFalseValuesIfUndefined()
8888
{
@@ -95,7 +95,7 @@ public function testMapDataReturnsArrayFalseValuesIfUndefined()
9595

9696
/**
9797
* @group exiftool
98-
* @covers \PHPExif\Reader\Adapter\Exiftool::mapData
98+
* @covers \PHPExif\Adapter\Exiftool::mapData
9999
*/
100100
public function testMapDataResultHasAllKeys()
101101
{
@@ -111,7 +111,7 @@ public function testMapDataResultHasAllKeys()
111111

112112
/**
113113
* @group exiftool
114-
* @covers \PHPExif\Reader\Adapter\Exiftool::mapData
114+
* @covers \PHPExif\Adapter\Exiftool::mapData
115115
*/
116116
public function testMapDataFocalLengthIsCalculated()
117117
{
@@ -128,11 +128,11 @@ public function testMapDataFocalLengthIsCalculated()
128128

129129
/**
130130
* @group exiftool
131-
* @covers \PHPExif\Reader\Adapter\Exiftool::getCliOutput
131+
* @covers \PHPExif\Adapter\Exiftool::getCliOutput
132132
*/
133133
public function testGetCliOutput()
134134
{
135-
$reflMethod = new \ReflectionMethod('\PHPExif\Reader\Adapter\Exiftool', 'getCliOutput');
135+
$reflMethod = new \ReflectionMethod('\PHPExif\Adapter\Exiftool', 'getCliOutput');
136136
$reflMethod->setAccessible(true);
137137

138138
$result = $reflMethod->invoke(

0 commit comments

Comments
 (0)