mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-12-01 21:15:20 +08:00
Future/Frontend
* create php classes, each mirroring a js object * each frontend class implements __toString and json_serialize and as such can be directly used by the template * also allows for sane object creation before js screams in agony * usage TBD
This commit is contained in:
49
includes/components/frontend/infoboxmarkup.class.php
Normal file
49
includes/components/frontend/infoboxmarkup.class.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Aowow;
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('illegal access');
|
||||
|
||||
|
||||
class InfoboxMarkup extends Markup
|
||||
{
|
||||
public function __construct(private array $items = [], array $opts, string $parent = '')
|
||||
{
|
||||
parent::__construct('', $opts, $parent);
|
||||
}
|
||||
|
||||
public function addItem(string $item, ?int $pos = null) : void
|
||||
{
|
||||
if (is_null($pos) || $pos >= count($this->items))
|
||||
$this->items[] = $item;
|
||||
else
|
||||
array_splice($this->items, $pos, 0, $item);
|
||||
}
|
||||
|
||||
public function append(string $text) : self
|
||||
{
|
||||
if ($this->items && !$this->__text)
|
||||
$this->replace('[ul][li]' . implode('[/li][li]', $this->items) . '[/li][/ul]');
|
||||
|
||||
return parent::append($text);
|
||||
}
|
||||
|
||||
public function __toString() : string
|
||||
{
|
||||
if ($this->items && !$this->__text)
|
||||
$this->replace('[ul][li]' . implode('[/li][li]', $this->items) . '[/li][/ul]');
|
||||
|
||||
return parent::__toString();
|
||||
}
|
||||
|
||||
public function getJsGlobals() : array
|
||||
{
|
||||
if ($this->items && !$this->__text)
|
||||
$this->replace('[ul][li]' . implode('[/li][li]', $this->items) . '[/li][/ul]');
|
||||
|
||||
return parent::getJsGlobals();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user