Debian Codegraph @

vendor/ipl/web/src/Widget/StateBadge.php

raw
1 <?php
2
3 namespace ipl\Web\Widget;
4
5 use ipl\Html\BaseHtmlElement;
6
7 class StateBadge extends BaseHtmlElement
8 {
9 protected $defaultAttributes = ['class' => 'state-badge'];
10
11 /** @var mixed Badge content */
12 protected $content;
13
14 /** @var bool Whether the state is handled */
15 protected $isHandled;
16
17 /** @var string Textual representation of a state */
18 protected $state;
19
20 /**
21 * Create a new state badge
22 *
23 * @param mixed $content Content of the badge
24 * @param string $state Textual representation of a state
25 * @param bool $isHandled True if state is handled
26 */
27 public function __construct($content, string $state, bool $isHandled = false)
28 {
29 $this->content = $content;
30 $this->isHandled = $isHandled;
31 $this->state = $state;
32 }
33
34 protected function assemble()
35 {
36 $this->setTag('span');
37
38 $class = "state-{$this->state}";
39 if ($this->isHandled) {
40 $class .= ' handled';
41 }
42
43 $this->addAttributes(['class' => $class]);
44
45 $this->add($this->content);
46 }
47 }