Upgrade to 3.4.3

This commit is contained in:
Bastian Allgeier
2020-09-15 10:25:09 +02:00
parent 54b9ba3047
commit d8e797dd9b
108 changed files with 1750 additions and 523 deletions

View File

@@ -4,7 +4,6 @@ namespace Kirby\Cms;
use Kirby\Exception\DuplicateException;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\LogicException;
use Kirby\Exception\PermissionException;
use Kirby\Image\Image;
use Kirby\Toolkit\Str;
@@ -21,6 +20,15 @@ use Kirby\Toolkit\V;
*/
class FileRules
{
/**
* Validates if the filename can be changed
*
* @param \Kirby\Cms\File $file
* @param string $name
* @return bool
* @throws \Kirby\Exception\DuplicateException If a file with this name exists
* @throws \Kirby\Exception\PermissionException If the user is not allowed to rename the file
*/
public static function changeName(File $file, string $name): bool
{
if ($file->permissions()->changeName() !== true) {
@@ -43,15 +51,31 @@ class FileRules
return true;
}
/**
* Validates if the file can be sorted
*
* @param \Kirby\Cms\File $file
* @param int $sort
* @return bool
*/
public static function changeSort(File $file, int $sort): bool
{
return true;
}
/**
* Validates if the file can be created
*
* @param \Kirby\Cms\File $file
* @param \Kirby\Image\Image $upload
* @return bool
* @throws \Kirby\Exception\DuplicateException If a file with the same name exists
* @throws \Kirby\Exception\PermissionException If the user is not allowed to create the file
*/
public static function create(File $file, Image $upload): bool
{
if ($file->exists() === true) {
throw new LogicException('The file exists and cannot be overwritten');
throw new DuplicateException('The file exists and cannot be overwritten');
}
if ($file->permissions()->create() !== true) {
@@ -67,6 +91,13 @@ class FileRules
return true;
}
/**
* Validates if the file can be deleted
*
* @param \Kirby\Cms\File $file
* @return bool
* @throws \Kirby\Exception\PermissionException If the user is not allowed to delete the file
*/
public static function delete(File $file): bool
{
if ($file->permissions()->delete() !== true) {
@@ -76,6 +107,15 @@ class FileRules
return true;
}
/**
* Validates if the file can be replaced
*
* @param \Kirby\Cms\File $file
* @param \Kirby\Image\Image $upload
* @return bool
* @throws \Kirby\Exception\PermissionException If the user is not allowed to replace the file
* @throws \Kirby\Exception\InvalidArgumentException If the file type of the new file is different
*/
public static function replace(File $file, Image $upload): bool
{
if ($file->permissions()->replace() !== true) {
@@ -84,7 +124,6 @@ class FileRules
static::validMime($file, $upload->mime());
if (
(string)$upload->mime() !== (string)$file->mime() &&
(string)$upload->extension() !== (string)$file->extension()
@@ -100,6 +139,14 @@ class FileRules
return true;
}
/**
* Validates if the file can be updated
*
* @param \Kirby\Cms\File $file
* @param array $content
* @return bool
* @throws \Kirby\Exception\PermissionException If the user is not allowed to update the file
*/
public static function update(File $file, array $content = []): bool
{
if ($file->permissions()->update() !== true) {
@@ -109,6 +156,14 @@ class FileRules
return true;
}
/**
* Validates the file extension
*
* @param \Kirby\Cms\File $file
* @param string $extension
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException If the extension is missing or forbidden
*/
public static function validExtension(File $file, string $extension): bool
{
// make it easier to compare the extension
@@ -145,9 +200,16 @@ class FileRules
return true;
}
/**
* Validates the filename
*
* @param \Kirby\Cms\File $file
* @param string $filename
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException If the filename is missing or forbidden
*/
public static function validFilename(File $file, string $filename)
{
// make it easier to compare the filename
$filename = strtolower($filename);
@@ -177,6 +239,14 @@ class FileRules
return true;
}
/**
* Validates the MIME type
*
* @param \Kirby\Cms\File $file
* @param string|null $mime
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException If the MIME type is missing or forbidden
*/
public static function validMime(File $file, string $mime = null)
{
// make it easier to compare the mime