Update Composer packages

This commit is contained in:
Paul Nicoué 2023-06-01 16:54:20 +02:00
parent 76a5c7ea8b
commit 9252d9ce90
32 changed files with 906 additions and 114 deletions

View file

@ -555,10 +555,8 @@ class App
/**
* Returns the default language object
*
* @return \Kirby\Cms\Language|null
*/
public function defaultLanguage()
public function defaultLanguage(): Language|null
{
return $this->defaultLanguage ??= $this->languages()->default();
}
@ -577,22 +575,21 @@ class App
/**
* Detect the preferred language from the visitor object
*
* @return \Kirby\Cms\Language
*/
public function detectedLanguage()
public function detectedLanguage(): Language|null
{
$languages = $this->languages();
$visitor = $this->visitor();
foreach ($visitor->acceptedLanguages() as $lang) {
if ($language = $languages->findBy('locale', $lang->locale(LC_ALL))) {
foreach ($visitor->acceptedLanguages() as $acceptedLang) {
$closure = fn ($language) => $language->locale(LC_ALL) === $acceptedLang->locale();
if ($language = $languages->filter($closure)?->first()) {
return $language;
}
}
foreach ($visitor->acceptedLanguages() as $lang) {
if ($language = $languages->findBy('code', $lang->code())) {
foreach ($visitor->acceptedLanguages() as $acceptedLang) {
if ($language = $languages->findBy('code', $acceptedLang->code())) {
return $language;
}
}

View file

@ -25,6 +25,13 @@ class Blocks extends Items
{
public const ITEM_CLASS = Block::class;
/**
* All registered blocks methods
*
* @var array
*/
public static $methods = [];
/**
* Return HTML when the collection is
* converted to a string

View file

@ -459,10 +459,19 @@ class Blueprint
// groups don't need all the crap
if ($type === 'group') {
$fields = $props['fields'];
if (isset($props['when']) === true) {
$fields = array_map(
fn ($field) => array_replace_recursive(['when' => $props['when']], $field),
$fields
);
}
return [
'fields' => $props['fields'],
'fields' => $fields,
'name' => $name,
'type' => $type,
'type' => $type
];
}

View file

@ -21,6 +21,13 @@ class Fieldsets extends Items
{
public const ITEM_CLASS = Fieldset::class;
/**
* All registered fieldsets methods
*
* @var array
*/
public static $methods = [];
protected static function createFieldsets($params)
{
$fieldsets = [];

View file

@ -172,15 +172,21 @@ class File extends ModelWithContent
* other content.
*
* @internal
* @param array $data
* @param string|null $languageCode
* @return array
*/
public function contentFileData(array $data, string $languageCode = null): array
{
return A::append($data, [
'template' => $data['template'] ?? $this->template(),
]);
public function contentFileData(
array $data,
string $languageCode = null
): array {
// only add the template in, if the $data array
// doesn't explicitly unsets it
if (
array_key_exists('template', $data) === false &&
$template = $this->template()
) {
$data['template'] = $template;
}
return $data;
}
/**

View file

@ -21,6 +21,13 @@ class Items extends Collection
protected Field|null $field;
/**
* All registered items methods
*
* @var array
*/
public static $methods = [];
/**
* @var array
*/

View file

@ -16,6 +16,13 @@ use Kirby\Filesystem\F;
*/
class Languages extends Collection
{
/**
* All registered languages methods
*
* @var array
*/
public static $methods = [];
/**
* Creates a new collection with the given language objects
*

View file

@ -15,4 +15,11 @@ namespace Kirby\Cms;
class LayoutColumns extends Items
{
public const ITEM_CLASS = LayoutColumn::class;
/**
* All registered layout columns methods
*
* @var array
*/
public static $methods = [];
}

View file

@ -20,6 +20,13 @@ class Layouts extends Items
{
public const ITEM_CLASS = Layout::class;
/**
* All registered layouts methods
*
* @var array
*/
public static $methods = [];
public static function factory(array $items = null, array $params = [])
{
$first = $items[0] ?? [];

View file

@ -536,29 +536,43 @@ trait PageActions
// create a temporary page object
$page = Page::factory($props);
// always create pages in the default language
if ($page->kirby()->multilang() === true) {
$languageCode = $page->kirby()->defaultLanguage()->code();
} else {
$languageCode = null;
}
// create a form for the page
$form = Form::for($page, ['values' => $props['content']]);
// use always default language to fill form with default values
$form = Form::for(
$page,
[
'language' => $languageCode,
'values' => $props['content']
]
);
// inject the content
$page = $page->clone(['content' => $form->strings(true)]);
// run the hooks and creation action
$page = $page->commit('create', ['page' => $page, 'input' => $props], function ($page, $props) {
// always create pages in the default language
if ($page->kirby()->multilang() === true) {
$languageCode = $page->kirby()->defaultLanguage()->code();
} else {
$languageCode = null;
$page = $page->commit(
'create',
[
'page' => $page,
'input' => $props
],
function ($page, $props) use ($languageCode) {
// write the content file
$page = $page->save($page->content()->toArray(), $languageCode);
// flush the parent cache to get children and drafts right
static::updateParentCollections($page, 'append');
return $page;
}
// write the content file
$page = $page->save($page->content()->toArray(), $languageCode);
// flush the parent cache to get children and drafts right
static::updateParentCollections($page, 'append');
return $page;
});
);
// publish the new page if a number is given
if (isset($props['num']) === true) {

View file

@ -18,6 +18,13 @@ namespace Kirby\Cms;
*/
class Roles extends Collection
{
/**
* All registered roles methods
*
* @var array
*/
public static $methods = [];
/**
* Returns a filtered list of all
* roles that can be created by the

View file

@ -20,6 +20,13 @@ use Kirby\Exception\InvalidArgumentException;
*/
class Structure extends Collection
{
/**
* All registered structure methods
*
* @var array
*/
public static $methods = [];
/**
* Creates a new Collection with the given objects
*

View file

@ -19,6 +19,13 @@ use Kirby\Filesystem\F;
*/
class Translations extends Collection
{
/**
* All registered translations methods
*
* @var array
*/
public static $methods = [];
/**
* @param string $code
* @return void

View file

@ -2,11 +2,11 @@
namespace Kirby\Data;
use Kirby\Cms\App;
use Kirby\Exception\InvalidArgumentException;
use Spyc;
/**
* Simple Wrapper around the Spyc YAML class
* Simple Wrapper around the Symfony or Spyc YAML class
*
* @package Kirby Data
* @author Bastian Allgeier <bastian@getkirby.com>
@ -21,8 +21,10 @@ class Yaml extends Handler
*/
public static function encode($data): string
{
// $data, $indent, $wordwrap, $no_opening_dashes
return Spyc::YAMLDump($data, false, false, true);
return match (static::handler()) {
'symfony' => YamlSymfony::encode($data),
default => YamlSpyc::encode($data),
};
}
/**
@ -42,16 +44,19 @@ class Yaml extends Handler
throw new InvalidArgumentException('Invalid YAML data; please pass a string');
}
// remove BOM
$string = str_replace("\xEF\xBB\xBF", '', $string);
$result = Spyc::YAMLLoadString($string);
return match (static::handler()) {
'symfony' => YamlSymfony::decode($string),
default => YamlSpyc::decode($string)
};
}
if (is_array($result) === true) {
return $result;
}
// apparently Spyc always returns an array, even for invalid YAML syntax
// so this Exception should currently never be thrown
throw new InvalidArgumentException('The YAML data cannot be parsed'); // @codeCoverageIgnore
/**
* Returns which YAML parser (`spyc` or `symfony`)
* is configured to be used
* @internal
*/
public static function handler(): string
{
return App::instance(null, true)?->option('yaml.handler') ?? 'spyc';
}
}

View file

@ -521,12 +521,26 @@ class F
Dir::make($directory, true);
}
// actually move the file
if (rename($oldRoot, $newRoot) !== true) {
return false;
// atomically moving the file will only work if
// source and target are on the same filesystem
if (stat($oldRoot)['dev'] === stat($directory)['dev']) {
// same filesystem, we can move the file
return rename($oldRoot, $newRoot) === true;
}
return true;
// @codeCoverageIgnoreStart
// not the same filesystem; we need to copy
// the file and unlink the source afterwards
if (copy($oldRoot, $newRoot) === true) {
return unlink($oldRoot) === true;
}
// copying failed, ensure the new root isn't there
// (e.g. if the file could be created but there's no
// more remaining disk space to write its contents)
static::remove($newRoot);
return false;
// @codeCoverageIgnoreEnd
}
/**

View file

@ -224,7 +224,7 @@ class Blocks extends Plain
'tag' => 'a',
'attrs' => ['href', 'rel', 'target', 'title'],
'defaults' => [
'rel' => 'noopener noreferrer'
'rel' => 'noreferrer'
]
],
[

View file

@ -358,7 +358,7 @@ class Html extends Xml
}
/**
* Add noopener & noreferrer to rels when target is `_blank`
* Add noreferrer to rels when target is `_blank`
*
* @param string|null $rel Current `rel` value
* @param string|null $target Current `target` value
@ -373,7 +373,7 @@ class Html extends Xml
return $rel;
}
return trim($rel . ' noopener noreferrer', ' ');
return trim($rel . ' noreferrer', ' ');
}
return $rel ?: null;