Update Kirby and Composer dependencies

This commit is contained in:
Paul Nicoué 2022-03-22 15:39:39 +01:00
parent f5d3ea5e84
commit ec74d78ba9
382 changed files with 25077 additions and 4955 deletions

View file

@ -12,7 +12,7 @@ use Kirby\Form\Form;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Api extends BaseApi

View file

@ -33,13 +33,11 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class App
{
const CLASS_ALIAS = 'kirby';
use AppCaches;
use AppErrors;
use AppPlugins;
@ -47,6 +45,8 @@ class App
use AppUsers;
use Properties;
public const CLASS_ALIAS = 'kirby';
protected static $instance;
protected static $version;
@ -56,6 +56,7 @@ class App
protected $collections;
protected $core;
protected $defaultLanguage;
protected $environment;
protected $language;
protected $languages;
protected $locks;
@ -91,12 +92,17 @@ class App
// register all roots to be able to load stuff afterwards
$this->bakeRoots($props['roots'] ?? []);
// stuff from config and additional options
$this->optionsFromConfig();
$this->optionsFromProps($props['options'] ?? []);
// register the Whoops error handler
$this->handleErrors();
try {
// stuff from config and additional options
$this->optionsFromConfig();
$this->optionsFromProps($props['options'] ?? []);
$this->optionsFromEnvironment();
} finally {
// register the Whoops error handler inside of a
// try-finally block to ensure it's still registered
// even if there is a problem loading the configurations
$this->handleErrors();
}
// set the path to make it available for the url bakery
$this->setPath($props['path'] ?? null);
@ -282,11 +288,6 @@ class App
*/
protected function bakeUrls(array $urls = null)
{
// inject the index URL from the config
if (isset($this->options['url']) === true) {
$urls['index'] = $this->options['url'];
}
$urls = array_merge($this->core->urls(), (array)$urls);
$this->urls = Ingredients::bake($urls);
return $this;
@ -330,6 +331,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 +343,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;
}
/**
@ -580,6 +590,17 @@ class App
return ($this->component('email'))($this, $props, $debug);
}
/**
* Returns the environment object with access
* to the detected host, base url and dedicated options
*
* @return \Kirby\Cms\Environment
*/
public function environment()
{
return $this->environment;
}
/**
* Finds any file in the content directory
*
@ -762,10 +783,11 @@ class App
*/
public function kirbytags(string $text = null, array $data = []): string
{
$data['kirby'] = $data['kirby'] ?? $this;
$data['site'] = $data['site'] ?? $data['kirby']->site();
$data['parent'] = $data['parent'] ?? $data['site']->page();
$options = $this->options;
$data['kirby'] ??= $this;
$data['site'] ??= $data['kirby']->site();
$data['parent'] ??= $data['site']->page();
$options = $this->options;
$text = $this->apply('kirbytags:before', compact('text', 'data', 'options'), 'text');
$text = KirbyTags::parse($text, $data, $options);
@ -780,14 +802,23 @@ class App
* @internal
* @param string|null $text
* @param array $data
* @param bool $inline
* @param bool $inline (deprecated: use $data['markdown']['inline'] instead)
* @return string
* @todo add deprecation warning for $inline parameter in 3.7.0
* @todo rename $data parameter to $options in 3.7.0
* @todo remove $inline parameter in in 3.8.0
*/
public function kirbytext(string $text = null, array $data = [], bool $inline = false): string
{
$options = A::merge([
'markdown' => [
'inline' => $inline
]
], $data);
$text = $this->apply('kirbytext:before', compact('text'), 'text');
$text = $this->kirbytags($text, $data);
$text = $this->markdown($text, $inline);
$text = $this->kirbytags($text, $options);
$text = $this->markdown($text, $options['markdown']);
if ($this->option('smartypants', false) !== false) {
$text = $this->smartypants($text);
@ -881,12 +912,34 @@ class App
*
* @internal
* @param string|null $text
* @param bool $inline
* @param bool|array $options
* @return string
* @todo rename $inline parameter to $options in 3.7.0
* @todo add deprecation warning for boolean $options in 3.7.0
* @todo remove boolean $options in in 3.8.0
*/
public function markdown(string $text = null, bool $inline = false): string
public function markdown(string $text = null, $inline = null): string
{
return ($this->component('markdown'))($this, $text, $this->options['markdown'] ?? [], $inline);
// TODO: remove after renaming parameter
$options = $inline;
// support for the old syntax to enable inline mode as second argument
if (is_bool($options) === true) {
$options = [
'inline' => $options
];
}
// merge global options with local options
$options = array_merge(
$this->options['markdown'] ?? [],
(array)$options
);
// TODO: deprecate passing the $inline parameter in 3.7.0
// TODO: remove passing the $inline parameter in 3.8.0
$inline = $options['inline'] ?? false;
return ($this->component('markdown'))($this, $text, $options, $inline);
}
/**
@ -944,18 +997,30 @@ class App
*/
protected function optionsFromConfig(): array
{
$server = $this->server();
$root = $this->root('config');
// create an empty config container
Config::$data = [];
$main = F::load($root . '/config.php', []);
$host = F::load($root . '/config.' . basename($server->host()) . '.php', []);
$addr = F::load($root . '/config.' . basename($server->address()) . '.php', []);
// load the main config options
$root = $this->root('config');
$options = F::load($root . '/config.php', []);
$config = Config::$data;
// merge into one clean options array
return $this->options = array_replace_recursive(Config::$data, $options);
}
return $this->options = array_replace_recursive($config, $main, $host, $addr);
/**
* Load all options for the current
* server environment
*
* @return array
*/
protected function optionsFromEnvironment(): array
{
// create the environment based on the URL setup
$this->environment = new Environment($this->root('config'), $this->options['url'] ?? null);
// merge into one clean options array
return $this->options = array_replace_recursive($this->options, $this->environment->options());
}
/**
@ -966,7 +1031,10 @@ class App
*/
protected function optionsFromProps(array $options = []): array
{
return $this->options = array_replace_recursive($this->options, $options);
return $this->options = array_replace_recursive(
$this->options,
$options
);
}
/**
@ -1373,7 +1441,7 @@ class App
*/
public function server()
{
return $this->server = $this->server ?? new Server();
return $this->server ??= new Server();
}
/**

View file

@ -11,7 +11,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait AppCaches

View file

@ -3,6 +3,7 @@
namespace Kirby\Cms;
use Kirby\Http\Response;
use Kirby\Toolkit\I18n;
use Whoops\Handler\CallbackHandler;
use Whoops\Handler\Handler;
use Whoops\Handler\PlainTextHandler;
@ -15,7 +16,7 @@ use Whoops\Run as Whoops;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait AppErrors
@ -128,7 +129,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 {
@ -136,7 +137,7 @@ trait AppErrors
'status' => 'error',
'code' => $code,
'details' => $details,
'message' => 'An unexpected error occurred! Enable debug mode for more info: https://getkirby.com/docs/reference/system/options/debug',
'message' => I18n::translate('error.unexpected'),
], $httpCode);
}
@ -158,9 +159,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
*

View file

@ -21,7 +21,7 @@ use Kirby\Toolkit\V;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait AppPlugins
@ -181,7 +181,7 @@ trait AppPlugins
{
return $this->extensions['blockModels'] = Block::$models = array_merge(Block::$models, $models);
}
/**
* Registers additional blocks methods
*

View file

@ -12,7 +12,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait AppTranslations

View file

@ -11,7 +11,7 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait AppUsers

View file

@ -20,7 +20,7 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Auth
@ -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

View file

@ -11,7 +11,7 @@ use Kirby\Cms\User;
* @package Kirby Cms
* @author Lukas Bestle <lukas@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
abstract class Challenge

View file

@ -13,7 +13,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Lukas Bestle <lukas@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class EmailChallenge extends Challenge

View file

@ -14,7 +14,7 @@ use Kirby\Toolkit\Properties;
* @package Kirby Cms
* @author Lukas Bestle <lukas@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Status

View file

@ -15,15 +15,15 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Block extends Item
{
const ITEMS_CLASS = '\Kirby\Cms\Blocks';
use HasMethods;
public const ITEMS_CLASS = '\Kirby\Cms\Blocks';
/**
* @var \Kirby\Cms\Content
*/

View file

@ -10,7 +10,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class BlockConverter

View file

@ -18,12 +18,12 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Blocks extends Items
{
const ITEM_CLASS = '\Kirby\Cms\Block';
public const ITEM_CLASS = '\Kirby\Cms\Block';
/**
* Return HTML when the collection is

View file

@ -20,7 +20,7 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Blueprint
@ -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'])
);
}
/**

View file

@ -19,7 +19,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Collection extends BaseCollection
@ -333,8 +333,6 @@ class Collection extends BaseCollection
*/
public function toArray(Closure $map = null): array
{
return parent::toArray($map ?? function ($object) {
return $object->toArray();
});
return parent::toArray($map ?? fn ($object) => $object->toArray());
}
}

View file

@ -17,7 +17,7 @@ use Kirby\Toolkit\Controller;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Collections

View file

@ -11,7 +11,7 @@ use Kirby\Form\Form;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Content

View file

@ -12,7 +12,7 @@ use Kirby\Exception\PermissionException;
* @package Kirby Cms
* @author Nico Hoffmann <nico@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class ContentLock
@ -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();

View file

@ -13,7 +13,7 @@ use Kirby\Filesystem\F;
* @author Nico Hoffmann <nico@getkirby.com>,
* Lukas Bestle <lukas@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class ContentLocks

View file

@ -12,7 +12,7 @@ use Kirby\Toolkit\Properties;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class ContentTranslation
@ -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);
}
/**

View file

@ -16,7 +16,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Core
@ -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,99 +321,33 @@ class Core
*/
public function roots(): array
{
return $this->cache['roots'] ?? $this->cache['roots'] = [
// kirby
'kirby' => function (array $roots) {
return dirname(__DIR__, 2);
},
return $this->cache['roots'] ??= [
'kirby' => fn (array $roots) => dirname(__DIR__, 2),
'i18n' => fn (array $roots) => $roots['kirby'] . '/i18n',
'i18n:translations' => fn (array $roots) => $roots['i18n'] . '/translations',
'i18n:rules' => fn (array $roots) => $roots['i18n'] . '/rules',
// i18n
'i18n' => function (array $roots) {
return $roots['kirby'] . '/i18n';
},
'i18n:translations' => function (array $roots) {
return $roots['i18n'] . '/translations';
},
'i18n:rules' => function (array $roots) {
return $roots['i18n'] . '/rules';
},
// index
'index' => function (array $roots) {
return dirname(__DIR__, 3);
},
// assets
'assets' => function (array $roots) {
return $roots['index'] . '/assets';
},
// content
'content' => function (array $roots) {
return $roots['index'] . '/content';
},
// media
'media' => function (array $roots) {
return $roots['index'] . '/media';
},
// panel
'panel' => function (array $roots) {
return $roots['kirby'] . '/panel';
},
// site
'site' => function (array $roots) {
return $roots['index'] . '/site';
},
'accounts' => function (array $roots) {
return $roots['site'] . '/accounts';
},
'blueprints' => function (array $roots) {
return $roots['site'] . '/blueprints';
},
'cache' => function (array $roots) {
return $roots['site'] . '/cache';
},
'collections' => function (array $roots) {
return $roots['site'] . '/collections';
},
'config' => function (array $roots) {
return $roots['site'] . '/config';
},
'controllers' => function (array $roots) {
return $roots['site'] . '/controllers';
},
'languages' => function (array $roots) {
return $roots['site'] . '/languages';
},
'license' => function (array $roots) {
return $roots['config'] . '/.license';
},
'logs' => function (array $roots) {
return $roots['site'] . '/logs';
},
'models' => function (array $roots) {
return $roots['site'] . '/models';
},
'plugins' => function (array $roots) {
return $roots['site'] . '/plugins';
},
'sessions' => function (array $roots) {
return $roots['site'] . '/sessions';
},
'snippets' => function (array $roots) {
return $roots['site'] . '/snippets';
},
'templates' => function (array $roots) {
return $roots['site'] . '/templates';
},
// blueprints
'roles' => function (array $roots) {
return $roots['blueprints'] . '/users';
},
'index' => fn (array $roots) => dirname(__DIR__, 3),
'assets' => fn (array $roots) => $roots['index'] . '/assets',
'content' => fn (array $roots) => $roots['index'] . '/content',
'media' => fn (array $roots) => $roots['index'] . '/media',
'panel' => fn (array $roots) => $roots['kirby'] . '/panel',
'site' => fn (array $roots) => $roots['index'] . '/site',
'accounts' => fn (array $roots) => $roots['site'] . '/accounts',
'blueprints' => fn (array $roots) => $roots['site'] . '/blueprints',
'cache' => fn (array $roots) => $roots['site'] . '/cache',
'collections' => fn (array $roots) => $roots['site'] . '/collections',
'config' => fn (array $roots) => $roots['site'] . '/config',
'controllers' => fn (array $roots) => $roots['site'] . '/controllers',
'languages' => fn (array $roots) => $roots['site'] . '/languages',
'license' => fn (array $roots) => $roots['config'] . '/.license',
'logs' => fn (array $roots) => $roots['site'] . '/logs',
'models' => fn (array $roots) => $roots['site'] . '/models',
'plugins' => fn (array $roots) => $roots['site'] . '/plugins',
'sessions' => fn (array $roots) => $roots['site'] . '/sessions',
'snippets' => fn (array $roots) => $roots['site'] . '/snippets',
'templates' => fn (array $roots) => $roots['site'] . '/templates',
'roles' => fn (array $roots) => $roots['blueprints'] . '/users',
];
}
@ -428,7 +362,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,13 +451,9 @@ class Core
*/
public function urls(): array
{
return $this->cache['urls'] ?? $this->cache['urls'] = [
'index' => function () {
return Url::index();
},
'base' => function (array $urls) {
return rtrim($urls['index'], '/');
},
return $this->cache['urls'] ??= [
'index' => fn () => $this->kirby->environment()->url(),
'base' => fn (array $urls) => rtrim($urls['index'], '/'),
'current' => function (array $urls) {
$path = trim($this->kirby->path(), '/');
@ -533,18 +463,10 @@ class Core
return $urls['base'] . '/' . $path;
}
},
'assets' => function (array $urls) {
return $urls['base'] . '/assets';
},
'api' => function (array $urls) {
return $urls['base'] . '/' . $this->kirby->option('api.slug', 'api');
},
'media' => function (array $urls) {
return $urls['base'] . '/media';
},
'panel' => function (array $urls) {
return $urls['base'] . '/' . $this->kirby->option('panel.slug', 'panel');
}
'assets' => fn (array $urls) => $urls['base'] . '/assets',
'api' => fn (array $urls) => $urls['base'] . '/' . $this->kirby->option('api.slug', 'api'),
'media' => fn (array $urls) => $urls['base'] . '/media',
'panel' => fn (array $urls) => $urls['base'] . '/' . $this->kirby->option('panel.slug', 'panel')
];
}
}

View file

@ -14,7 +14,7 @@ use Kirby\Exception\NotFoundException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Email

View file

@ -0,0 +1,222 @@
<?php
namespace Kirby\Cms;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Filesystem\F;
use Kirby\Http\Server;
use Kirby\Http\Uri;
/**
* The environment object takes care of
* secure host and base URL detection, as
* well as loading the dedicated
* environment options.
*
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Environment
{
/**
* @var string
*/
protected $root;
/**
* @var \Kirby\Http\Uri
*/
protected $uri;
/**
* @param string $root
* @param bool|string|array|null $allowed
*/
public function __construct(string $root, $allowed = null)
{
$this->root = $root;
if (is_string($allowed) === true) {
$this->setupFromString($allowed);
return;
}
if (is_array($allowed) === true) {
$this->setupFromArray($allowed);
return;
}
if (is_int($allowed) === true) {
$this->setupFromFlag($allowed);
return;
}
if (is_null($allowed) === true) {
$this->setupFromFlag(Server::HOST_FROM_SERVER | Server::HOST_ALLOW_EMPTY);
return;
}
throw new InvalidArgumentException('Invalid allow list setup for base URLs');
}
/**
* Throw an exception if the host in the URI
* object is empty
*
* @throws \Kirby\Exception\InvalidArgumentException
* @return void
*/
protected function blockEmptyHost(): void
{
if (empty($this->uri->host()) === true) {
throw new InvalidArgumentException('Invalid host setup. The detected host is not allowed.');
}
}
/**
* Returns the detected host name
*
* @return string|null
*/
public function host(): ?string
{
return $this->uri->host();
}
/**
* Loads and returns the environment options
*
* @return array
*/
public function options(): array
{
$configHost = [];
$configAddr = [];
$host = $this->host();
$addr = Server::address();
// load the config for the host
if (empty($host) === false) {
$configHost = F::load($this->root . '/config.' . $host . '.php', []);
}
// load the config for the server IP
if (empty($addr) === false) {
$configAddr = F::load($this->root . '/config.' . $addr . '.php', []);
}
return array_replace_recursive($configHost, $configAddr);
}
/**
* The current URL should be auto detected from a host allowlist
*
* @param array $allowed
* @return \Kirby\Http\Uri
*/
public function setupFromArray(array $allowed)
{
$allowedStrings = [];
$allowedUris = [];
$hosts = [];
foreach ($allowed as $url) {
$allowedUris[] = $uri = new Uri($url, ['slash' => false]);
$allowedStrings[] = $uri->toString();
$hosts[] = $uri->host();
}
// register all allowed hosts
Server::hosts($hosts);
// get the index URL, including the subfolder if it exists
$this->uri = Uri::index();
// empty URLs don't make sense in an allow list
$this->blockEmptyHost();
// validate against the list of allowed base URLs
if (in_array($this->uri->toString(), $allowedStrings) === false) {
throw new InvalidArgumentException('The subfolder is not in the allowed base URL list');
}
return $this->uri;
}
/**
* The URL option receives a set of Server constant flags
*
* Server::HOST_FROM_SERVER
* Server::HOST_FROM_SERVER | Server::HOST_ALLOW_EMPTY
* Server::HOST_FROM_HOST
* Server::HOST_FROM_HOST | Server::HOST_ALLOW_EMPTY
*
* @param int $allowed
* @return \Kirby\Http\Uri
*/
public function setupFromFlag(int $allowed)
{
// allow host detection from host headers
if ($allowed & Server::HOST_FROM_HEADER) {
Server::hosts(Server::HOST_FROM_HEADER);
// detect host only from server name
} else {
Server::hosts(Server::HOST_FROM_SERVER);
}
// get the base URL
$this->uri = Uri::index();
// accept empty hosts
if ($allowed & Server::HOST_ALLOW_EMPTY) {
return $this->uri;
}
// block empty hosts
$this->blockEmptyHost();
return $this->uri;
}
/**
* The current URL is predefined with a single string
* and not detected automatically.
*
* If the url option is relative (i.e. '/' or '/some/subfolder')
* The host will be empty and that's totally fine.
* No need to block an empty host here
*
* @param string $allowed
* @return \Kirby\Http\Uri
*/
public function setupFromString(string $allowed)
{
// create the URI object directly from the given option
// without any form of detection from the server
$this->uri = new Uri($allowed);
// only create an allow list from absolute URLs
// otherwise the default secure host detection
// behavior will be used
if (empty($host = $this->uri->host()) === false) {
Server::hosts([$host]);
}
return $this->uri;
}
/**
* Returns the base URL for the environment
*
* @return string
*/
public function url(): string
{
return $this->uri;
}
}

View file

@ -16,7 +16,7 @@ use Kirby\Toolkit\Controller;
* @author Lukas Bestle <lukas@getkirby.com>,
* Ahmet Bora
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Event

View file

@ -21,7 +21,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Field

View file

@ -14,12 +14,12 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Fieldset extends Item
{
const ITEMS_CLASS = '\Kirby\Cms\Fieldsets';
public const ITEMS_CLASS = '\Kirby\Cms\Fieldsets';
protected $disabled;
protected $editable;

View file

@ -3,6 +3,7 @@
namespace Kirby\Cms;
use Closure;
use Kirby\Toolkit\A;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
@ -13,12 +14,12 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Fieldsets extends Items
{
const ITEM_CLASS = '\Kirby\Cms\Fieldset';
public const ITEM_CLASS = '\Kirby\Cms\Fieldset';
protected static function createFieldsets($params)
{
@ -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()
);
}
}

View file

@ -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
@ -24,19 +25,19 @@ use Kirby\Toolkit\A;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class File extends ModelWithContent
{
const CLASS_ALIAS = 'file';
use FileActions;
use FileModifications;
use HasMethods;
use HasSiblings;
use IsFile;
public const CLASS_ALIAS = 'file';
/**
* Cache for the initialized blueprint object
*
@ -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);
}

View file

@ -14,7 +14,7 @@ use Kirby\Form\Form;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait FileActions
@ -90,9 +90,11 @@ trait FileActions
*/
public function changeSort(int $sort)
{
return $this->commit('changeSort', ['file' => $this, 'position' => $sort], function ($file, $sort) {
return $file->save(['sort' => $sort]);
});
return $this->commit(
'changeSort',
['file' => $this, 'position' => $sort],
fn ($file, $sort) => $file->save(['sort' => $sort])
);
}
/**

View file

@ -12,7 +12,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class FileBlueprint extends Blueprint
@ -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;

View file

@ -10,7 +10,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait FileModifications
@ -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;

View file

@ -8,7 +8,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class FilePermissions extends ModelPermissions

View file

@ -12,7 +12,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class FilePicker extends Picker

View file

@ -15,7 +15,7 @@ use Kirby\Toolkit\V;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class FileRules

View file

@ -10,7 +10,7 @@ use Kirby\Filesystem\IsFile;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class FileVersion

View file

@ -16,7 +16,7 @@ use Kirby\Filesystem\F;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Files extends Collection
@ -135,11 +135,14 @@ class Files extends Collection
* human-readable format
* @since 3.6.0
*
* @param string|null|false $locale Locale for number formatting,
* `null` for the current locale,
* `false` to disable number formatting
* @return string
*/
public function niceSize(): string
public function niceSize($locale = null): string
{
return F::niceSize($this->size());
return F::niceSize($this->size(), $locale);
}
/**
@ -151,9 +154,7 @@ class Files extends Collection
*/
public function size(): int
{
return F::size($this->values(function ($file) {
return $file->root();
}));
return F::size($this->values(fn ($file) => $file->root()));
}
/**

View file

@ -14,7 +14,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Find

View file

@ -11,7 +11,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait HasChildren

View file

@ -8,7 +8,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait HasFiles

View file

@ -10,7 +10,7 @@ use Kirby\Exception\BadMethodCallException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait HasMethods

View file

@ -9,7 +9,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait HasSiblings

View file

@ -10,7 +10,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Html extends \Kirby\Toolkit\Html

View file

@ -11,7 +11,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Ingredients

View file

@ -15,15 +15,15 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Item
{
const ITEMS_CLASS = '\Kirby\Cms\Items';
use HasSiblings;
public const ITEMS_CLASS = '\Kirby\Cms\Items';
/**
* @var string
*/

View file

@ -12,12 +12,12 @@ use Exception;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Items extends Collection
{
const ITEM_CLASS = '\Kirby\Cms\Item';
public const ITEM_CLASS = '\Kirby\Cms\Item';
/**
* @var array

View file

@ -23,7 +23,7 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Language extends Model

View file

@ -15,7 +15,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class LanguageRouter
@ -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;

View file

@ -12,7 +12,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class LanguageRules

View file

@ -11,7 +11,7 @@ use Kirby\Filesystem\F;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Languages extends Collection
@ -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);
}

View file

@ -10,15 +10,15 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Layout extends Item
{
const ITEMS_CLASS = '\Kirby\Cms\Layouts';
use HasMethods;
public const ITEMS_CLASS = '\Kirby\Cms\Layouts';
/**
* @var \Kirby\Cms\Content
*/

View file

@ -12,15 +12,15 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class LayoutColumn extends Item
{
const ITEMS_CLASS = '\Kirby\Cms\LayoutColumns';
use HasMethods;
public const ITEMS_CLASS = '\Kirby\Cms\LayoutColumns';
/**
* @var \Kirby\Cms\Blocks
*/

View file

@ -9,10 +9,10 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class LayoutColumns extends Items
{
const ITEM_CLASS = '\Kirby\Cms\LayoutColumn';
public const ITEM_CLASS = '\Kirby\Cms\LayoutColumn';
}

View file

@ -12,12 +12,12 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Layouts extends Items
{
const ITEM_CLASS = '\Kirby\Cms\Layout';
public const ITEM_CLASS = '\Kirby\Cms\Layout';
public static function factory(array $items = null, array $params = [])
{

View file

@ -23,7 +23,7 @@ use Kirby\Filesystem\F;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Loader

View file

@ -15,7 +15,7 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Media

View file

@ -10,7 +10,7 @@ use Kirby\Toolkit\Properties;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
abstract class Model
@ -23,7 +23,7 @@ abstract class Model
* The CLASS_ALIAS is a short human-readable
* version of the class name. I.e. page.
*/
const CLASS_ALIAS = null;
public const CLASS_ALIAS = null;
/**
* The parent Kirby instance
@ -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();
}
/**

View file

@ -10,7 +10,7 @@ use Kirby\Toolkit\A;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
abstract class ModelPermissions

View file

@ -15,7 +15,7 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
abstract class ModelWithContent extends Model

View file

@ -13,7 +13,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Nest

View file

@ -11,7 +11,7 @@ use Kirby\Toolkit\Collection as BaseCollection;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class NestCollection extends BaseCollection
@ -26,8 +26,6 @@ class NestCollection extends BaseCollection
*/
public function toArray(Closure $map = null): array
{
return parent::toArray($map ?? function ($object) {
return $object->toArray();
});
return parent::toArray($map ?? fn ($object) => $object->toArray());
}
}

View file

@ -10,7 +10,7 @@ use Kirby\Toolkit\Obj;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class NestObject extends Obj

View file

@ -20,13 +20,11 @@ use Kirby\Toolkit\A;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Page extends ModelWithContent
{
const CLASS_ALIAS = 'page';
use PageActions;
use PageSiblings;
use HasChildren;
@ -34,6 +32,8 @@ class Page extends ModelWithContent
use HasMethods;
use HasSiblings;
public const CLASS_ALIAS = 'page';
/**
* All registered page methods
*
@ -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();
}
/**
@ -1338,7 +1338,7 @@ class Page extends ModelWithContent
'mediaUrl' => $this->mediaUrl(),
'mediaRoot' => $this->mediaRoot(),
'num' => $this->num(),
'parent' => $this->parent() ? $this->parent()->id(): null,
'parent' => $this->parent() ? $this->parent()->id() : null,
'slug' => $this->slug(),
'template' => $this->template(),
'translations' => $this->translations()->toArray(),

View file

@ -19,7 +19,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait PageActions
@ -201,9 +201,11 @@ trait PageActions
protected function changeStatusToDraft()
{
$arguments = ['page' => $this, 'status' => 'draft', 'position' => null];
$page = $this->commit('changeStatus', $arguments, function ($page) {
return $page->unpublish();
});
$page = $this->commit(
'changeStatus',
$arguments,
fn ($page) => $page->unpublish()
);
return $page;
}
@ -755,9 +757,7 @@ trait PageActions
->children()
->listed()
->append($this)
->filter(function ($page) {
return $page->blueprint()->num() === 'default';
});
->filter(fn ($page) => $page->blueprint()->num() === 'default');
// get a non-associative array of ids
$keys = $siblings->keys();
@ -780,10 +780,8 @@ trait PageActions
foreach ($sorted as $key => $id) {
if ($id === $this->id()) {
continue;
} else {
if ($sibling = $siblings->get($id)) {
$sibling->changeNum($key + 1);
}
} elseif ($sibling = $siblings->get($id)) {
$sibling->changeNum($key + 1);
}
}
@ -804,9 +802,7 @@ trait PageActions
->children()
->listed()
->not($this)
->filter(function ($page) {
return $page->blueprint()->num() === 'default';
});
->filter(fn ($page) => $page->blueprint()->num() === 'default');
if ($siblings->count() > 0) {
foreach ($siblings as $sibling) {

View file

@ -8,7 +8,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class PageBlueprint extends Blueprint

View file

@ -8,7 +8,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class PagePermissions extends ModelPermissions

View file

@ -13,7 +13,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class PagePicker extends Picker

View file

@ -14,7 +14,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class PageRules

View file

@ -8,7 +8,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait PageSiblings
@ -110,7 +110,7 @@ trait PageSiblings
*/
public function prevUnlisted($collection = null)
{
return $this->prevAll($collection)->unlisted()->first();
return $this->prevAll($collection)->unlisted()->last();
}
/**

View file

@ -17,7 +17,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Pages extends Collection
@ -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();
@ -205,6 +205,10 @@ class Pages extends Collection
*/
public function findById(string $id = null)
{
if ($id === null) {
return null;
}
// remove trailing or leading slashes
$id = trim($id, '/');

View file

@ -17,7 +17,7 @@ use Kirby\Toolkit\Pagination as BasePagination;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Pagination extends BasePagination
@ -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);

View file

@ -12,7 +12,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Permissions

View file

@ -9,7 +9,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
abstract class Picker

View file

@ -15,7 +15,7 @@ use Kirby\Toolkit\V;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Plugin extends Model

View file

@ -14,7 +14,7 @@ use Kirby\Http\Response;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class PluginAssets

View file

@ -10,7 +10,7 @@ use Kirby\Toolkit\Facade;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class R extends Facade

View file

@ -12,7 +12,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Responder

View file

@ -9,7 +9,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Response extends \Kirby\Http\Response

View file

@ -14,7 +14,7 @@ use Kirby\Toolkit\I18n;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Role extends Model
@ -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());
}
/**

View file

@ -13,7 +13,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Roles extends Collection

View file

@ -10,7 +10,7 @@ use Kirby\Toolkit\Facade;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class S extends Facade

View file

@ -11,7 +11,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Search

View file

@ -11,7 +11,7 @@ use Kirby\Toolkit\Component;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Section extends Component
@ -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);
}

View file

@ -17,18 +17,18 @@ use Kirby\Toolkit\A;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Site extends ModelWithContent
{
const CLASS_ALIAS = 'site';
use SiteActions;
use HasChildren;
use HasFiles;
use HasMethods;
public const CLASS_ALIAS = 'site';
/**
* The SiteBlueprint object
*
@ -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');
}
/**
@ -572,10 +572,10 @@ class Site extends ModelWithContent
return [
'children' => $this->children()->keys(),
'content' => $this->content()->toArray(),
'errorPage' => $this->errorPage() ? $this->errorPage()->id(): false,
'errorPage' => $this->errorPage() ? $this->errorPage()->id() : false,
'files' => $this->files()->keys(),
'homePage' => $this->homePage() ? $this->homePage()->id(): false,
'page' => $this->page() ? $this->page()->id(): false,
'homePage' => $this->homePage() ? $this->homePage()->id() : false,
'page' => $this->page() ? $this->page()->id() : false,
'title' => $this->title()->value(),
'url' => $this->url(),
];

View file

@ -10,7 +10,7 @@ use Closure;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait SiteActions

View file

@ -9,7 +9,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class SiteBlueprint extends Blueprint

View file

@ -8,7 +8,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class SitePermissions extends ModelPermissions

View file

@ -12,7 +12,7 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class SiteRules

View file

@ -15,7 +15,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Structure extends Collection

View file

@ -15,7 +15,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class StructureObject extends Model

View file

@ -25,7 +25,7 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class System
@ -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);

View file

@ -13,7 +13,7 @@ use Kirby\Toolkit\Tpl;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Template
@ -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;
}
/**

View file

@ -8,12 +8,12 @@ use Kirby\Toolkit\Str;
/**
* Wrapper around Kirby's localization files,
* which are store in `kirby/translations`.
* which are stored in `kirby/translations`.
*
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Translation

View file

@ -14,7 +14,7 @@ use Kirby\Filesystem\F;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Translations extends Collection

View file

@ -16,7 +16,7 @@ use Kirby\Http\Url as BaseUrl;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class Url extends BaseUrl

View file

@ -17,18 +17,18 @@ use Kirby\Toolkit\Str;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class User extends ModelWithContent
{
const CLASS_ALIAS = 'user';
use HasFiles;
use HasMethods;
use HasSiblings;
use UserActions;
public const CLASS_ALIAS = 'user';
/**
* @var UserBlueprint
*/
@ -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);
}
/**

View file

@ -19,7 +19,7 @@ use Throwable;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
trait UserActions

View file

@ -9,7 +9,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class UserBlueprint extends Blueprint

View file

@ -8,7 +8,7 @@ namespace Kirby\Cms;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class UserPermissions extends ModelPermissions

View file

@ -12,7 +12,7 @@ use Kirby\Exception\InvalidArgumentException;
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
class UserPicker extends Picker

Some files were not shown because too many files have changed in this diff Show more