Upgrade to rc5

This commit is contained in:
Bastian Allgeier
2020-12-10 11:24:42 +01:00
parent 3fec0d7c93
commit c378376bc9
257 changed files with 13009 additions and 1846 deletions

View File

@@ -2,11 +2,10 @@
namespace Kirby\Image;
use Exception;
use Kirby\Exception\Exception;
use Kirby\Http\Response;
use Kirby\Toolkit\File;
use Kirby\Toolkit\Html;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Mime;
use Kirby\Toolkit\V;
@@ -204,15 +203,44 @@ class Image extends File
*/
public function match(array $rules): bool
{
if (($rules['mime'] ?? null) !== null) {
if (Mime::isAccepted($this->mime(), $rules['mime']) !== true) {
throw new Exception(I18n::template('error.file.mime.invalid', [
'mime' => $this->mime()
]));
$rules = array_change_key_case($rules);
if (is_array($rules['mime'] ?? null) === true) {
$mime = $this->mime();
// determine if any pattern matches the MIME type;
// once any pattern matches, `$carry` is `true` and the rest is skipped
$matches = array_reduce($rules['mime'], function ($carry, $pattern) use ($mime) {
return $carry || Mime::matches($mime, $pattern);
}, false);
if ($matches !== true) {
throw new Exception([
'key' => 'file.mime.invalid',
'data' => compact('mime')
]);
}
}
$rules = array_change_key_case($rules);
if (is_array($rules['extension'] ?? null) === true) {
$extension = $this->extension();
if (in_array($extension, $rules['extension']) !== true) {
throw new Exception([
'key' => 'file.extension.invalid',
'data' => compact('extension')
]);
}
}
if (is_array($rules['type'] ?? null) === true) {
$type = $this->type();
if (in_array($type, $rules['type']) !== true) {
throw new Exception([
'key' => 'file.type.invalid',
'data' => compact('type')
]);
}
}
$validations = [
'maxsize' => ['size', 'max'],
@@ -232,9 +260,10 @@ class Image extends File
$validator = $arguments[1];
if (V::$validator($this->$property(), $rule) === false) {
throw new Exception(I18n::template('error.file.' . $key, [
$property => $rule
]));
throw new Exception([
'key' => 'file.' . $key,
'data' => [$property => $rule]
]);
}
}
}