Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tool paths in factory #73

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions lib/PHPExif/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
@@ -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);
@@ -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;

15 changes: 14 additions & 1 deletion lib/PHPExif/Adapter/Exiftool.php
Original file line number Diff line number Diff line change
@@ -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
*
13 changes: 13 additions & 0 deletions lib/PHPExif/Adapter/FFprobe.php
Original file line number Diff line number Diff line change
@@ -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
*
1 change: 1 addition & 0 deletions lib/PHPExif/Adapter/ImageMagick.php
Original file line number Diff line number Diff line change
@@ -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 */
6 changes: 3 additions & 3 deletions lib/PHPExif/Adapter/Native.php
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ class Native extends AbstractAdapter
*
* @var array
*/
protected array $requiredSections = array();
protected array $requiredSections = [];

/**
* Include the thumbnail in the EXIF data?
@@ -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;
@@ -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']);
6 changes: 3 additions & 3 deletions lib/PHPExif/Exif.php
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion lib/PHPExif/Mapper/Exiftool.php
Original file line number Diff line number Diff line change
@@ -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)) {
2 changes: 1 addition & 1 deletion lib/PHPExif/Mapper/FFprobe.php
Original file line number Diff line number Diff line change
@@ -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)) {
2 changes: 1 addition & 1 deletion lib/PHPExif/Mapper/ImageMagick.php
Original file line number Diff line number Diff line change
@@ -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)) {
2 changes: 1 addition & 1 deletion lib/PHPExif/Mapper/Native.php
Original file line number Diff line number Diff line change
@@ -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)) {
11 changes: 6 additions & 5 deletions lib/PHPExif/Reader/Reader.php
Original file line number Diff line number Diff line change
@@ -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);
}

/**
2 changes: 1 addition & 1 deletion tests/PHPExif/Adapter/AdapterAbstractTest.php
Original file line number Diff line number Diff line change
@@ -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);
}

2 changes: 1 addition & 1 deletion tests/PHPExif/Adapter/ExiftoolProcOpenTest.php
Original file line number Diff line number Diff line change
@@ -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) {
2 changes: 1 addition & 1 deletion tests/PHPExif/ExifTest.php
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion tests/PHPExif/Mapper/ExiftoolMapperTest.php
Original file line number Diff line number Diff line change
@@ -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);

2 changes: 1 addition & 1 deletion tests/PHPExif/Mapper/FFprobeMapperTest.php
Original file line number Diff line number Diff line change
@@ -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);

2 changes: 1 addition & 1 deletion tests/PHPExif/Mapper/ImageMagickMapperTest.php
Original file line number Diff line number Diff line change
@@ -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);

2 changes: 1 addition & 1 deletion tests/PHPExif/Mapper/NativeMapperTest.php
Original file line number Diff line number Diff line change
@@ -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);