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

@@ -114,7 +114,7 @@ class Dimensions
*/
public function fit(int $box, bool $force = false)
{
if ($this->width == 0 || $this->height == 0) {
if ($this->width === 0 || $this->height === 0) {
$this->width = $box;
$this->height = $box;
return $this;
@@ -379,7 +379,7 @@ class Dimensions
*/
public function square(): bool
{
return $this->width == $this->height;
return $this->width === $this->height;
}
/**

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]
]);
}
}
}

View File

@@ -79,7 +79,7 @@ class Location
$seconds = count($coord) > 2 ? $this->num($coord[2]) : 0;
$hemi = strtoupper($hemi);
$flip = ($hemi == 'W' || $hemi == 'S') ? -1 : 1;
$flip = ($hemi === 'W' || $hemi === 'S') ? -1 : 1;
return $flip * ($degrees + $minutes / 60 + $seconds / 3600);
}
@@ -94,7 +94,7 @@ class Location
{
$parts = explode('/', $part);
if (count($parts) == 1) {
if (count($parts) === 1) {
return $parts[0];
}