1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 16:50:07 +02:00

Move file pointer creation to trait

This commit is contained in:
Oliver Vogel
2023-11-12 10:58:34 +01:00
parent 2960c31611
commit 5e3c6973df
3 changed files with 23 additions and 8 deletions

View File

@@ -7,11 +7,14 @@ use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanBuildFilePointer;
use Intervention\MimeSniffer\MimeSniffer; use Intervention\MimeSniffer\MimeSniffer;
use Intervention\MimeSniffer\AbstractType; use Intervention\MimeSniffer\AbstractType;
abstract class AbstractDecoder implements DecoderInterface abstract class AbstractDecoder implements DecoderInterface
{ {
use CanBuildFilePointer;
public function __construct(protected ?AbstractDecoder $successor = null) public function __construct(protected ?AbstractDecoder $successor = null)
{ {
// //
@@ -49,9 +52,7 @@ abstract class AbstractDecoder implements DecoderInterface
} }
try { try {
$pointer = fopen('php://temp', 'rw'); $pointer = $this->buildFilePointer($image_data);
fputs($pointer, $image_data);
rewind($pointer);
$data = @exif_read_data($pointer, null, true); $data = @exif_read_data($pointer, null, true);
fclose($pointer); fclose($pointer);
} catch (Exception $e) { } catch (Exception $e) {

View File

@@ -4,9 +4,12 @@ namespace Intervention\Image;
use Intervention\Image\Exceptions\NotWritableException; use Intervention\Image\Exceptions\NotWritableException;
use Intervention\Image\Interfaces\GenericDataInterface; use Intervention\Image\Interfaces\GenericDataInterface;
use Intervention\Image\Traits\CanBuildFilePointer;
class GenericData implements GenericDataInterface class GenericData implements GenericDataInterface
{ {
use CanBuildFilePointer;
/** /**
* Create new instance * Create new instance
* *
@@ -50,11 +53,7 @@ class GenericData implements GenericDataInterface
*/ */
public function toFilePointer() public function toFilePointer()
{ {
$pointer = fopen('php://temp', 'rw'); return $this->buildFilePointer($this->toString());
fputs($pointer, $this->toString());
rewind($pointer);
return $pointer;
} }
/** /**

View File

@@ -0,0 +1,15 @@
<?php
namespace Intervention\Image\Traits;
trait CanBuildFilePointer
{
public function buildFilePointer(string $data)
{
$pointer = fopen('php://temp', 'rw');
fputs($pointer, $data);
rewind($pointer);
return $pointer;
}
}