Skip to content

Commit

Permalink
Support for Php8 & 8.1, drop 7.4 (#40)
Browse files Browse the repository at this point in the history
* stronger types requirements
* Full support for php8
* fix dependencies
* Make workflow more similar to Lychee
* Use `shivammathur/setup-php` and `extensions` to install PHP extension Imagick
* Add project folder Idea PHPStorm to ignored files
* Made composer.json more Lychee-like
* Fixed error in version string.
* Added extension "fileinfo" to dependencies as this is required by `mime_content_type`.
* update Readme

Co-authored-by: ildyria <[email protected]>
  • Loading branch information
nagmat84 and ildyria authored Apr 27, 2022
1 parent a4e6f5c commit 458b697
Show file tree
Hide file tree
Showing 23 changed files with 279 additions and 340 deletions.
52 changes: 13 additions & 39 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,30 @@ on:
jobs:
tests:
runs-on: ${{ matrix.operating-system }}
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push to the branch.
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)

strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-20.04]
php-versions: ['7.4', '8.0']
php-versions: ['8.0', '8.1']
dependencies: ['no', 'low', 'beta']
include:
- operating-system: ubuntu-20.04
php-versions: '8.0'
continue-on-error: true

name: PHP ${{ matrix.php-versions }} - ${{ matrix.dependencies }}

env:
extensions: curl json libxml dom
extensions: curl, dom, imagick, json, libxml, mbstring
key: cache-v1 # can be any string, change to clear the extension cache.

steps:
- name: Install local deps
run: |
sudo apt-get update
sudo apt-get -y install ffmpeg php-imagick libimage-exiftool-perl libmagickwand-dev
# Checks out a copy of your repository on the ubuntu machine
- name: Checkout code
uses: actions/checkout@v2

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
uses: shivammathur/cache-extensions@1.6.2
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
Expand All @@ -57,42 +49,24 @@ jobs:
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Cache Composer Dependencies
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: ~/.composer/cache/files
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP Action
uses: shivammathur/setup-php@2.8.0
uses: shivammathur/setup-php@2.15.0
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
coverage: xdebug
tools: pecl, composer

- name: Set Up imagick (php8 and php7.3)
if: ${{ matrix.php-versions != '7.4' }}
run: |
git clone https://github.com/Imagick/imagick.git
cd imagick && phpize && ./configure && make
DEST=$(php -i | grep 'extension_dir => /')
php -i | grep 'extension_dir => /'
php -i | grep 'extension_dir'
echo $DEST
DEST2=$(echo "${DEST##* }")
echo 'Copying imagick.so to ' $DEST2
sudo cp modules/imagick.so $DEST2
echo 'Update php.ini file at ' $(echo $(php --ini | grep 'Loaded Configuration File') | awk 'NF>1{print $NF}')
sudo echo 'extension="imagick.so"' >> $(echo $(php --ini | grep 'Loaded Configuration File') | awk 'NF>1{print $NF}')
cd ..
- name: Set Up imagick (php7.4)
if: ${{ matrix.php-versions == '7.4' }}
run: |
sudo apt-get -y install php-imagick

- name: PHP Show modules
run: php -m
- name: Set Up Imagick, FFmpeg & Exiftools
run: |
sudo apt-get update
sudo apt-get --fix-broken install
sudo apt-get -y install ffmpeg libimage-exiftool-perl libmagickwand-dev
- name: Get composer cache directory
id: composer-cache
Expand All @@ -109,11 +83,11 @@ jobs:
if: ${{ matrix.dependencies == 'beta' }}
run: perl -pi -e 's/^}$/,"minimum-stability":"beta"}/' composer.json

- name: Install Composer dependencies
- name: Install Composer dependencies (normal)
if: ${{ matrix.dependencies != 'low' }}
run: composer update --no-interaction

- name: Install Composer dependencies
- name: Install Composer dependencies (low)
if: ${{ matrix.dependencies == 'low' }}
run: composer update -vvv --prefer-lowest --prefer-stable --no-interaction

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ tests/log
vendor
composer.phar
.DS_Store
.idea
.phpunit.result.cache
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# [PHPExif v0.7.2](http://github.com/LycheeOrg/php-exif) [![Build Status](https://github.com/LycheeOrg/php-exif/workflows/Tests/badge.svg)] [![Coverage Status](https://codecov.io/gh/LycheeOrg/php-exif/branch/master/graph/badge.svg)](https://codecov.io/gh/LycheeOrg/php-exif) [![Code Climate](https://api.codeclimate.com/v1/badges/f15042d535274f36c5a2/maintainability)](https://codeclimate.com/github/LycheeOrg/php-exif/maintainability)
# [PHPExif v0.7.4](http://github.com/LycheeOrg/php-exif)

