1
0

downgrade to kirby v3

This commit is contained in:
Philip Wagner
2024-09-01 10:47:15 +02:00
parent a4b2aece7b
commit af86acb7a1
1085 changed files with 54743 additions and 65042 deletions

View File

@@ -21,21 +21,37 @@ use Kirby\Toolkit\Str;
*/
class Element
{
public function __construct(
protected DOMElement $node,
protected array $marks = []
) {
/**
* @var array
*/
protected $marks;
/**
* @var \DOMElement
*/
protected $node;
/**
* @param \DOMElement $node
* @param array $marks
*/
public function __construct(DOMElement $node, array $marks = [])
{
$this->marks = $marks;
$this->node = $node;
}
/**
* The returns the attribute value or
* the given fallback if the attribute does not exist
*
* @param string $attr
* @param string|null $fallback
* @return string|null
*/
public function attr(
string $attr,
string|null $fallback = null
): string|null {
if ($this->node->hasAttribute($attr) === true) {
public function attr(string $attr, string $fallback = null): ?string
{
if ($this->node->hasAttribute($attr)) {
return $this->node->getAttribute($attr) ?? $fallback;
}
@@ -44,6 +60,8 @@ class Element
/**
* Returns a list of all child elements
*
* @return \DOMNodeList
*/
public function children(): DOMNodeList
{
@@ -52,6 +70,8 @@ class Element
/**
* Returns an array with all class names
*
* @return array
*/
public function classList(): array
{
@@ -60,16 +80,20 @@ class Element
/**
* Returns the value of the class attribute
*
* @return string|null
*/
public function className(): string|null
public function className(): ?string
{
return $this->attr('class');
}
/**
* Returns the original dom element
*
* @return \DOMElement
*/
public function element(): DOMElement
public function element()
{
return $this->node;
}
@@ -77,6 +101,9 @@ class Element
/**
* Returns an array with all nested elements
* that could be found for the given query
*
* @param string $query
* @return array
*/
public function filter(string $query): array
{
@@ -94,8 +121,11 @@ class Element
/**
* Tries to find a single nested element by
* query and otherwise returns null
*
* @param string $query
* @return \Kirby\Parsley\Element|null
*/
public function find(string $query): static|null
public function find(string $query)
{
if ($result = $this->query($query)[0]) {
return new static($result);
@@ -108,16 +138,17 @@ class Element
* Returns the inner HTML of the element
*
* @param array|null $marks List of allowed marks
* @return string
*/
public function innerHtml(array|null $marks = null): string
public function innerHtml(array $marks = null): string
{
$marks ??= $this->marks;
$inline = new Inline($this->node, $marks);
return $inline->innerHtml();
return (new Inline($this->node, $marks ?? $this->marks))->innerHtml();
}
/**
* Returns the contents as plain text
*
* @return string
*/
public function innerText(): string
{
@@ -126,31 +157,40 @@ class Element
/**
* Returns the full HTML for the element
*
* @param array|null $marks
* @return string
*/
public function outerHtml(array|null $marks = null): string
public function outerHtml(array $marks = null): string
{
return $this->node->ownerDocument->saveHtml($this->node);
}
/**
* Searches nested elements
*
* @param string $query
* @return DOMNodeList|null
*/
public function query(string $query): DOMNodeList|null
public function query(string $query)
{
$path = new DOMXPath($this->node->ownerDocument);
return $path->query($query, $this->node);
return (new DOMXPath($this->node->ownerDocument))->query($query, $this->node);
}
/**
* Removes the element from the DOM
*
* @return void
*/
public function remove(): void
public function remove()
{
$this->node->parentNode->removeChild($this->node);
}
/**
* Returns the name of the element
*
* @return string
*/
public function tagName(): string
{