Skip to content

Commit

Permalink
Merge pull request #96 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mirko-pagliai authored Jan 5, 2024
2 parents 26172dc + 6af8eb5 commit cbf6140
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 63 deletions.
27 changes: 11 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2']
php-version: ['8.1', '8.2', '8.3']
prefer-lowest: ['']
thumber-driver: ['imagick', 'gd']
include:
- php-version: '7.4'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '8.0'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '8.1'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '8.2'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '7.4'
thumber-driver: 'gd'
- php-version: '8.3'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -70,13 +65,13 @@ jobs:
if [[ ${{ matrix.thumber-driver }} == 'gd' ]] || ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
vendor/bin/phpunit --exclude-group imageEquals
elif [[ ${{ matrix.php-version }} == '8.0' ]]; then
export XDEBUG_MODE=coverage && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
export XDEBUG_MODE=coverage && vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Submit code coverage
if: matrix.php-version == '8.1'
if: matrix.php-version == '8.2'
uses: codecov/codecov-action@v3

cs-stan:
Expand All @@ -89,7 +84,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: cs2pr

Expand All @@ -108,7 +103,7 @@ jobs:

- name: Run psalm
if: success() || failure()
run: vendor/bin/psalm --output-format=github --php-version=8.1
run: vendor/bin/psalm --output-format=github --php-version=8.2

- name: Run phpstan
if: success() || failure()
Expand All @@ -117,11 +112,11 @@ jobs:

testsuite-windows:
runs-on: windows-2019
name: Windows - PHP 7.4
name: Windows - PHP 8.2

env:
EXTENSIONS: mbstring, intl, gd
PHP_VERSION: '7.4'
PHP_VERSION: '8.2'

steps:
- uses: actions/checkout@v3
Expand All @@ -147,4 +142,4 @@ jobs:
run: composer update

- name: Run PHPUnit
run: vendor/bin/phpunit --verbose --exclude-group imageEquals
run: vendor/bin/phpunit --exclude-group imageEquals
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# 1.x branch
## 1.12 branch
### 1.12.0
* requires at least PHP 8.1, CakePHP 5.0 and PHPUnit 10;
* added tests for PHP 8.3.

## 1.11 branch
### 1.11.3
* removed some exception classes already deprecated or scheduled for deprecation.
Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ even a coffee is enough! Thank you.

***

