-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fb8878
commit 6b11023
Showing
3 changed files
with
38 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
namespace Intervention\MimeSniffer; | ||
|
||
use Intervention\MimeSniffer\Interfaces\TypeInterface; | ||
use InvalidArgumentException; | ||
use RuntimeException; | ||
|
||
class MimeSniffer | ||
{ | ||
|
@@ -16,26 +18,35 @@ class MimeSniffer | |
protected string $content; | ||
|
||
/** | ||
* Universal factory method | ||
* Create new instance | ||
* | ||
* @param mixed $content | ||
* @return MimeSniffer | ||
* @return void | ||
*/ | ||
public static function create(mixed $content): self | ||
public function __construct(mixed $content = null) | ||
{ | ||
if (is_string($content) && file_exists($content)) { | ||
return self::createFromFilename($content); | ||
$this->setFromFilename($content); | ||
} | ||
|
||
if (is_string($content)) { | ||
return self::createFromString($content); | ||
$this->setFromString($content); | ||
} | ||
|
||
if (is_resource($content)) { | ||
return self::createFromPointer($content); | ||
$this->setFromPointer($content); | ||
} | ||
} | ||
|
||
return new self(); | ||
/** | ||
* Universal factory method | ||
* | ||
* @param mixed $content | ||
* @return MimeSniffer | ||
*/ | ||
public static function create(mixed $content): self | ||
{ | ||
return new self($content); | ||
} | ||
|
||
/** | ||
|
@@ -113,6 +124,10 @@ public static function createFromPointer($pointer): self | |
*/ | ||
public function setFromPointer($pointer): self | ||
{ | ||
if (!is_resource($pointer)) { | ||
throw new InvalidArgumentException('Argument #1 $pointer must be of type resource.'); | ||
Check failure on line 128 in src/MimeSniffer.php
|
||
} | ||
|
||
$this->setFromString(fread($pointer, 1024)); | ||
|
||
return $this; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters