Skip to content

Commit

Permalink
Move file pointer creation to trait
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Nov 12, 2023
1 parent 2960c31 commit 5e3c697
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/Drivers/Abstract/Decoders/AbstractDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanBuildFilePointer;
use Intervention\MimeSniffer\MimeSniffer;
use Intervention\MimeSniffer\AbstractType;

abstract class AbstractDecoder implements DecoderInterface
{
use CanBuildFilePointer;

public function __construct(protected ?AbstractDecoder $successor = null)
{
//
Expand Down Expand Up @@ -49,9 +52,7 @@ protected function decodeExifData(string $image_data): array
}

try {
$pointer = fopen('php://temp', 'rw');
fputs($pointer, $image_data);
rewind($pointer);
$pointer = $this->buildFilePointer($image_data);
$data = @exif_read_data($pointer, null, true);
fclose($pointer);
} catch (Exception $e) {
Expand Down
9 changes: 4 additions & 5 deletions src/GenericData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Intervention\Image\Exceptions\NotWritableException;
use Intervention\Image\Interfaces\GenericDataInterface;
use Intervention\Image\Traits\CanBuildFilePointer;

class GenericData implements GenericDataInterface
{
use CanBuildFilePointer;

/**
* Create new instance
*
Expand Down Expand Up @@ -50,11 +53,7 @@ public function toString(): string
*/
public function toFilePointer()
{
$pointer = fopen('php://temp', 'rw');
fputs($pointer, $this->toString());
rewind($pointer);

return $pointer;
return $this->buildFilePointer($this->toString());
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/Traits/CanBuildFilePointer.php
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 5e3c697

Please sign in to comment.