Skip to content
Snippets Groups Projects
Verified Commit 54a3f555 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3173031 by Spokje, andypost, mondrake: Clean-up...

Issue #3173031 by Spokje, andypost, mondrake: Clean-up \Drupal\system\Plugin\ImageToolkit\GDToolkit when core require php 8.0

(cherry picked from commit 7f337ca7)
parent 88864fe0
No related branches found
No related tags found
24 merge requests!8506Draft: Issue #3456536 by ibrahim tameme,!5646Issue #3350972 by nod_: [random test failure]...,!5600Issue #3350972 by nod_: [random test failure]...,!5343Issue #3305066 by quietone, Rename RedirectLeadingSlashesSubscriber,!4350Issue #3307718: Implement xxHash for non-cryptographic use-cases,!3603#ISSUE 3346218 Add a different message on edit comment,!3555Issue #2473873: Views entity operations lack cacheability support, resulting in incorrect dropbuttons,!3494Issue #3327018 by Spokje, longwave, xjm, mondrake: Update PHPStan to 1.9.3 and...,!3410Issue #3340128: UserLoginForm::submitForm has some dead code,!3389Issue #3325184 by Spokje, andypost, xjm, smustgrave: $this->configFactory is...,!3381Issue #3332363: Refactor Claro's menus-and-lists stylesheet,!3307Issue #3326193: CKEditor 5 can grow past the viewport when there is a lot of content,!3236Issue #3332419: Refactor Claro's messages stylesheet,!3231Draft: Issue #3049525 by longwave, fougere, larowlan, kim.pepper, AaronBauman, Wim...,!3212Issue #3294003: Refactor Claro's entity-meta stylesheet,!3194Issue #3330981: Fix PHPStan L1 error "Relying on entity queries to check access by default is deprecated...",!3143Issue #3313342: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 LayoutBuilderUiCacheContext.php on line 28,!3024Issue #3307509: Empty option for views bulk form,!2972Issue #1845004: Replace custom password hashing library with PHP 5.5 password_hash(),!2719Issue #3110137: Remove Classy from core.,!2688Issue #3261452: [PP-1] Remove tracker module from core,!2437Issue #3238257 by hooroomoo, Wim Leers: Fragment link pointing to <textarea>...,!2296Issue #3100732: Allow specifying `meta` data on JSON:API objects,!1626Issue #3256642: Make life better for database drivers that extend another database driver
......@@ -30,7 +30,7 @@ class GDToolkit extends ImageToolkitBase {
/**
* A GD image resource.
*
* @var resource|\GdImage|null
* @var \GdImage|null
*/
protected $resource = NULL;
......@@ -96,19 +96,6 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
$this->fileSystem = $file_system;
}
/**
* Destructs a GDToolkit object.
*
* Frees memory associated with a GD image resource.
*
* @todo Remove the method for PHP 8.0+ https://www.drupal.org/node/3173031
*/
public function __destruct() {
if (is_resource($this->resource)) {
imagedestroy($this->resource);
}
}
/**
* {@inheritdoc}
*/
......@@ -128,20 +115,15 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* Sets the GD image resource.
*
* @param resource|\GdImage $resource
* @param \GdImage $resource
* The GD image resource.
*
* @return $this
* An instance of the current toolkit object.
*/
public function setResource($resource) {
if (!(is_object($resource) && $resource instanceof \GdImage)) {
// Since PHP 8.0 resource should be \GdImage, for previous versions it
// should be resource.
// @TODO clean-up for PHP 8.0+ https://www.drupal.org/node/3173031
if (!is_resource($resource) || get_resource_type($resource) != 'gd') {
throw new \InvalidArgumentException('Invalid resource argument');
}
if (!$resource instanceof \GdImage) {
throw new \InvalidArgumentException('Invalid resource argument');
}
$this->preLoadInfo = NULL;
$this->resource = $resource;
......@@ -151,12 +133,11 @@ public function setResource($resource) {
/**
* Retrieves the GD image resource.
*
* @return resource|\GdImage|null
* @return \GdImage|null
* The GD image resource, or NULL if not available.
*/
public function getResource() {
// @TODO clean-up for PHP 8.0+ https://www.drupal.org/node/3173031
if (!(is_resource($this->resource) || (is_object($this->resource) && $this->resource instanceof \GdImage))) {
if (!$this->resource) {
$this->load();
}
return $this->resource;
......
......@@ -436,39 +436,6 @@ public function testManipulations() {
$this->assertTrue($image->isValid(), 'CreateNew with valid arguments validates the Image.');
}
/**
* Tests that GD resources are freed from memory.
*
* @todo Remove the method for PHP 8.0+ https://www.drupal.org/node/3179058
*/
public function testResourceDestruction() {
if (PHP_VERSION_ID >= 80000) {
$this->markTestSkipped('In PHP8 resources are no longer used. \GdImage objects are used instead. These will be garbage collected like the regular objects they are.');
}
// Test that an Image object going out of scope releases its GD resource.
$image = $this->imageFactory->get('core/tests/fixtures/files/image-test.png');
$res = $image->getToolkit()->getResource();
$this->assertIsResource($res);
$image = NULL;
// @todo In https://www.drupal.org/node/3133236 convert this to
// $this->assertIsNotResource($res).
$this->assertFalse(is_resource($res), 'Image resource was destroyed after losing scope.');
// Test that 'create_new' operation does not leave orphaned GD resources.
$image = $this->imageFactory->get('core/tests/fixtures/files/image-test.png');
$old_res = $image->getToolkit()->getResource();
// Check if resource has been created successfully.
$this->assertIsResource($old_res);
$image->createNew(20, 20);
$new_res = $image->getToolkit()->getResource();
// Check if the original resource has been destroyed.
// @todo In https://www.drupal.org/node/3133236 convert this to
// $this->assertIsNotResource($old_res).
$this->assertFalse(is_resource($old_res));
// Check if a new resource has been created successfully.
$this->assertIsResource($new_res);
}
/**
* Tests for GIF images with transparency.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment