Skip to content

Commit

Permalink
Support tool paths in factory (#73)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Martin Stone <[email protected]>
  • Loading branch information
ildyria and d7415 authored Jul 1, 2024
1 parent 8a44f53 commit b9535df
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 25 deletions.
4 changes: 2 additions & 2 deletions lib/PHPExif/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class AbstractAdapter implements AdapterInterface
*
* @param array $options Optional array of data to initialize the object with
*/
public function __construct(array $options = array())
public function __construct(array $options = [])
{
if (count($options) > 0) {
$this->setOptions($options);
Expand All @@ -43,7 +43,7 @@ public function __construct(array $options = array())
* @param \PHPExif\Contracts\MapperInterface $mapper
* @return \PHPExif\Contracts\AdapterInterface
*/
public function setMapper(MapperInterface $mapper): AdapterInterface
final public function setMapper(MapperInterface $mapper): AdapterInterface
{
$this->mapper = $mapper;

Expand Down
15 changes: 14 additions & 1 deletion lib/PHPExif/Adapter/Exiftool.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,22 @@ class Exiftool extends AbstractAdapter
*/
protected string $toolPath = '';
protected bool $numeric = true;
protected array $encoding = array();
protected array $encoding = [];
protected string $mapperClass = MapperExiftool::class;

/**
* Set up Exiftool adapter
*
* @param array $options option to be passed to the parent
* @param string $path optional path to the tool
* @return self
*/
public function __construct(array $options = [], string $path = '')
{
parent::__construct($options);
$this->toolPath = $path;
}

/**
* Setter for the exiftool binary path
*
Expand Down
13 changes: 13 additions & 0 deletions lib/PHPExif/Adapter/FFprobe.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ class FFprobe extends AbstractAdapter
protected string $mapperClass = MapperFFprobe::class;


/**
* Set up FFprobe adapter
*
* @param array $options option to be passed to the parent
* @param string $path optional path to the tool
* @return self
*/
public function __construct(array $options = [], string $path = '')
{
parent::__construct($options);
$this->toolPath = $path;
}

/**
* Setter for the exiftool binary path
*
Expand Down
1 change: 1 addition & 0 deletions lib/PHPExif/Adapter/ImageMagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ImageMagick extends AbstractAdapter
public function getExifFromFile(string $file): Exif
{
/* Create the object */
/** @disregard P1009 */
$im = new Imagick($file);

/* Get the EXIF information */
Expand Down
6 changes: 3 additions & 3 deletions lib/PHPExif/Adapter/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Native extends AbstractAdapter
*
* @var array
*/
protected array $requiredSections = array();
protected array $requiredSections = [];

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

// exif_read_data failed to read exif data (i.e. not a jpg/tiff)
if (false === $data) {
$data = array();
$data = [];
$data['FileSize'] = filesize($file);
$data['FileName'] = basename($file);
$data['MimeType'] = $mimeType;
Expand Down Expand Up @@ -248,7 +248,7 @@ public function getExifFromFile(string $file): Exif
public function getIptcData(string $file): array
{
getimagesize($file, $info);
$arrData = array();
$arrData = [];
if (isset($info['APP13'])) {
try {
$iptc = iptcparse($info['APP13']);
Expand Down
6 changes: 3 additions & 3 deletions lib/PHPExif/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ class Exif
/**
* The mapped EXIF data
*/
protected array $data = array();
protected array $data = [];

/**
* The raw EXIF data
*/
protected array $rawData = array();
protected array $rawData = [];

/**
* Class constructor
*
* @param array $data
*/
public function __construct(array $data = array())
public function __construct(array $data = [])
{
$this->setData($data);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PHPExif/Mapper/Exiftool.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function setNumeric(bool $numeric): Exiftool
*/
public function mapRawData(array $data): array
{
$mappedData = array();
$mappedData = [];

foreach ($data as $field => $value) {
if (!array_key_exists($field, $this->map)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/PHPExif/Mapper/FFprobe.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class FFprobe extends AbstractMapper
*/
public function mapRawData(array $data): array
{
$mappedData = array();
$mappedData = [];

foreach ($data as $field => $value) {
if ($this->isSection($field) && is_array($value)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/PHPExif/Mapper/ImageMagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ImageMagick extends AbstractMapper
*/
public function mapRawData(array $data): array
{
$mappedData = array();
$mappedData = [];

foreach ($data as $field => $value) {
if (!array_key_exists($field, $this->map)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/PHPExif/Mapper/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Native extends AbstractMapper
*/
public function mapRawData(array $data): array
{
$mappedData = array();
$mappedData = [];

foreach ($data as $field => $value) {
if ($this->isSection($field) && is_array($value)) {
Expand Down
11 changes: 6 additions & 5 deletions lib/PHPExif/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ public function __construct(protected readonly AdapterInterface $adapter)
* Factory for the reader
*
* @param ReaderType $type
* @param string $path
* @return Reader
*/
public static function factory(ReaderType $type): Reader
public static function factory(ReaderType $type, string $path = ''): Reader
{
$classname = get_called_class();
$adapter = match ($type) {
ReaderType::NATIVE => new NativeAdapter(),
ReaderType::EXIFTOOL => new ExiftoolAdapter(),
ReaderType::FFPROBE => new FFProbeAdapter(),
ReaderType::EXIFTOOL => new ExiftoolAdapter(path: $path),
ReaderType::FFPROBE => new FFProbeAdapter(path: $path),
ReaderType::IMAGICK => new ImageMagickAdapter(),
};
return new $classname($adapter);

return new Reader($adapter);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPExif/Adapter/AdapterAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp(): void
*/
public function testSetOptionsReturnsCurrentInstance()
{
$result = $this->adapter->setOptions(array());
$result = $this->adapter->setOptions([]);
$this->assertSame($this->adapter, $result);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPExif/Adapter/ExiftoolProcOpenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// stub the function
use PHPExif\Reader\PhpExifReaderException;

function proc_open($cmd, array $descriptorspec, &$pipes = array())
function proc_open($cmd, array $descriptorspec, &$pipes = [])
{
global $mockProcOpen;
if (isset($mockProcOpen) && !$mockProcOpen) {
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPExif/ExifTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function setUp(): void
*/
public function testConstructorCallsSetData()
{
$input = array();
$input = [];

// Get mock, without the constructor being called
$mock = $this->getMockBuilder(Exif::class)
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPExif/Mapper/ExiftoolMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testMapRawDataMapsFieldsCorrectly()

// create raw data
$keys = array_keys($map);
$values = array();
$values = [];
$values = array_pad($values, count($keys), 'foo');
$rawData = array_combine($keys, $values);

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPExif/Mapper/FFprobeMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testMapRawDataMapsFieldsCorrectly()

// create raw data
$keys = array_keys($map);
$values = array();
$values = [];
$values = array_pad($values, count($keys), 'foo');
$rawData = array_combine($keys, $values);

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPExif/Mapper/ImageMagickMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testMapRawDataMapsFieldsCorrectly()

// create raw data
$keys = array_unique(array_keys($map));
$values = array();
$values = [];
$values = array_pad($values, count($keys), 'foo');
$rawData = array_combine($keys, $values);

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPExif/Mapper/NativeMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testMapRawDataMapsFieldsCorrectly()

// create raw data
$keys = array_keys($map);
$values = array();
$values = [];
$values = array_pad($values, count($keys), 'foo');
$rawData = array_combine($keys, $values);

Expand Down

0 comments on commit b9535df

Please sign in to comment.