lagdo /
ui-builder
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Lagdo\UiBuilder; |
||
| 4 | |||
| 5 | use Lagdo\UiBuilder\Component\Base\Component; |
||
| 6 | use Lagdo\UiBuilder\Component\Base\HtmlComponent; |
||
| 7 | use Lagdo\UiBuilder\Component\Html\Comment; |
||
| 8 | use Lagdo\UiBuilder\Component\Html\Element; |
||
| 9 | use Lagdo\UiBuilder\Component\Html\Html; |
||
| 10 | use Lagdo\UiBuilder\Component\Html\Text; |
||
| 11 | use Lagdo\UiBuilder\Component\Virtual\EachComponent; |
||
| 12 | use Lagdo\UiBuilder\Component\Virtual\ListComponent; |
||
| 13 | use Lagdo\UiBuilder\Component\Virtual\TakeComponent; |
||
| 14 | use Lagdo\UiBuilder\Component\Virtual\WhenComponent; |
||
| 15 | use Lagdo\UiBuilder\Html\HtmlBuilder; |
||
| 16 | use Closure; |
||
| 17 | |||
| 18 | abstract class AbstractBuilder implements BuilderInterface |
||
| 19 | { |
||
| 20 | use Builder\LayoutBuilderTrait; |
||
| 21 | use Builder\ButtonBuilderTrait; |
||
| 22 | use Builder\DropdownBuilderTrait; |
||
| 23 | use Builder\PanelBuilderTrait; |
||
| 24 | use Builder\FormBuilderTrait; |
||
| 25 | use Builder\MenuBuilderTrait; |
||
| 26 | use Builder\TabBuilderTrait; |
||
| 27 | use Builder\PaginationBuilderTrait; |
||
| 28 | use Builder\TableBuilderTrait; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var HtmlBuilder |
||
| 32 | */ |
||
| 33 | protected $builder; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The constructor |
||
| 37 | */ |
||
| 38 | public function __construct() |
||
| 39 | { |
||
| 40 | $this->builder = new HtmlBuilder(); |
||
| 41 | $this->builder->registerFactory('form', HtmlBuilder::TARGET_BUILDER, |
||
| 42 | fn(string $tagName, string $method, array $arguments) => |
||
| 43 | $this->createFormComponent($tagName, $arguments)); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param string $method |
||
| 48 | * @param array $arguments |
||
| 49 | * |
||
| 50 | * @return HtmlComponent |
||
| 51 | */ |
||
| 52 | public function __call(string $method, array $arguments): mixed |
||
| 53 | { |
||
| 54 | return $this->builder->callBuilderFactory($method, $arguments); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @inheritDoc |
||
| 59 | */ |
||
| 60 | public function registerFactory(string $tagPrefix, string $tagTarget, Closure $tagFactory): void |
||
| 61 | { |
||
| 62 | $this->builder->registerFactory($tagPrefix, $tagTarget, $tagFactory); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @inheritDoc |
||
| 67 | */ |
||
| 68 | public function tag(string $name, ...$arguments): HtmlComponent |
||
| 69 | { |
||
| 70 | return $this->builder->createComponent($name, $arguments); |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Create an element of a given class name |
||
| 75 | * |
||
| 76 | * @template T of HtmlComponent |
||
| 77 | * @psalm-param class-string<T> $class |
||
| 78 | * @param array $arguments |
||
| 79 | * |
||
| 80 | * @return T |
||
|
0 ignored issues
–
show
The type
Lagdo\UiBuilder\T was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 81 | */ |
||
| 82 | protected function createComponentOfClass(string $class, $arguments): HtmlComponent |
||
| 83 | { |
||
| 84 | return $this->builder->createComponent($class::$tag, $arguments, $class); |
||
|
0 ignored issues
–
show
|
|||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @inheritDoc |
||
| 89 | */ |
||
| 90 | public function each(array $values, Closure $closure): Component |
||
| 91 | { |
||
| 92 | return new EachComponent($values, $closure); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @inheritDoc |
||
| 97 | */ |
||
| 98 | public function list(...$arguments): Component |
||
| 99 | { |
||
| 100 | return new ListComponent($arguments); |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @inheritDoc |
||
| 105 | */ |
||
| 106 | public function when(bool $condition, Closure $closure): Component |
||
| 107 | { |
||
| 108 | return new WhenComponent($condition, $closure); |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @inheritDoc |
||
| 113 | */ |
||
| 114 | public function take(...$arguments): Component |
||
| 115 | { |
||
| 116 | return new TakeComponent($arguments); |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @inheritDoc |
||
| 121 | */ |
||
| 122 | public function text(string $text): Element |
||
| 123 | { |
||
| 124 | return new Text($text); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @inheritDoc |
||
| 129 | */ |
||
| 130 | public function html(string $html): Element |
||
| 131 | { |
||
| 132 | return new Html($html); |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @inheritDoc |
||
| 137 | */ |
||
| 138 | public function comment(string $comment): Element |
||
| 139 | { |
||
| 140 | return new Comment($comment); |
||
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @inheritDoc |
||
| 145 | */ |
||
| 146 | public function build(...$arguments): string |
||
| 147 | { |
||
| 148 | return $this->builder->build($arguments); |
||
| 149 | } |
||
| 150 | } |
||
| 151 |