namespace App\FluentComponents;
class Label
{
protected $value;
public function value($text)
{
$this->value = $text;
return $this;
}
public function build()
{
return '<label>' . $this->value . '</label>';
}
public static function builder()
{
return new self();
}
}
----------------------------------------------------------------------
namespace App\FluentComponents;
class Card
{
protected $sections = [];
public function section($components)
{
$this->sections[] = $components;
return $this;
}
public function build()
{
$html = '<div class="card">';
foreach ($this->sections as $section) {
$html .= '<div class="card-section">';
foreach ($section as $component) {
$html .= $component->build();
}
$html .= '</div>';
}
$html .= '</div>';
return $html;
}
public static function builder()
{
return new self();
}
}
-------------------------------------------------------------
use App\FluentComponents\Card;
use App\FluentComponents\Label;
$cardHtml = Card::builder()
->section([
Label::builder()->value('Label 1'),
Label::builder()->value('Label 2')
])
->build();
echo $cardHtml;