[![GitHub Release][release-shield]](https://github.com/LycheeOrg/php-exif/releases)
[![PHP 8.0 & 8.1][php-shield]](https://github.com/LycheeOrg/php-exif#installation-composer)
[![MIT License][license-shield]](https://github.com/LycheeOrg/php-exif/blob/master/LICENSE)
<br>
[![Build Status](https://github.com/LycheeOrg/php-exif/workflows/Tests/badge.svg)](https://github.com/LycheeOrg/php-exif/actions)
[![Coverage Status](https://codecov.io/gh/LycheeOrg/php-exif/branch/master/graph/badge.svg)](https://codecov.io/gh/LycheeOrg/php-exif)
[![Code Climate](https://api.codeclimate.com/v1/badges/f15042d535274f36c5a2/maintainability)](https://codeclimate.com/github/LycheeOrg/php-exif/maintainability)

PHPExif is a library which gives you easy access to the EXIF meta-data of an image or video.

Expand Down Expand Up @@ -47,7 +55,13 @@ Have a bug or a feature request? [Please open a new issue](https://github.com/Ly
* [tmp-hallenser](https://github.com/tmp-hallenser)
* [kamil4](https://github.com/kamil4)
* [ildyria](https://github.com/ildyria)
* [nagmat84](https://github.com/nagmat84)

## License

[MIT License](http://github.com/LycheeOrg/php-exif/blob/master/LICENSE)


[release-shield]: https://img.shields.io/github/release-pre/LycheeOrg/php-exif.svg
[php-shield]: https://img.shields.io/badge/PHP-8.0%20|%208.1-blue
[license-shield]: https://img.shields.io/github/license/LycheeOrg/Lychee.svg
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
],
"keywords": ["EXIF", "IPTC", "jpeg", "tiff", "exiftool", "FFmpeg", "FFprobe", "ImageMagick", "Imagick"],
"require": {
"php": ">=7.2",
"php": "^8.0",
"ext-fileinfo": "*",
"neitanod/forceutf8": "^2.0.4",
"php-ffmpeg/php-ffmpeg": "^0.17.0"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpmd/phpmd": "^2.9",
"phpunit/phpunit": "^9.3",
"sebastian/phpcpd": ">=4.1",
"friendsofphp/php-cs-fixer": ">=2.17",
"phpunit/phpunit": "^9.5.10",
"friendsofphp/php-cs-fixer": "^3.3",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"lib-exiftool": "Use perl lib exiftool as adapter",
"ext-exif": "Use exif PHP extension as adapter",
"FFmpeg": "Use FFmpeg/FFprobe as adapter",
"ImageMagick": "Use ImageMagick as adapter"
"ext-imagick": "Use ImageMagick as adapter",
"ext-mbstring": "Support UTC-16 characters in EXIF data with exif PHP extension"
},
"autoload": {
"psr-0": {
Expand Down
37 changes: 11 additions & 26 deletions lib/PHPExif/Adapter/AdapterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,10 @@
*/
abstract class AdapterAbstract implements AdapterInterface
{
/**
* @var string
*/
protected $hydratorClass = '\\PHPExif\\Hydrator\\Mutator';

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

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

/**
* @var string
*/
protected $mapperClass = '';
protected string $hydratorClass = '\\PHPExif\\Hydrator\\Mutator';
protected ?MapperInterface $mapper = null;
protected ?HydratorInterface $hydrator = null;
protected string $mapperClass = '';

/**
* Class constructor
Expand All @@ -63,7 +48,7 @@ public function __construct(array $options = array())
* @param \PHPExif\Mapper\MapperInterface $mapper
* @return \PHPExif\Adapter\AdapterInterface
*/
public function setMapper(MapperInterface $mapper)
public function setMapper(MapperInterface $mapper) : AdapterInterface
{
$this->mapper = $mapper;

Expand All @@ -75,7 +60,7 @@ public function setMapper(MapperInterface $mapper)
*
* @return \PHPExif\Mapper\MapperInterface
*/
public function getMapper()
public function getMapper() : MapperInterface
{
if (null === $this->mapper) {
// lazy load one
Expand All @@ -93,7 +78,7 @@ public function getMapper()
* @param \PHPExif\Hydrator\HydratorInterface $hydrator
* @return \PHPExif\Adapter\AdapterInterface
*/
public function setHydrator(HydratorInterface $hydrator)
public function setHydrator(HydratorInterface $hydrator) : AdapterInterface
{
$this->hydrator = $hydrator;

Expand All @@ -105,7 +90,7 @@ public function setHydrator(HydratorInterface $hydrator)
*
* @return \PHPExif\Hydrator\HydratorInterface
*/
public function getHydrator()
public function getHydrator() : HydratorInterface
{
if (null === $this->hydrator) {
// lazy load one
Expand All @@ -123,7 +108,7 @@ public function getHydrator()
* @param array $options
* @return \PHPExif\Reader\AdapterAbstract
*/
public function setOptions(array $options)
public function setOptions(array $options) : AdapterInterface
{
$hydrator = $this->getHydrator();
$hydrator->hydrate($this, $options);
Expand All @@ -134,12 +119,12 @@ public function setOptions(array $options)
/**
* Encodes an array of strings into UTF8
*
* @param array $data
* @param array|string $data
* @return array
*/
// @codeCoverageIgnoreStart
// this is fine because we use it directly in our tests for Exiftool and Native
public function convertToUTF8($data)
public function convertToUTF8($data) : array|string
{
if (is_array($data)) {
foreach ($data as $k => $v) {
Expand Down
4 changes: 3 additions & 1 deletion lib/PHPExif/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace PHPExif\Adapter;

use PHPExif\Exif;

/**
* PHP Exif Reader Adapter
*
Expand All @@ -29,5 +31,5 @@ interface AdapterInterface
* @return \PHPExif\Exif Instance of Exif object with data
* @throws \RuntimeException If the EXIF data could not be read
*/
public function getExifFromFile($file);
public function getExifFromFile(string $file) : Exif|false;
}
46 changes: 20 additions & 26 deletions lib/PHPExif/Adapter/Exiftool.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,11 @@ class Exiftool extends AdapterAbstract

/**
* Path to the exiftool binary
*
* @var string
*/
protected $toolPath;

/**
* @var boolean
*/
protected $numeric = true;

/**
* @var array
*/
protected $encoding = array();

/**
* @var string
*/
protected $mapperClass = '\\PHPExif\\Mapper\\Exiftool';
protected string $toolPath = '';
protected bool $numeric = true;
protected array $encoding = array();
protected string $mapperClass = '\\PHPExif\\Mapper\\Exiftool';

/**
* Setter for the exiftool binary path
Expand All @@ -56,7 +42,7 @@ class Exiftool extends AdapterAbstract
* @return \PHPExif\Adapter\Exiftool Current instance
* @throws \InvalidArgumentException When path is invalid
*/
public function setToolPath($path)
public function setToolPath(string $path) : Exiftool
{
if (!file_exists($path)) {
throw new InvalidArgumentException(
Expand All @@ -75,7 +61,7 @@ public function setToolPath($path)
/**
* @param boolean $numeric
*/
public function setNumeric($numeric)
public function setNumeric(bool $numeric) : void
{
$this->numeric = $numeric;
}
Expand All @@ -84,7 +70,7 @@ public function setNumeric($numeric)
* @see http://www.sno.phy.queensu.ca/~phil/exiftool/faq.html#Q10
* @param array $encoding encoding parameters in an array eg. ["exif" => "UTF-8"]
*/
public function setEncoding($encoding)
public function setEncoding(array $encoding) : void
{
$possible_keys = array("exif", "iptc", "id3", "photoshop", "quicktime",);
$possible_values = array("UTF8", "cp65001", "UTF-8", "Thai", "cp874", "Latin", "cp1252",
Expand All @@ -106,7 +92,7 @@ public function setEncoding($encoding)
*
* @return string
*/
public function getToolPath()
public function getToolPath() : string
{
if (empty($this->toolPath)) {
// Do not use "which": not available on sh
Expand All @@ -125,7 +111,7 @@ public function getToolPath()
* @return \PHPExif\Exif Instance of Exif object with data
* @throws \RuntimeException If the EXIF data could not be read
*/
public function getExifFromFile($file)
public function getExifFromFile(string $file) : Exif
{
$encoding = '';
if (!empty($this->encoding)) {
Expand All @@ -134,6 +120,9 @@ public function getExifFromFile($file)
$encoding .= escapeshellarg($key).'='.escapeshellarg($value);
}
}
/**
* @var string
*/
$result = $this->getCliOutput(
sprintf(
'%1$s%3$s -j -a -G1 %5$s -c %4$s %2$s',
Expand All @@ -145,7 +134,9 @@ public function getExifFromFile($file)
)
);

// Force UTF8 encoding
/**
* @var string
*/
$result = $this->convertToUTF8($result);

$data = json_decode($result, true);
Expand All @@ -158,6 +149,9 @@ public function getExifFromFile($file)
}

// map the data:
/**
* @var \PHPExif\Mapper\Exiftool
*/
$mapper = $this->getMapper();
$mapper->setNumeric($this->numeric);
$mappedData = $mapper->mapRawData(reset($data));
Expand All @@ -175,10 +169,10 @@ public function getExifFromFile($file)
* Returns the output from given cli command
*
* @param string $command
* @return mixed
* @return string|false
* @throws RuntimeException If the command can't be executed
*/
protected function getCliOutput($command)
protected function getCliOutput(string $command) : string|false
{
$descriptorspec = array(
0 => array('pipe', 'r'),
Expand Down
Loading

0 comments on commit 458b697

Please sign in to comment.