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

Detection for vips 1 not longer works #46

Merged
merged 12 commits into from
Dec 11, 2024
3 changes: 2 additions & 1 deletion .github/workflows/settings/both.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extensions": "",
"ini_values": "ffi.enable=true, zend.max_allowed_stack_size=-1",
"aptinstall": "libvips-dev"
}
}
3 changes: 2 additions & 1 deletion .github/workflows/settings/ffi-only.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extensions": "",
"ini_values": "ffi.enable=true, zend.max_allowed_stack_size=-1",
"aptinstall": "libvips"
}
}
3 changes: 2 additions & 1 deletion .github/workflows/settings/vips-only.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extensions": ":ffi",
"ini_values": "",
"aptinstall": "libvips-dev"
}
}
14 changes: 11 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false

matrix:
php: ['7.4', '8.0', '8.1']
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
settings: ['both', 'vips-only', 'ffi-only']
COMPOSER_FLAGS: ['']

Expand Down Expand Up @@ -50,11 +50,14 @@ jobs:
with:
php-version: ${{ matrix.php }}
tools: composer:v2
ini-values: ${{fromJson(env.SETTINGS_JSON).ini_values}}
coverage: none
extensions: ${{fromJson(env.SETTINGS_JSON).extensions}}

- name: Install vips
run: sudo apt install -y ${{fromJson(env.SETTINGS_JSON).aptinstall}} --no-install-recommends
run: |
sudo apt update
sudo apt install -y ${{fromJson(env.SETTINGS_JSON).aptinstall}} --no-install-recommends

- name: Install vips extension
run: sudo pecl install vips
Expand All @@ -68,11 +71,16 @@ jobs:
run: |
composer update --prefer-dist --no-interaction --no-progress --no-ansi ${{ matrix.COMPOSER_FLAGS || '' }}

- name: Debug PHP settings
run: |
php -r 'echo "Has VIPS Extension: " . (extension_loaded("vips") ? "true" : "false") . PHP_EOL; echo "Has FFI Extension: " . (extension_loaded("ffi") ? "true" : "false") . PHP_EOL; echo "Has FFI Class: " . (class_exists(FFI::class) ? "true" : "false") . PHP_EOL; echo "Has FFI Enabled: " . (ini_get("ffi.enable") === "1" ? "true" : "false") . PHP_EOL; echo "Has zend.max_allowed_stack_size correct: " . (ini_get("zend.max_allowed_stack_size") === "-1" ? "true" : "false") . PHP_EOL;'

Comment on lines +74 to +77
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will keep this may helpful in future?

- name: PHPStan
run: composer phpstan

- name: PHPUnit
run: composer phpunit

- name: Composer audit
run: composer audit
run: |
composer audit --no-dev
11 changes: 10 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@
'strict_param' => true,
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'phpdoc_no_empty_return' => false,
'no_superfluous_phpdoc_tags' => true,
'no_superfluous_phpdoc_tags' => false,
'fully_qualified_strict_types' => false,
'native_function_invocation' => false,
'no_null_property_initialization' => false,
'phpdoc_trim' => false,
'blank_line_before_statement' => false,
'phpdoc_add_missing_param_annotation' => false,
'modernize_strpos' => false,
'trailing_comma_in_multiline' => false,
'no_whitespace_in_blank_line' => false,
Comment on lines +33 to +42
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to reduce too much changes inside this PR but still allow to test against PHP 8.4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter changes are totally fine for me. That doesn't change functionality

])
->setFinder(
$finder
Expand Down
6 changes: 3 additions & 3 deletions lib/Imagine/Vips/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function pasteVipsImage(VipsImage $vips, PointInterface $start, $alpha =
return $this->vips->copyMemory();
}

public static function generateImage(BoxInterface $size, ColorInterface $color = null)
public static function generateImage(BoxInterface $size, ?ColorInterface $color = null)
{
$width = $size->getWidth();
$height = $size->getHeight();
Expand Down Expand Up @@ -385,7 +385,7 @@ public function applyToLayers(callable $callback)
*
* @return ImageInterface
*/
public function rotate($angle, ColorInterface $background = null)
public function rotate($angle, ?ColorInterface $background = null)
{
$color = $background ?: $this->palette->color('fff');
try {
Expand Down Expand Up @@ -768,7 +768,7 @@ public static function getColorArrayAlpha(ColorInterface $color, $bands = 4): ar
*
* @return ImageInterface
*/
public function convertToAlternative(ImagineInterface $imagine = null, array $tiffOptions = [], $asTiff = false)
public function convertToAlternative(?ImagineInterface $imagine = null, array $tiffOptions = [], $asTiff = false)
{
if (null === $imagine) {
$oldMetaReader = null;
Expand Down
23 changes: 14 additions & 9 deletions lib/Imagine/Vips/Imagine.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function open($path, $loadOptions = [])
/**
* {@inheritdoc}
*/
public function create(BoxInterface $size, ColorInterface $color = null)
public function create(BoxInterface $size, ?ColorInterface $color = null)
{
$vips = Image::generateImage($size, $color);

Expand Down Expand Up @@ -202,20 +202,25 @@ public static function createPalette(VipsImage $vips)
public static function hasVipsInstalled()
{
try {
// this method only exists in php-vips 2.0
if (class_exists(FFI::class)) {
// if ffi extension is not installed, we can't use php-vips
if (!\extension_loaded('ffi')) {
return false;
}
// if we're still on php-vips 1.0, check if 'vips' extension is installed
if (\extension_loaded('vips')) {
return true;
}

if (class_exists(FFI::class)
// if ffi extension is not installed, we can't use php-vips 2
&& extension_loaded('ffi')
// preload is not yet supported by vips see https://github.com/libvips/php-vips
&& '1' === \ini_get('ffi.enable')
) {
// this will throw an exception, if libvips is not installed
// will return false in the catch block
Config::version();

return true;
}
// if we're still on php-vips 1.0, check if 'vips' extension is installed
return \extension_loaded('vips');

return false;
} catch (\Exception $e) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Imagine/Vips/Layers.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Layers extends AbstractLayers
*/
private $count = 0;

public function __construct(Image $image, self $layers = null)
public function __construct(Image $image, ?self $layers = null)
{
$this->image = $image;

Expand Down
Loading