Update Composer packages
This commit is contained in:
parent
0320235f6c
commit
a8b68fb61b
378 changed files with 28466 additions and 28852 deletions
|
@ -2,9 +2,15 @@
|
|||
|
||||
namespace Kirby\Text;
|
||||
|
||||
use AllowDynamicProperties;
|
||||
use Closure;
|
||||
use Kirby\Cms\App;
|
||||
use Kirby\Cms\File;
|
||||
use Kirby\Cms\Model;
|
||||
use Kirby\Exception\BadMethodCallException;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Uuid\Uri as UuidUri;
|
||||
use Kirby\Uuid\Uuid;
|
||||
|
||||
/**
|
||||
* Representation and parse of a single KirbyTag.
|
||||
|
@ -14,30 +20,30 @@ use Kirby\Exception\InvalidArgumentException;
|
|||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*
|
||||
* @todo remove the following psalm suppress when PHP >= 8.2 required
|
||||
* @psalm-suppress UndefinedAttributeClass
|
||||
*/
|
||||
#[AllowDynamicProperties]
|
||||
class KirbyTag
|
||||
{
|
||||
public static $aliases = [];
|
||||
public static $types = [];
|
||||
public static array $aliases = [];
|
||||
public static array $types = [];
|
||||
|
||||
public $attrs = [];
|
||||
public $data = [];
|
||||
public $options = [];
|
||||
public $type = null;
|
||||
public $value = null;
|
||||
public array $attrs = [];
|
||||
public array $data = [];
|
||||
public array $options = [];
|
||||
public string $type;
|
||||
public string|null $value = null;
|
||||
|
||||
public function __call(string $name, array $arguments = [])
|
||||
{
|
||||
return $this->data[$name] ?? $this->$name;
|
||||
}
|
||||
|
||||
public static function __callStatic(string $type, array $arguments = [])
|
||||
{
|
||||
return (new static($type, ...$arguments))->render();
|
||||
}
|
||||
|
||||
public function __construct(string $type, string $value = null, array $attrs = [], array $data = [], array $options = [])
|
||||
{
|
||||
public function __construct(
|
||||
string $type,
|
||||
string|null $value = null,
|
||||
array $attrs = [],
|
||||
array $data = [],
|
||||
array $options = []
|
||||
) {
|
||||
// type aliases
|
||||
if (isset(static::$types[$type]) === false) {
|
||||
if (isset(static::$aliases[$type]) === false) {
|
||||
throw new InvalidArgumentException('Undefined tag type: ' . $type);
|
||||
|
@ -70,6 +76,22 @@ class KirbyTag
|
|||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic data and property getter
|
||||
*/
|
||||
public function __call(string $name, array $arguments = [])
|
||||
{
|
||||
return $this->data[$name] ?? $this->$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic call `KirbyTag::myType($parameter1, $parameter2)`
|
||||
*/
|
||||
public static function __callStatic(string $type, array $arguments = []): string
|
||||
{
|
||||
return (new static($type, ...$arguments))->render();
|
||||
}
|
||||
|
||||
public function __get(string $attr)
|
||||
{
|
||||
$attr = strtolower($attr);
|
||||
|
@ -82,7 +104,7 @@ class KirbyTag
|
|||
return $this->$name ?? $default;
|
||||
}
|
||||
|
||||
public static function factory(...$arguments)
|
||||
public static function factory(...$arguments): string
|
||||
{
|
||||
return (new static(...$arguments))->render();
|
||||
}
|
||||
|
@ -92,14 +114,23 @@ class KirbyTag
|
|||
* The method first searches the file
|
||||
* in the current parent, if it's a page.
|
||||
* Afterwards it uses Kirby's global file finder.
|
||||
*
|
||||
* @param string $path
|
||||
* @return \Kirby\Cms\File|null
|
||||
*/
|
||||
public function file(string $path)
|
||||
public function file(string $path): File|null
|
||||
{
|
||||
$parent = $this->parent();
|
||||
|
||||
// check first for UUID
|
||||
if (Uuid::is($path, 'file') === true) {
|
||||
if (
|
||||
is_object($parent) === true &&
|
||||
method_exists($parent, 'files') === true
|
||||
) {
|
||||
$context = $parent->files();
|
||||
}
|
||||
|
||||
return Uuid::for($path, $context ?? null)->model();
|
||||
}
|
||||
|
||||
if (
|
||||
is_object($parent) === true &&
|
||||
method_exists($parent, 'file') === true &&
|
||||
|
@ -109,8 +140,8 @@ class KirbyTag
|
|||
}
|
||||
|
||||
if (
|
||||
is_a($parent, 'Kirby\Cms\File') === true &&
|
||||
$file = $parent->page()->file($path)
|
||||
$parent instanceof File &&
|
||||
$file = $parent->page()?->file($path)
|
||||
) {
|
||||
return $file;
|
||||
}
|
||||
|
@ -119,10 +150,8 @@ class KirbyTag
|
|||
}
|
||||
/**
|
||||
* Returns the current Kirby instance
|
||||
*
|
||||
* @return \Kirby\Cms\App
|
||||
*/
|
||||
public function kirby()
|
||||
public function kirby(): App
|
||||
{
|
||||
return $this->data['kirby'] ?? App::instance();
|
||||
}
|
||||
|
@ -132,14 +161,11 @@ class KirbyTag
|
|||
return $this->options[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param array $data
|
||||
* @param array $options
|
||||
* @return static
|
||||
*/
|
||||
public static function parse(string $string, array $data = [], array $options = [])
|
||||
{
|
||||
public static function parse(
|
||||
string $string,
|
||||
array $data = [],
|
||||
array $options = []
|
||||
): static {
|
||||
// remove the brackets, extract the first attribute (the tag type)
|
||||
$tag = trim(ltrim($string, '('));
|
||||
|
||||
|
@ -149,7 +175,8 @@ class KirbyTag
|
|||
$tag = substr($tag, 0, -1);
|
||||
}
|
||||
|
||||
$type = trim(substr($tag, 0, strpos($tag, ':')));
|
||||
$pos = strpos($tag, ':');
|
||||
$type = trim(substr($tag, 0, $pos ? $pos : null));
|
||||
$type = strtolower($type);
|
||||
$attr = static::$types[$type]['attr'] ?? [];
|
||||
|
||||
|
@ -157,8 +184,11 @@ class KirbyTag
|
|||
// to the list of possible attributes
|
||||
array_unshift($attr, $type);
|
||||
|
||||
// ensure that UUIDs protocols aren't matched as attributes
|
||||
$uuids = sprintf('(?!(%s):\/\/)', implode('|', UuidUri::$schemes));
|
||||
|
||||
// extract all attributes
|
||||
$regex = sprintf('/(%s):/i', implode('|', $attr));
|
||||
$regex = sprintf('/%s(%s):/i', $uuids, implode('|', $attr));
|
||||
$search = preg_split($regex, $tag, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// $search is now an array with alternating keys and values
|
||||
|
@ -185,10 +215,8 @@ class KirbyTag
|
|||
|
||||
/**
|
||||
* Returns the parent model
|
||||
*
|
||||
* @return \Kirby\Cms\Model|null
|
||||
*/
|
||||
public function parent()
|
||||
public function parent(): Model|null
|
||||
{
|
||||
return $this->data['parent'];
|
||||
}
|
||||
|
@ -197,7 +225,7 @@ class KirbyTag
|
|||
{
|
||||
$callback = static::$types[$this->type]['html'] ?? null;
|
||||
|
||||
if (is_a($callback, 'Closure') === true) {
|
||||
if ($callback instanceof Closure) {
|
||||
return (string)$callback($this);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,11 @@ use Kirby\Toolkit\Str;
|
|||
*/
|
||||
class KirbyTags
|
||||
{
|
||||
public static function parse(string $text = null, array $data = [], array $options = []): string
|
||||
{
|
||||
public static function parse(
|
||||
string|null $text = null,
|
||||
array $data = [],
|
||||
array $options = []
|
||||
): string {
|
||||
$regex = '!
|
||||
(?=[^\]]) # positive lookahead that matches a group after the main expression without including ] in the result
|
||||
(?=\([a-z0-9_-]+:) # positive lookahead that requires starts with ( and lowercase ASCII letters, digits, underscores or hyphens followed with : immediately to the right of the current location
|
||||
|
|
|
@ -23,16 +23,12 @@ class Markdown
|
|||
/**
|
||||
* Array with all configured options
|
||||
* for the parser
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
protected array $options = [];
|
||||
|
||||
/**
|
||||
* Returns default values for all
|
||||
* available parser options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function defaults(): array
|
||||
{
|
||||
|
@ -46,8 +42,6 @@ class Markdown
|
|||
/**
|
||||
* Creates a new Markdown parser
|
||||
* with the given options
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
|
@ -56,12 +50,8 @@ class Markdown
|
|||
|
||||
/**
|
||||
* Parses the given text and returns the HTML
|
||||
*
|
||||
* @param string|null $text
|
||||
* @param bool $inline
|
||||
* @return string
|
||||
*/
|
||||
public function parse(string $text = null, bool $inline = false): string
|
||||
public function parse(string|null $text = null, bool $inline = false): string
|
||||
{
|
||||
if ($this->options['extra'] === true) {
|
||||
$parser = new ParsedownExtra();
|
||||
|
@ -74,8 +64,8 @@ class Markdown
|
|||
|
||||
if ($inline === true) {
|
||||
return @$parser->line($text);
|
||||
} else {
|
||||
return @$parser->text($text);
|
||||
}
|
||||
|
||||
return @$parser->text($text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,23 +21,17 @@ class SmartyPants
|
|||
/**
|
||||
* Array with all configured options
|
||||
* for the parser
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
protected array $options = [];
|
||||
|
||||
/**
|
||||
* Michelf's parser object
|
||||
*
|
||||
* @var SmartyPantsTypographer
|
||||
*/
|
||||
protected $parser;
|
||||
protected SmartyPantsTypographer $parser;
|
||||
|
||||
/**
|
||||
* Returns default values for all
|
||||
* available parser options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function defaults(): array
|
||||
{
|
||||
|
@ -75,8 +69,6 @@ class SmartyPants
|
|||
/**
|
||||
* Creates a new SmartyPants parser
|
||||
* with the given options
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
|
@ -114,11 +106,8 @@ class SmartyPants
|
|||
|
||||
/**
|
||||
* Parses the given text
|
||||
*
|
||||
* @param string|null $text
|
||||
* @return string
|
||||
*/
|
||||
public function parse(string $text = null): string
|
||||
public function parse(string|null $text = null): string
|
||||
{
|
||||
// prepare the text
|
||||
$text = str_replace('"', '"', $text ?? '');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue