Upgrade to 4.3.0

This commit is contained in:
Bastian Allgeier
2024-06-13 12:13:00 +02:00
parent 4b55753c46
commit e50c0341fc
87 changed files with 643 additions and 430 deletions

View File

@@ -30,6 +30,7 @@ use Kirby\Toolkit\A;
use Kirby\Toolkit\Config;
use Kirby\Toolkit\Controller;
use Kirby\Toolkit\LazyValue;
use Kirby\Toolkit\Locale;
use Kirby\Toolkit\Str;
use Kirby\Uuid\Uuid;
use Throwable;
@@ -170,7 +171,7 @@ class App
'roots' => $this->roots(),
'site' => $this->site(),
'urls' => $this->urls(),
'version' => $this->version(),
'version' => static::version(),
];
}
@@ -255,7 +256,7 @@ class App
foreach ($this->options as $key => $value) {
// detect option keys with the `vendor.plugin.option` format
if (preg_match('/^([a-z0-9-]+\.[a-z0-9-]+)\.(.*)$/i', $key, $matches) === 1) {
list(, $plugin, $option) = $matches;
[, $plugin, $option] = $matches;
// verify that it's really a plugin option
if (isset(static::$plugins[str_replace('.', '/', $plugin)]) !== true) {
@@ -538,6 +539,14 @@ class App
return false;
}
/**
* Returns the current language, if set by `static::setCurrentLanguage`
*/
public function currentLanguage(): Language|null
{
return $this->language ??= $this->defaultLanguage();
}
/**
* Returns the default language object
*/
@@ -623,7 +632,7 @@ class App
return Uuid::for($path, $parent?->files())->model();
}
$parent = $parent ?? $this->site();
$parent ??= $this->site();
$id = dirname($path);
$filename = basename($path);
@@ -879,7 +888,8 @@ class App
}
/**
* Returns the current language
* Returns the language by code or shortcut (`default`, `current`).
* Passing `null` is an alias for passing `current`
*/
public function language(string $code = null): Language|null
{
@@ -887,19 +897,11 @@ class App
return null;
}
if ($code === 'default') {
return $this->defaultLanguage();
}
// if requesting a non-default language,
// find it but don't cache it
if ($code !== null) {
return $this->languages()->find($code);
}
// otherwise return language set by `AppTranslation::setCurrentLanguage`
// or default language
return $this->language ??= $this->defaultLanguage();
return match ($code ?? 'current') {
'default' => $this->defaultLanguage(),
'current' => $this->currentLanguage(),
default => $this->languages()->find($code)
};
}
/**
@@ -1141,7 +1143,7 @@ class App
return null;
}
$parent = $parent ?? $this->site();
$parent ??= $this->site();
if ($page = $parent->find($id)) {
/**
@@ -1212,7 +1214,7 @@ class App
* @internal
* @throws \Kirby\Exception\NotFoundException if the home page cannot be found
*/
public function resolve(string $path = null, string $language = null): mixed
public function resolve(string|null $path = null, string|null $language = null): mixed
{
// set the current translation
$this->setCurrentTranslation($language);
@@ -1410,6 +1412,30 @@ class App
);
}
/**
* Load and set the current language if it exists
* Otherwise fall back to the default language
*
* @internal
*/
public function setCurrentLanguage(
string|null $languageCode = null
): Language|null {
if ($this->multilang() === false) {
Locale::set($this->option('locale', 'en_US.utf-8'));
return $this->language = null;
}
$this->language = $this->language($languageCode) ?? $this->defaultLanguage();
Locale::set($this->language->locale());
// add language slug rules to Str class
Str::$language = $this->language->rules();
return $this->language;
}
/**
* Create your own set of languages
*