* [Requirements and supported formats](#requirements-and-supported-formats)
* [Installation](#installation)
* [Requirements and supported formats](#requirements-and-supported-formats)
* [Installation](#installation)
+ [Installation on older CakePHP and PHP versions](#installation-on-older-cakephp-and-php-versions)
- [For PHP 7.2 or later](#for-php-72-or-later)
- [For PHP 5.6 and CakePHP 3 or later](#for-php-56-and-cakephp-3-or-later)
* [Configuration](#configuration)
- [For PHP 8.0 and CakePHP 4 or later](#for-php-80-and-cakephp-4-or-later)
- [For PHP 7.2 or later](#for-php-72-or-later)
- [For PHP 5.6 and CakePHP 3 or later](#for-php-56-and-cakephp-3-or-later)
* [Configuration](#configuration)
+ [Configuration values](#configuration-values)
* [How to use](#how-to-use)
* [Testing](#testing)
* [Versioning](#versioning)
* [How to use](#how-to-use)
* [Testing](#testing)
* [Versioning](#versioning)

## Requirements and supported formats
*cakephp-thumber* requires GD Library (>=2.0) **or** Imagick PHP extension
Expand Down Expand Up @@ -82,12 +83,25 @@ $ mkdir tmp/thumbs && chmod 775 tmp/thumbs
If you want to use a different directory, read the [Configuration](#configuration) section.

### Installation on older CakePHP and PHP versions
Recent packages and the master branch require at least CakePHP 4.0 and PHP 7.4
Recent packages and the master branch require at least CakePHP 5.0 and PHP 8.1
and the current development of the code is based on these and later versions of
CakePHP and PHP.
However, there are still some branches compatible with previous versions of
CakePHP and PHP.

#### For PHP 8.0 and CakePHP 4 or later
The [cakephp4](//github.com/mirko-pagliai/cakephp-thumber/tree/cakephp4) branch
requires at least PHP `>=7.4` and CakePHP `^4.4`.

In this case, you can install the package as well:
```bash
$ composer require --prefer-dist mirko-pagliai/cakephp-thumber:dev-cakephp4
```

Note that the `cakephp4` branch will no longer be updated as of January 5, 2024,
except for security patches, and it matches the
[1.11.3](//github.com/mirko-pagliai/cakephp-thumber/releases/tag/1.11.3) version.

#### For PHP 7.2 or later
The [php7.2](//github.com/mirko-pagliai/cakephp-thumber/tree/php7.2) branch
requires at least PHP 7.2.
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.1",
"ext-fileinfo": "*",
"cakephp/cakephp": "^4.4",
"cakephp/cakephp": "^5.0",
"intervention/image": "^2.4",
"mirko-pagliai/php-thumber": "~1.5.3"
"mirko-pagliai/php-tools": "~1.9.3",
"mirko-pagliai/php-thumber": "~1.6.1"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "^9.1|^9.5",
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.1.0 <=10.5.3",
"phpstan/phpstan": "^1.10.38",
"vimeo/psalm": "^5.15.0"
},
Expand Down Expand Up @@ -47,8 +48,8 @@
"cs-fix": "phpcbf --standard=phpcs.xml.dist",
"test": "rm -f -r /tmp/cake* && phpunit",
"coverage": "XDEBUG_MODE=coverage phpunit --coverage-html=coverage",
"phpstan": "phpstan.phar analyse",
"psalm": "psalm.phar --php-version=8.0",
"phpstan": "phpstan analyse",
"psalm": "psalm --php-version=8.0",
"stan": [
"@phpstan",
"@psalm"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Thumber\Cake\Middleware\ThumbnailMiddleware;

/** @var \Cake\Routing\RouteBuilder $routes */
$routes->plugin('Thumber', ['path' => '/thumb'], function (RouteBuilder $routes) {
$routes->plugin('Thumber', ['path' => '/thumb'], function (RouteBuilder $routes): void {
$routes->registerMiddleware('thumbnail', new ThumbnailMiddleware());

if (!$routes->nameExists('thumb')) {
Expand Down
8 changes: 5 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
>
<coverage>
<coverage/>

<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
</source>

<testsuites>
<testsuite name="cakephp-thumber Test Cases">
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ClearAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Cake\Console\ConsoleOptionParser;
use Exception;
use Thumber\Cake\Utility\ThumbManager;
use function Cake\I18n\__d;

/**
* Clears all thumbnails
Expand Down Expand Up @@ -56,7 +57,7 @@ public function execute(Arguments $args, ConsoleIo $io): void
{
try {
$count = $this->getThumbManager()->clearAll();
} catch (Exception $e) {
} catch (Exception) {
$io->err(__d('thumber', 'Error deleting thumbnails'));
$this->abort();
}
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Cake\Console\ConsoleOptionParser;
use Exception;
use Thumber\Cake\Utility\ThumbManager;
use function Cake\I18n\__d;

/**
* Clears all thumbnails that have been generated from an image path
Expand Down Expand Up @@ -60,7 +61,7 @@ public function execute(Arguments $args, ConsoleIo $io): void
{
try {
$count = $this->getThumbManager()->clear((string)$args->getArgument('path'));
} catch (Exception $e) {
} catch (Exception) {
$io->err(__d('thumber', 'Error deleting thumbnails'));
$this->abort();
}
Expand Down
11 changes: 6 additions & 5 deletions src/Middleware/ThumbnailMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Psr\Http\Server\RequestHandlerInterface;
use Thumber\Cake\Http\Exception\ThumbNotFoundException;
use Tools\Filesystem;
use function Cake\I18n\__d;

/**
* Handles serving thumbnails
Expand All @@ -43,12 +44,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
throw new ThumbNotFoundException(__d('thumber', "File `{0}` doesn't exist", $file));
}

$response = new Response();
$response = $response->withModified(filemtime($file) ?: 0);
if ($response->isNotModified($request)) {
return $response->withNotModified();
$Response = new Response();
$Response = $Response->withModified(filemtime($file) ?: 0);
if ($Response->isNotModified($request)) {
return $Response->withNotModified();
}

return $response->withFile($file)->withType(mime_content_type($file) ?: '');
return $Response->withFile($file)->withType(mime_content_type($file) ?: '');
}
}
1 change: 1 addition & 0 deletions src/Utility/ThumbCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Cake\Routing\Router;
use LogicException;
use Thumber\ThumbCreator as BaseThumbCreator;
use function Cake\I18n\__d;

/**
* Utility to create a thumb.
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/ThumbManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Cake\Core\Plugin;
use Thumber\ThumbManager as BaseThumbManager;
use Tools\Filesystem;
use function Cake\Core\pluginSplit;

/**
* A utility to manage thumbnails
Expand Down Expand Up @@ -51,7 +52,6 @@ public static function resolveFilePath(string $path): string
* @param string $path Path of the original image
* @param bool $sort Whether results should be sorted
* @return array<string, string>
* @throws \Tools\Exception\NotReadableException
*/
public function get(string $path, bool $sort = false): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/ThumbHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Cake\View\Helper;
use LogicException;
use Thumber\Cake\Utility\ThumbCreator;
use function Cake\I18n\__d;

/**
* Thumb Helper.
Expand All @@ -40,7 +41,7 @@ class ThumbHelper extends Helper
* Helpers
* @var array
*/
public $helpers = ['Html'];
public array $helpers = ['Html'];

/**
* Magic method. It dynamically calls all other methods.
Expand All @@ -53,7 +54,6 @@ class ThumbHelper extends Helper
* @param array $params Array of params for the method
* @return string
* @throws \LogicException
* @throws \Tools\Exception\MethodNotExistsException
* @see https://github.com/mirko-pagliai/cakephp-thumber/wiki/How-to-use-the-helper
* @since 1.4.0
*/
Expand Down
4 changes: 0 additions & 4 deletions tests/TestCase/Command/ClearAllCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);

/**
Expand Down Expand Up @@ -40,8 +39,6 @@ class ClearAllCommandTest extends TestCase
*/
public function testExecute(): void
{
$this->useCommandRunner();

$command = 'thumber.clear_all -v';

$this->createSomeThumbs();
Expand All @@ -56,7 +53,6 @@ public function testExecute(): void
}

/**
* Test for `execute()` method, on failure
* @test
* @uses \Thumber\Cake\Command\ClearAllCommand::execute()
*/
Expand Down
4 changes: 0 additions & 4 deletions tests/TestCase/Command/ClearCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);

/**
Expand Down Expand Up @@ -40,8 +39,6 @@ class ClearCommandTest extends TestCase
*/
public function testExecute(): void
{
$this->useCommandRunner();

$command = 'thumber.clear -v';

$this->createSomeThumbs();
Expand All @@ -67,7 +64,6 @@ public function testExecute(): void
}

/**
* Test for `execute()` method, on failure
* @test
* @uses \Thumber\Cake\Command\ClearCommand::execute()
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/Middleware/ThumbnailMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);

/**
Expand Down Expand Up @@ -56,6 +55,9 @@ public function testThumb(): void
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
];
if (version_compare(PHP_VERSION, '8.3', '>=')) {
$extensions['bmp'] = 'image/bmp';
}
}

$ThumbHelper = new ThumbHelper(new View());
Expand Down Expand Up @@ -84,7 +86,7 @@ public function testThumb(): void
$this->assertResponseCode(304);

//Deletes the last thumbnail file. Now the `Last-Modified` header is different
@unlink($thumb);
unlink($thumb);
sleep(1);
(new ThumbCreator($file))->resize(200)->save();
$this->get($url);
Expand Down
Loading

0 comments on commit cbf6140

Please sign in to comment.