Selaa lähdekoodia

Update Core\Files

Visman 3 vuotta sitten
vanhempi
commit
3acbe21fb0
1 muutettua tiedostoa jossa 25 lisäystä ja 7 poistoa
  1. 25 7
      app/Core/Files.php

+ 25 - 7
app/Core/Files.php

@@ -10,6 +10,7 @@ declare(strict_types=1);
 
 
 namespace ForkBB\Core;
 namespace ForkBB\Core;
 
 
+use ForkBB\Core\Container;
 use ForkBB\Core\File;
 use ForkBB\Core\File;
 use ForkBB\Core\Image;
 use ForkBB\Core\Image;
 use ForkBB\Core\Image\DefaultDriver;
 use ForkBB\Core\Image\DefaultDriver;
@@ -19,6 +20,12 @@ use RuntimeException;
 
 
 class Files
 class Files
 {
 {
+    /**
+     * Контейнер
+     * @var Container
+     */
+    protected $c;
+
     /**
     /**
      * Максимальный размер для картинок
      * Максимальный размер для картинок
      * @var int
      * @var int
@@ -848,15 +855,18 @@ class Files
         'image/avif' => 'avif',
         'image/avif' => 'avif',
     ];
     ];
 
 
-    public function __construct(/* string|int */ $maxFileSize, /* string|int */ $maxImgSize, array $imgDrivers)
+    public function __construct(/* string|int */ $maxFileSize, /* string|int */ $maxImgSize, array $imgDrivers, Container $c)
     {
     {
+        $this->c = $c;
+
         $init = \min(
         $init = \min(
             \PHP_INT_MAX,
             \PHP_INT_MAX,
             $this->size(\ini_get('upload_max_filesize')),
             $this->size(\ini_get('upload_max_filesize')),
             $this->size(\ini_get('post_max_size'))
             $this->size(\ini_get('post_max_size'))
         );
         );
-        $this->maxPixels  = (int) ($this->size(\ini_get('memory_limit')) / 10);
-        $this->maxImgSize = \min(
+
+        $this->maxPixels   = (int) ($this->size(\ini_get('memory_limit')) / 10);
+        $this->maxImgSize  = \min(
             $this->size($maxImgSize),
             $this->size($maxImgSize),
             $init,
             $init,
             $this->maxPixels
             $this->maxPixels
@@ -865,7 +875,7 @@ class Files
             $this->size($maxFileSize),
             $this->size($maxFileSize),
             $init
             $init
         );
         );
-        $this->imgDriver = $this->imgDriver($imgDrivers);
+        $this->imgDriver   = $this->imgDriver($imgDrivers);
     }
     }
 
 
     /**
     /**
@@ -910,6 +920,7 @@ class Files
             if (! \preg_match('%^([^a-z]+)([a-z]+)?$%i', \trim($value), $matches)) {
             if (! \preg_match('%^([^a-z]+)([a-z]+)?$%i', \trim($value), $matches)) {
                 throw new InvalidArgumentException('Expected string indicating the amount of information');
                 throw new InvalidArgumentException('Expected string indicating the amount of information');
             }
             }
+
             if (! \is_numeric($matches[1])) {
             if (! \is_numeric($matches[1])) {
                 throw new InvalidArgumentException('String does not contain number');
                 throw new InvalidArgumentException('String does not contain number');
             }
             }
@@ -1002,6 +1013,7 @@ class Files
 
 
         if (\is_array($file['tmp_name'])) {
         if (\is_array($file['tmp_name'])) {
             $result = [];
             $result = [];
+
             foreach ($file['tmp_name'] as $key => $value) {
             foreach ($file['tmp_name'] as $key => $value) {
                 if (
                 if (
                     '' === $file['name'][$key]
                     '' === $file['name'][$key]
@@ -1138,17 +1150,23 @@ class Files
 //            'size'      => $file['size'],
 //            'size'      => $file['size'],
         ];
         ];
 
 
+        $level = $this->c->ErrorHandler->logOnly(\E_WARNING);
+
         try {
         try {
             if (null !== $imageExt) {
             if (null !== $imageExt) {
-                return new Image($file['tmp_name'], $options, $this->imgDriver);
+                $result = new Image($file['tmp_name'], $options, $this->imgDriver);
             } else {
             } else {
-                return new File($file['tmp_name'], $options);
+                $result = new File($file['tmp_name'], $options);
             }
             }
         } catch (FileException $e) {
         } catch (FileException $e) {
             $this->error = $e->getMessage();
             $this->error = $e->getMessage();
 
 
-            return null;
+            $result = null;
         }
         }
+
+        $this->c->ErrorHandler->logOnly($level);
+
+        return $result;
     }
     }
 
 
     public function isBadPath(string $path): bool
     public function isBadPath(string $path): bool