<?php
namespace PHPFUI;
class Button extends \PHPFUI\HTML5Element
{
private bool $started = false;
public function __construct(protected string $text, protected string $link = '')
{
if ($link)
{
parent::__construct('a');
}
else
{
parent::__construct('button');
$this->addAttribute('type', 'button');
}
$this->addClass('button');
}
public function getLink() : string
{
return $this->link;
}
public function getText() : string
{
return $this->text;
}
public function setDisabled(bool $disabled = true) : static
{
if ($disabled)
{
$this->addClass('disabled');
}
else
{
$this->deleteClass('disabled');
}
return $this;
}
public function setLink(string $link) : static
{
$this->link = $link;
return $this;
}
public function setText(string $text) : static
{
$this->text = $text;
return $this;
}
protected function getStart() : string
{
if (! $this->started)
{
$this->started = true;
$this->add($this->text);
if ($this->link && ! $this->hasClass('disabled'))
{
$this->setAttribute('href', $this->link);
}
}
return parent::getStart();
}
}