Skip to content

Commit b9535df

Browse files
ildyriad7415
andauthored
Support tool paths in factory (LycheeOrg#73)
--------- Co-authored-by: Martin Stone <1611702+d7415@users.noreply.github.com>
1 parent 8a44f53 commit b9535df

18 files changed

+53
-25
lines changed

lib/PHPExif/Adapter/AbstractAdapter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class AbstractAdapter implements AdapterInterface
3030
*
3131
* @param array $options Optional array of data to initialize the object with
3232
*/
33-
public function __construct(array $options = array())
33+
public function __construct(array $options = [])
3434
{
3535
if (count($options) > 0) {
3636
$this->setOptions($options);
@@ -43,7 +43,7 @@ public function __construct(array $options = array())
4343
* @param \PHPExif\Contracts\MapperInterface $mapper
4444
* @return \PHPExif\Contracts\AdapterInterface
4545
*/
46-
public function setMapper(MapperInterface $mapper): AdapterInterface
46+
final public function setMapper(MapperInterface $mapper): AdapterInterface
4747
{
4848
$this->mapper = $mapper;
4949

lib/PHPExif/Adapter/Exiftool.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,22 @@ class Exiftool extends AbstractAdapter
3232
*/
3333
protected string $toolPath = '';
3434
protected bool $numeric = true;
35-
protected array $encoding = array();
35+
protected array $encoding = [];
3636
protected string $mapperClass = MapperExiftool::class;
3737

38+
/**
39+
* Set up Exiftool adapter
40+
*
41+
* @param array $options option to be passed to the parent
42+
* @param string $path optional path to the tool
43+
* @return self
44+
*/
45+
public function __construct(array $options = [], string $path = '')
46+
{
47+
parent::__construct($options);
48+
$this->toolPath = $path;
49+
}
50+
3851
/**
3952
* Setter for the exiftool binary path
4053
*

lib/PHPExif/Adapter/FFprobe.php

+13
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ class FFprobe extends AbstractAdapter
4242
protected string $mapperClass = MapperFFprobe::class;
4343

4444

45+
/**
46+
* Set up FFprobe adapter
47+
*
48+
* @param array $options option to be passed to the parent
49+
* @param string $path optional path to the tool
50+
* @return self
51+
*/
52+
public function __construct(array $options = [], string $path = '')
53+
{
54+
parent::__construct($options);
55+
$this->toolPath = $path;
56+
}
57+
4558
/**
4659
* Setter for the exiftool binary path
4760
*

lib/PHPExif/Adapter/ImageMagick.php

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ImageMagick extends AbstractAdapter
5252
public function getExifFromFile(string $file): Exif
5353
{
5454
/* Create the object */
55+
/** @disregard P1009 */
5556
$im = new Imagick($file);
5657

5758
/* Get the EXIF information */

lib/PHPExif/Adapter/Native.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Native extends AbstractAdapter
4141
*
4242
* @var array
4343
*/
44-
protected array $requiredSections = array();
44+
protected array $requiredSections = [];
4545

4646
/**
4747
* Include the thumbnail in the EXIF data?
@@ -200,7 +200,7 @@ public function getExifFromFile(string $file): Exif
200200

201201
// exif_read_data failed to read exif data (i.e. not a jpg/tiff)
202202
if (false === $data) {
203-
$data = array();
203+
$data = [];
204204
$data['FileSize'] = filesize($file);
205205
$data['FileName'] = basename($file);
206206
$data['MimeType'] = $mimeType;
@@ -248,7 +248,7 @@ public function getExifFromFile(string $file): Exif
248248
public function getIptcData(string $file): array
249249
{
250250
getimagesize($file, $info);
251-
$arrData = array();
251+
$arrData = [];
252252
if (isset($info['APP13'])) {
253253
try {
254254
$iptc = iptcparse($info['APP13']);

lib/PHPExif/Exif.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ class Exif
6262
/**
6363
* The mapped EXIF data
6464
*/
65-
protected array $data = array();
65+
protected array $data = [];
6666

6767
/**
6868
* The raw EXIF data
6969
*/
70-
protected array $rawData = array();
70+
protected array $rawData = [];
7171

7272
/**
7373
* Class constructor
7474
*
7575
* @param array $data
7676
*/
77-
public function __construct(array $data = array())
77+
public function __construct(array $data = [])
7878
{
7979
$this->setData($data);
8080
}

lib/PHPExif/Mapper/Exiftool.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function setNumeric(bool $numeric): Exiftool
202202
*/
203203
public function mapRawData(array $data): array
204204
{
205-
$mappedData = array();
205+
$mappedData = [];
206206

207207
foreach ($data as $field => $value) {
208208
if (!array_key_exists($field, $this->map)) {

lib/PHPExif/Mapper/FFprobe.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class FFprobe extends AbstractMapper
9090
*/
9191
public function mapRawData(array $data): array
9292
{
93-
$mappedData = array();
93+
$mappedData = [];
9494

9595
foreach ($data as $field => $value) {
9696
if ($this->isSection($field) && is_array($value)) {

lib/PHPExif/Mapper/ImageMagick.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class ImageMagick extends AbstractMapper
123123
*/
124124
public function mapRawData(array $data): array
125125
{
126-
$mappedData = array();
126+
$mappedData = [];
127127

128128
foreach ($data as $field => $value) {
129129
if (!array_key_exists($field, $this->map)) {

lib/PHPExif/Mapper/Native.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Native extends AbstractMapper
147147
*/
148148
public function mapRawData(array $data): array
149149
{
150-
$mappedData = array();
150+
$mappedData = [];
151151

152152
foreach ($data as $field => $value) {
153153
if ($this->isSection($field) && is_array($value)) {

lib/PHPExif/Reader/Reader.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@ public function __construct(protected readonly AdapterInterface $adapter)
3434
* Factory for the reader
3535
*
3636
* @param ReaderType $type
37+
* @param string $path
3738
* @return Reader
3839
*/
39-
public static function factory(ReaderType $type): Reader
40+
public static function factory(ReaderType $type, string $path = ''): Reader
4041
{
41-
$classname = get_called_class();
4242
$adapter = match ($type) {
4343
ReaderType::NATIVE => new NativeAdapter(),
44-
ReaderType::EXIFTOOL => new ExiftoolAdapter(),
45-
ReaderType::FFPROBE => new FFProbeAdapter(),
44+
ReaderType::EXIFTOOL => new ExiftoolAdapter(path: $path),
45+
ReaderType::FFPROBE => new FFProbeAdapter(path: $path),
4646
ReaderType::IMAGICK => new ImageMagickAdapter(),
4747
};
48-
return new $classname($adapter);
48+
49+
return new Reader($adapter);
4950
}
5051

5152
/**

tests/PHPExif/Adapter/AdapterAbstractTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function setUp(): void
2121
*/
2222
public function testSetOptionsReturnsCurrentInstance()
2323
{
24-
$result = $this->adapter->setOptions(array());
24+
$result = $this->adapter->setOptions([]);
2525
$this->assertSame($this->adapter, $result);
2626
}
2727

tests/PHPExif/Adapter/ExiftoolProcOpenTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// stub the function
1616
use PHPExif\Reader\PhpExifReaderException;
1717

18-
function proc_open($cmd, array $descriptorspec, &$pipes = array())
18+
function proc_open($cmd, array $descriptorspec, &$pipes = [])
1919
{
2020
global $mockProcOpen;
2121
if (isset($mockProcOpen) && !$mockProcOpen) {

tests/PHPExif/ExifTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function setUp(): void
2222
*/
2323
public function testConstructorCallsSetData()
2424
{
25-
$input = array();
25+
$input = [];
2626

2727
// Get mock, without the constructor being called
2828
$mock = $this->getMockBuilder(Exif::class)

tests/PHPExif/Mapper/ExiftoolMapperTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testMapRawDataMapsFieldsCorrectly()
9494

9595
// create raw data
9696
$keys = array_keys($map);
97-
$values = array();
97+
$values = [];
9898
$values = array_pad($values, count($keys), 'foo');
9999
$rawData = array_combine($keys, $values);
100100

tests/PHPExif/Mapper/FFprobeMapperTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testMapRawDataMapsFieldsCorrectly()
6363

6464
// create raw data
6565
$keys = array_keys($map);
66-
$values = array();
66+
$values = [];
6767
$values = array_pad($values, count($keys), 'foo');
6868
$rawData = array_combine($keys, $values);
6969

tests/PHPExif/Mapper/ImageMagickMapperTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testMapRawDataMapsFieldsCorrectly()
5757

5858
// create raw data
5959
$keys = array_unique(array_keys($map));
60-
$values = array();
60+
$values = [];
6161
$values = array_pad($values, count($keys), 'foo');
6262
$rawData = array_combine($keys, $values);
6363

tests/PHPExif/Mapper/NativeMapperTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testMapRawDataMapsFieldsCorrectly()
5959

6060
// create raw data
6161
$keys = array_keys($map);
62-
$values = array();
62+
$values = [];
6363
$values = array_pad($values, count($keys), 'foo');
6464
$rawData = array_combine($keys, $values);
6565

0 commit comments

Comments
 (0)