Upgrade to 3.6.1
This commit is contained in:
@@ -330,6 +330,10 @@ class App
|
||||
{
|
||||
$router = $this->router();
|
||||
|
||||
/**
|
||||
* @todo Closures should not defined statically but
|
||||
* for each instance to avoid this constant setting and unsetting
|
||||
*/
|
||||
$router::$beforeEach = function ($route, $path, $method) {
|
||||
$this->trigger('route:before', compact('route', 'path', 'method'));
|
||||
};
|
||||
@@ -338,7 +342,12 @@ class App
|
||||
return $this->apply('route:after', compact('route', 'path', 'method', 'result', 'final'), 'result');
|
||||
};
|
||||
|
||||
return $router->call($path ?? $this->path(), $method ?? $this->request()->method());
|
||||
$result = $router->call($path ?? $this->path(), $method ?? $this->request()->method());
|
||||
|
||||
$router::$beforeEach = null;
|
||||
$router::$afterEach = null;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -128,7 +128,7 @@ trait AppErrors
|
||||
'code' => $code,
|
||||
'message' => $exception->getMessage(),
|
||||
'details' => $details,
|
||||
'file' => ltrim($exception->getFile(), $_SERVER['DOCUMENT_ROOT'] ?? null),
|
||||
'file' => ltrim($exception->getFile(), $_SERVER['DOCUMENT_ROOT'] ?? ''),
|
||||
'line' => $exception->getLine(),
|
||||
], $httpCode);
|
||||
} else {
|
||||
@@ -158,9 +158,23 @@ trait AppErrors
|
||||
$whoops = $this->whoops();
|
||||
$whoops->clearHandlers();
|
||||
$whoops->pushHandler($handler);
|
||||
$whoops->pushHandler($this->getExceptionHookWhoopsHandler());
|
||||
$whoops->register(); // will only do something if not already registered
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a callback handler for triggering the `system.exception` hook
|
||||
*
|
||||
* @return \Whoops\Handler\CallbackHandler
|
||||
*/
|
||||
protected function getExceptionHookWhoopsHandler(): CallbackHandler
|
||||
{
|
||||
return new CallbackHandler(function ($exception, $inspector, $run) {
|
||||
$this->trigger('system.exception', compact('exception'));
|
||||
return Handler::DONE;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Whoops handlers and disables Whoops
|
||||
*
|
||||
|
||||
@@ -605,9 +605,10 @@ class Auth
|
||||
$originalLog = $log;
|
||||
$time = time() - $this->kirby->option('auth.timeout', 3600);
|
||||
foreach ($log as $category => $entries) {
|
||||
$log[$category] = array_filter($entries, function ($entry) use ($time) {
|
||||
return $entry['time'] > $time;
|
||||
});
|
||||
$log[$category] = array_filter(
|
||||
$entries,
|
||||
fn ($entry) => $entry['time'] > $time
|
||||
);
|
||||
}
|
||||
|
||||
// write new log to the file system if it changed
|
||||
|
||||
@@ -74,7 +74,7 @@ class Blueprint
|
||||
$props = $this->preset($props);
|
||||
|
||||
// normalize the name
|
||||
$props['name'] = $props['name'] ?? 'default';
|
||||
$props['name'] ??= 'default';
|
||||
|
||||
// normalize and translate the title
|
||||
$props['title'] = $this->i18n($props['title'] ?? ucfirst($props['name']));
|
||||
@@ -337,7 +337,7 @@ class Blueprint
|
||||
|
||||
$normalize = function ($props) use ($name) {
|
||||
// inject the filename as name if no name is set
|
||||
$props['name'] = $props['name'] ?? $name;
|
||||
$props['name'] ??= $name;
|
||||
|
||||
// normalize the title
|
||||
$title = $props['title'] ?? ucfirst($props['name']);
|
||||
@@ -567,9 +567,7 @@ class Blueprint
|
||||
|
||||
// set all options to false
|
||||
if ($options === false) {
|
||||
return array_map(function () {
|
||||
return false;
|
||||
}, $defaults);
|
||||
return array_map(fn () => false, $defaults);
|
||||
}
|
||||
|
||||
// extend options if possible
|
||||
@@ -579,7 +577,7 @@ class Blueprint
|
||||
$alias = $aliases[$key] ?? null;
|
||||
|
||||
if ($alias !== null) {
|
||||
$options[$alias] = $options[$alias] ?? $value;
|
||||
$options[$alias] ??= $value;
|
||||
unset($options[$key]);
|
||||
}
|
||||
}
|
||||
@@ -765,9 +763,10 @@ class Blueprint
|
||||
*/
|
||||
public function sections(): array
|
||||
{
|
||||
return array_map(function ($section) {
|
||||
return $this->section($section['name']);
|
||||
}, $this->sections);
|
||||
return A::map(
|
||||
$this->sections,
|
||||
fn ($section) => $this->section($section['name'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -208,7 +208,7 @@ class ContentLock
|
||||
}
|
||||
|
||||
// add lock user to unlocked data
|
||||
$this->data['unlock'] = $this->data['unlock'] ?? [];
|
||||
$this->data['unlock'] ??= [];
|
||||
$this->data['unlock'][] = $this->data['lock']['user'];
|
||||
|
||||
return $this->clearLock();
|
||||
|
||||
@@ -208,7 +208,7 @@ class ContentTranslation
|
||||
*/
|
||||
public function slug(): ?string
|
||||
{
|
||||
return $this->slug = $this->slug ?? ($this->content()['slug'] ?? null);
|
||||
return $this->slug ??= ($this->content()['slug'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -167,7 +167,7 @@ class Core
|
||||
*/
|
||||
public function components(): array
|
||||
{
|
||||
return $this->cache['components'] ?? $this->cache['components'] = include $this->root . '/components.php';
|
||||
return $this->cache['components'] ??= include $this->root . '/components.php';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +203,7 @@ class Core
|
||||
*/
|
||||
public function fieldMethods(): array
|
||||
{
|
||||
return $this->cache['fieldMethods'] ?? $this->cache['fieldMethods'] = (include $this->root . '/methods.php')($this->kirby);
|
||||
return $this->cache['fieldMethods'] ??= (include $this->root . '/methods.php')($this->kirby);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,7 +295,7 @@ class Core
|
||||
*/
|
||||
public function kirbyTags(): array
|
||||
{
|
||||
return $this->cache['kirbytags'] ?? $this->cache['kirbytags'] = include $this->root . '/tags.php';
|
||||
return $this->cache['kirbytags'] ??= include $this->root . '/tags.php';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,7 +321,7 @@ class Core
|
||||
*/
|
||||
public function roots(): array
|
||||
{
|
||||
return $this->cache['roots'] ?? $this->cache['roots'] = [
|
||||
return $this->cache['roots'] ??= [
|
||||
// kirby
|
||||
'kirby' => function (array $roots) {
|
||||
return dirname(__DIR__, 2);
|
||||
@@ -428,7 +428,7 @@ class Core
|
||||
*/
|
||||
public function routes(): array
|
||||
{
|
||||
return $this->cache['routes'] ?? $this->cache['routes'] = (include $this->root . '/routes.php')($this->kirby);
|
||||
return $this->cache['routes'] ??= (include $this->root . '/routes.php')($this->kirby);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -517,7 +517,7 @@ class Core
|
||||
*/
|
||||
public function urls(): array
|
||||
{
|
||||
return $this->cache['urls'] ?? $this->cache['urls'] = [
|
||||
return $this->cache['urls'] ??= [
|
||||
'index' => function () {
|
||||
return Url::index();
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Kirby\Cms;
|
||||
|
||||
use Closure;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
@@ -42,7 +43,7 @@ class Fieldsets extends Items
|
||||
$fieldset = Blueprint::extend($fieldset);
|
||||
|
||||
// make sure the type is always set
|
||||
$fieldset['type'] = $fieldset['type'] ?? $type;
|
||||
$fieldset['type'] ??= $type;
|
||||
|
||||
// extract groups
|
||||
if ($fieldset['type'] === 'group') {
|
||||
@@ -69,7 +70,7 @@ class Fieldsets extends Items
|
||||
|
||||
public static function factory(array $items = null, array $params = [])
|
||||
{
|
||||
$items = $items ?? option('blocks.fieldsets', [
|
||||
$items ??= option('blocks.fieldsets', [
|
||||
'code' => 'blocks/code',
|
||||
'gallery' => 'blocks/gallery',
|
||||
'heading' => 'blocks/heading',
|
||||
@@ -94,8 +95,9 @@ class Fieldsets extends Items
|
||||
|
||||
public function toArray(?Closure $map = null): array
|
||||
{
|
||||
return array_map($map ?? function ($fieldset) {
|
||||
return $fieldset->toArray();
|
||||
}, $this->data);
|
||||
return A::map(
|
||||
$this->data,
|
||||
$map ?? fn ($fieldset) => $fieldset->toArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use Kirby\Filesystem\F;
|
||||
use Kirby\Filesystem\IsFile;
|
||||
use Kirby\Panel\File as Panel;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* The `$file` object provides a set
|
||||
@@ -362,14 +363,9 @@ class File extends ModelWithContent
|
||||
$file = $this->modifiedFile();
|
||||
$content = $this->modifiedContent($languageCode);
|
||||
$modified = max($file, $content);
|
||||
$handler ??= $this->kirby()->option('date.handler', 'date');
|
||||
|
||||
if (is_null($format) === true) {
|
||||
return $modified;
|
||||
}
|
||||
|
||||
$handler = $handler ?? $this->kirby()->option('date.handler', 'date');
|
||||
|
||||
return $handler($format, $modified);
|
||||
return Str::date($modified, $format, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,7 +418,7 @@ class File extends ModelWithContent
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->parent = $this->parent ?? $this->kirby()->site();
|
||||
return $this->parent ??= $this->kirby()->site();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -472,7 +468,7 @@ class File extends ModelWithContent
|
||||
*/
|
||||
public function root(): ?string
|
||||
{
|
||||
return $this->root = $this->root ?? $this->parent()->root() . '/' . $this->filename();
|
||||
return $this->root ??= $this->parent()->root() . '/' . $this->filename();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -598,7 +594,7 @@ class File extends ModelWithContent
|
||||
*/
|
||||
public function template(): ?string
|
||||
{
|
||||
return $this->template = $this->template ?? $this->content()->get('template')->value();
|
||||
return $this->template ??= $this->content()->get('template')->value();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -631,7 +627,7 @@ class File extends ModelWithContent
|
||||
*/
|
||||
public function url(): string
|
||||
{
|
||||
return $this->url ?? $this->url = ($this->kirby()->component('file::url'))($this->kirby(), $this);
|
||||
return $this->url ??= ($this->kirby()->component('file::url'))($this->kirby(), $this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -163,17 +163,24 @@ class FileBlueprint extends Blueprint
|
||||
|
||||
// normalize the MIME, extension and type from strings into arrays
|
||||
if (is_string($accept['mime']) === true) {
|
||||
$accept['mime'] = array_map(function ($mime) {
|
||||
return $mime['value'];
|
||||
}, Str::accepted($accept['mime']));
|
||||
$accept['mime'] = array_map(
|
||||
fn ($mime) => $mime['value'],
|
||||
Str::accepted($accept['mime'])
|
||||
);
|
||||
}
|
||||
|
||||
if (is_string($accept['extension']) === true) {
|
||||
$accept['extension'] = array_map('trim', explode(',', $accept['extension']));
|
||||
$accept['extension'] = array_map(
|
||||
'trim',
|
||||
explode(',', $accept['extension'])
|
||||
);
|
||||
}
|
||||
|
||||
if (is_string($accept['type']) === true) {
|
||||
$accept['type'] = array_map('trim', explode(',', $accept['type']));
|
||||
$accept['type'] = array_map(
|
||||
'trim',
|
||||
explode(',', $accept['type'])
|
||||
);
|
||||
}
|
||||
|
||||
return $accept;
|
||||
|
||||
@@ -203,9 +203,10 @@ trait FileModifications
|
||||
|
||||
if (
|
||||
is_a($result, 'Kirby\Cms\FileVersion') === false &&
|
||||
is_a($result, 'Kirby\Cms\File') === false
|
||||
is_a($result, 'Kirby\Cms\File') === false &&
|
||||
is_a($result, 'Kirby\Filesystem\Asset') === false
|
||||
) {
|
||||
throw new InvalidArgumentException('The file::version component must return a File or FileVersion object');
|
||||
throw new InvalidArgumentException('The file::version component must return a File, FileVersion or Asset object');
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -87,9 +87,10 @@ class LanguageRouter
|
||||
$patterns = A::wrap($route['pattern']);
|
||||
|
||||
// prefix all patterns with the page slug
|
||||
$patterns = array_map(function ($pattern) use ($page, $language) {
|
||||
return $page->uri($language) . '/' . $pattern;
|
||||
}, $patterns);
|
||||
$patterns = A::map(
|
||||
$patterns,
|
||||
fn ($pattern) => $page->uri($language) . '/' . $pattern
|
||||
);
|
||||
|
||||
// re-inject the pattern and the full page object
|
||||
$routes[$index]['pattern'] = $patterns;
|
||||
|
||||
@@ -25,9 +25,10 @@ class Languages extends Collection
|
||||
*/
|
||||
public function __construct($objects = [], $parent = null)
|
||||
{
|
||||
$defaults = array_filter($objects, function ($language) {
|
||||
return $language->isDefault() === true;
|
||||
});
|
||||
$defaults = array_filter(
|
||||
$objects,
|
||||
fn ($language) => $language->isDefault() === true
|
||||
);
|
||||
|
||||
if (count($defaults) > 1) {
|
||||
throw new DuplicateException('You cannot have multiple default languages. Please check your language config files.');
|
||||
@@ -87,8 +88,9 @@ class Languages extends Collection
|
||||
$props = F::load($file);
|
||||
|
||||
if (is_array($props) === true) {
|
||||
// inject the language code from the filename if it does not exist
|
||||
$props['code'] = $props['code'] ?? F::name($file);
|
||||
// inject the language code from the filename
|
||||
// if it does not exist
|
||||
$props['code'] ??= F::name($file);
|
||||
|
||||
$languages[] = new Language($props);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ abstract class Model
|
||||
*/
|
||||
public function kirby()
|
||||
{
|
||||
return static::$kirby = static::$kirby ?? App::instance();
|
||||
return static::$kirby ??= App::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ abstract class Model
|
||||
*/
|
||||
public function site()
|
||||
{
|
||||
return $this->site = $this->site ?? $this->kirby()->site();
|
||||
return $this->site ??= $this->kirby()->site();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -382,7 +382,7 @@ class Page extends ModelWithContent
|
||||
*/
|
||||
public function depth(): int
|
||||
{
|
||||
return $this->depth = $this->depth ?? (substr_count($this->id(), '/') + 1);
|
||||
return $this->depth ??= (substr_count($this->id(), '/') + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1102,7 +1102,7 @@ class Page extends ModelWithContent
|
||||
*/
|
||||
public function root(): string
|
||||
{
|
||||
return $this->root = $this->root ?? $this->kirby()->root('content') . '/' . $this->diruri();
|
||||
return $this->root ??= $this->kirby()->root('content') . '/' . $this->diruri();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ class Pages extends Collection
|
||||
*/
|
||||
public static function factory(array $pages, Model $model = null, bool $draft = false)
|
||||
{
|
||||
$model = $model ?? App::instance()->site();
|
||||
$model ??= App::instance()->site();
|
||||
$children = new static([], $model);
|
||||
$kirby = $model->kirby();
|
||||
|
||||
|
||||
@@ -69,9 +69,9 @@ class Pagination extends BasePagination
|
||||
$config = $kirby->option('pagination', []);
|
||||
$request = $kirby->request();
|
||||
|
||||
$params['limit'] = $params['limit'] ?? $config['limit'] ?? 20;
|
||||
$params['method'] = $params['method'] ?? $config['method'] ?? 'param';
|
||||
$params['variable'] = $params['variable'] ?? $config['variable'] ?? 'page';
|
||||
$params['limit'] ??= $config['limit'] ?? 20;
|
||||
$params['method'] ??= $config['method'] ?? 'param';
|
||||
$params['variable'] ??= $config['variable'] ?? 'page';
|
||||
|
||||
if (empty($params['url']) === true) {
|
||||
$params['url'] = new Uri($kirby->url('current'), [
|
||||
@@ -81,9 +81,9 @@ class Pagination extends BasePagination
|
||||
}
|
||||
|
||||
if ($params['method'] === 'query') {
|
||||
$params['page'] = $params['page'] ?? $params['url']->query()->get($params['variable']);
|
||||
$params['page'] ??= $params['url']->query()->get($params['variable']);
|
||||
} elseif ($params['method'] === 'param') {
|
||||
$params['page'] = $params['page'] ?? $params['url']->params()->get($params['variable']);
|
||||
$params['page'] ??= $params['url']->params()->get($params['variable']);
|
||||
}
|
||||
|
||||
parent::__construct($params);
|
||||
|
||||
@@ -210,7 +210,7 @@ class Role extends Model
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return $this->title = $this->title ?? ucfirst($this->name());
|
||||
return $this->title ??= ucfirst($this->name());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,8 +49,8 @@ class Section extends Component
|
||||
}
|
||||
|
||||
// use the type as fallback for the name
|
||||
$attrs['name'] = $attrs['name'] ?? $type;
|
||||
$attrs['type'] = $type;
|
||||
$attrs['name'] ??= $type;
|
||||
$attrs['type'] = $type;
|
||||
|
||||
parent::__construct($type, $attrs);
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ class Site extends ModelWithContent
|
||||
*/
|
||||
public function root(): string
|
||||
{
|
||||
return $this->root = $this->root ?? $this->kirby()->root('content');
|
||||
return $this->root ??= $this->kirby()->root('content');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -405,7 +405,7 @@ class System
|
||||
{
|
||||
return
|
||||
version_compare(PHP_VERSION, '7.4.0', '>=') === true &&
|
||||
version_compare(PHP_VERSION, '8.1.0', '<') === true;
|
||||
version_compare(PHP_VERSION, '8.2.0', '<') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -508,7 +508,7 @@ class System
|
||||
];
|
||||
}
|
||||
|
||||
$software = $_SERVER['SERVER_SOFTWARE'] ?? null;
|
||||
$software = $_SERVER['SERVER_SOFTWARE'] ?? '';
|
||||
|
||||
preg_match('!(' . implode('|', $servers) . ')!i', $software, $matches);
|
||||
|
||||
|
||||
@@ -78,7 +78,11 @@ class Template
|
||||
*/
|
||||
public function exists(): bool
|
||||
{
|
||||
return file_exists($this->file());
|
||||
if ($file = $this->file()) {
|
||||
return file_exists($file);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -228,7 +228,7 @@ class User extends ModelWithContent
|
||||
|
||||
protected function credentials(): array
|
||||
{
|
||||
return $this->credentials = $this->credentials ?? $this->readCredentials();
|
||||
return $this->credentials ??= $this->readCredentials();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +238,7 @@ class User extends ModelWithContent
|
||||
*/
|
||||
public function email(): ?string
|
||||
{
|
||||
return $this->email = $this->email ?? $this->credentials()['email'] ?? null;
|
||||
return $this->email ??= $this->credentials()['email'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,7 +403,7 @@ class User extends ModelWithContent
|
||||
*/
|
||||
public function language(): string
|
||||
{
|
||||
return $this->language ?? $this->language = $this->credentials()['language'] ?? $this->kirby()->panelLanguage();
|
||||
return $this->language ??= $this->credentials()['language'] ?? $this->kirby()->panelLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -530,9 +530,9 @@ class User extends ModelWithContent
|
||||
$modifiedContent = F::modified($this->contentFile($languageCode));
|
||||
$modifiedIndex = F::modified($this->root() . '/index.php');
|
||||
$modifiedTotal = max([$modifiedContent, $modifiedIndex]);
|
||||
$handler = $handler ?? $this->kirby()->option('date.handler', 'date');
|
||||
$handler ??= $this->kirby()->option('date.handler', 'date');
|
||||
|
||||
return $handler($format, $modifiedTotal);
|
||||
return Str::date($modifiedTotal, $format, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user