mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 08:40:33 +02:00
Move file pointer creation to trait
This commit is contained in:
@@ -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) {
|
||||||
|
@@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
15
src/Traits/CanBuildFilePointer.php
Normal file
15
src/Traits/CanBuildFilePointer.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user