Upgrade to 3.7.0

This commit is contained in:
Bastian Allgeier
2022-06-27 10:02:22 +02:00
parent 0751a6510d
commit 1c22148d7b
674 changed files with 5052 additions and 3082 deletions

31
kirby/src/Api/Api.php Normal file → Executable file
View File

@@ -8,6 +8,7 @@ use Kirby\Exception\NotFoundException;
use Kirby\Filesystem\F;
use Kirby\Http\Response;
use Kirby\Http\Router;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Pagination;
use Kirby\Toolkit\Properties;
use Kirby\Toolkit\Str;
@@ -679,6 +680,12 @@ class Api
*/
public function responseForException(Throwable $e): array
{
if (isset($this->kirby) === true) {
$docRoot = $this->kirby->environment()->get('DOCUMENT_ROOT');
} else {
$docRoot = $_SERVER['DOCUMENT_ROOT'] ?? null;
}
// prepare the result array for all exception types
$result = [
'status' => 'error',
@@ -686,7 +693,7 @@ class Api
'code' => empty($e->getCode()) === true ? 500 : $e->getCode(),
'exception' => get_class($e),
'key' => null,
'file' => F::relativepath($e->getFile(), $_SERVER['DOCUMENT_ROOT'] ?? null),
'file' => F::relativepath($e->getFile(), $docRoot),
'line' => $e->getLine(),
'details' => [],
'route' => $this->route ? $this->route->pattern() : null
@@ -735,13 +742,13 @@ class Api
// get error messages from translation
$errorMessages = [
UPLOAD_ERR_INI_SIZE => t('upload.error.iniSize'),
UPLOAD_ERR_FORM_SIZE => t('upload.error.formSize'),
UPLOAD_ERR_PARTIAL => t('upload.error.partial'),
UPLOAD_ERR_NO_FILE => t('upload.error.noFile'),
UPLOAD_ERR_NO_TMP_DIR => t('upload.error.tmpDir'),
UPLOAD_ERR_CANT_WRITE => t('upload.error.cantWrite'),
UPLOAD_ERR_EXTENSION => t('upload.error.extension')
UPLOAD_ERR_INI_SIZE => I18n::translate('upload.error.iniSize'),
UPLOAD_ERR_FORM_SIZE => I18n::translate('upload.error.formSize'),
UPLOAD_ERR_PARTIAL => I18n::translate('upload.error.partial'),
UPLOAD_ERR_NO_FILE => I18n::translate('upload.error.noFile'),
UPLOAD_ERR_NO_TMP_DIR => I18n::translate('upload.error.tmpDir'),
UPLOAD_ERR_CANT_WRITE => I18n::translate('upload.error.cantWrite'),
UPLOAD_ERR_EXTENSION => I18n::translate('upload.error.extension')
];
if (empty($files) === true) {
@@ -749,9 +756,9 @@ class Api
$uploadMaxFileSize = Str::toBytes(ini_get('upload_max_filesize'));
if ($postMaxSize < $uploadMaxFileSize) {
throw new Exception(t('upload.error.iniPostSize'));
throw new Exception(I18n::translate('upload.error.iniPostSize'));
} else {
throw new Exception(t('upload.error.noFiles'));
throw new Exception(I18n::translate('upload.error.noFiles'));
}
}
@@ -764,7 +771,7 @@ class Api
try {
if ($upload['error'] !== 0) {
$errorMessage = $errorMessages[$upload['error']] ?? t('upload.error.default');
$errorMessage = $errorMessages[$upload['error']] ?? I18n::translate('upload.error.default');
throw new Exception($errorMessage);
}
@@ -786,7 +793,7 @@ class Api
// move the file to a location including the extension,
// for better mime detection
if ($debug === false && move_uploaded_file($upload['tmp_name'], $source) === false) {
throw new Exception(t('upload.error.cantMove'));
throw new Exception(I18n::translate('upload.error.cantMove'));
}
$data = $callback($source, $filename);