Skip to content

Commit c83e115

Browse files
committed
Image::$formats changed to const
1 parent 751d98a commit c83e115

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Utils/Image.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Image
115115

116116
public const EMPTY_GIF = "GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;";
117117

118-
private static $formats = [self::JPEG => 'jpeg', self::PNG => 'png', self::GIF => 'gif', self::WEBP => 'webp'];
118+
private const FORMATS = [self::JPEG => 'jpeg', self::PNG => 'png', self::GIF => 'gif', self::WEBP => 'webp'];
119119

120120
/** @var resource */
121121
private $image;
@@ -148,7 +148,7 @@ public static function fromFile(string $file, int &$detectedFormat = null)
148148
}
149149

150150
$detectedFormat = @getimagesize($file)[2]; // @ - files smaller than 12 bytes causes read error
151-
if (!isset(self::$formats[$detectedFormat])) {
151+
if (!isset(self::FORMATS[$detectedFormat])) {
152152
$detectedFormat = null;
153153
throw new UnknownImageFileException(is_file($file) ? "Unknown type of file '$file'." : "File '$file' not found.");
154154
}
@@ -171,7 +171,7 @@ public static function fromString(string $s, int &$detectedFormat = null)
171171

172172
if (func_num_args() > 1) {
173173
$tmp = @getimagesizefromstring($s)[2]; // @ - strings smaller than 12 bytes causes read error
174-
$detectedFormat = isset(self::$formats[$tmp]) ? $tmp : null;
174+
$detectedFormat = isset(self::FORMATS[$tmp]) ? $tmp : null;
175175
}
176176

177177
return new static(Callback::invokeSafe('imagecreatefromstring', [$s], function (string $message): void {
@@ -484,7 +484,7 @@ public function place(self $image, $left = 0, $top = 0, int $opacity = 100)
484484
public function save(string $file, int $quality = null, int $type = null): void
485485
{
486486
if ($type === null) {
487-
$extensions = array_flip(self::$formats) + ['jpg' => self::JPEG];
487+
$extensions = array_flip(self::FORMATS) + ['jpg' => self::JPEG];
488488
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
489489
if (!isset($extensions[$ext])) {
490490
throw new Nette\InvalidArgumentException("Unsupported file extension '$ext'.");
@@ -529,7 +529,7 @@ public function __toString(): string
529529
*/
530530
public function send(int $type = self::JPEG, int $quality = null): void
531531
{
532-
if (!isset(self::$formats[$type])) {
532+
if (!isset(self::FORMATS[$type])) {
533533
throw new Nette\InvalidArgumentException("Unsupported image type '$type'.");
534534
}
535535
header('Content-Type: ' . image_type_to_mime_type($type));

0 commit comments

Comments
 (0)