1 | <?php |
||
4 | class Builder |
||
5 | { |
||
6 | |||
7 | /** |
||
8 | * A list of configuration parameters that can be used |
||
9 | * by tags, decorators etc when rendering |
||
10 | * |
||
11 | * @var array |
||
12 | */ |
||
13 | protected $options = array(); |
||
14 | |||
15 | /** |
||
16 | * tag-to-class name mappings |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $tagFactories = array( |
||
21 | 'button' => 'Sirius\Html\Tag\Button', |
||
22 | 'checkbox' => 'Sirius\Html\Tag\Checkbox', |
||
23 | 'file' => 'Sirius\Html\Tag\File', |
||
24 | 'hidden' => 'Sirius\Html\Tag\Hidden', |
||
25 | 'img' => 'Sirius\Html\Tag\Img', |
||
26 | 'multiselect' => 'Sirius\Html\Tag\MultiSelect', |
||
27 | 'password' => 'Sirius\Html\Tag\Password', |
||
28 | 'radio' => 'Sirius\Html\Tag\Radio', |
||
29 | 'select' => 'Sirius\Html\Tag\Select', |
||
30 | 'text' => 'Sirius\Html\Tag\Text', |
||
31 | 'textarea' => 'Sirius\Html\Tag\Textarea' |
||
32 | ); |
||
33 | |||
34 | /** |
||
35 | * @param array $options |
||
36 | */ |
||
37 | 8 | public function __construct($options = array()) |
|
41 | |||
42 | /** |
||
43 | * Sets a value of an option |
||
44 | * |
||
45 | * @param $name |
||
46 | * @param $value |
||
47 | */ |
||
48 | 2 | public function setOption($name, $value) |
|
52 | |||
53 | /** |
||
54 | * Get a configuration option |
||
55 | * |
||
56 | * @param $name |
||
57 | * |
||
58 | * @return null |
||
59 | */ |
||
60 | 2 | public function getOption($name) |
|
64 | |||
65 | /** |
||
66 | * Clones the instance and applies new set of options |
||
67 | * |
||
68 | * @param $options |
||
69 | * |
||
70 | * @return Builder |
||
71 | */ |
||
72 | 1 | public function with($options) |
|
81 | |||
82 | /** |
||
83 | * Add an element factory (class or callback) |
||
84 | * |
||
85 | * @param string $name |
||
86 | * @param mixed $classOrCallback |
||
87 | * |
||
88 | * @return self |
||
89 | */ |
||
90 | 8 | public function registerTag($name, $classOrCallback) |
|
96 | |||
97 | /** |
||
98 | * Make an HTML tag with a specific tag name (div, p, section etc) |
||
99 | * |
||
100 | * @param string $tag |
||
101 | * @param mixed $props |
||
102 | * @param mixed $content |
||
103 | * |
||
104 | * @throws \InvalidArgumentException |
||
105 | * @return Tag |
||
106 | */ |
||
107 | 6 | public function make($tag, $props = null, $content = null) |
|
133 | |||
134 | /** |
||
135 | * Magic method for creating HTML tags |
||
136 | * |
||
137 | * @example |
||
138 | * $builder->h1(null, 'Heading 1'); // <h1>Heading 1</h1> |
||
139 | * $builder->article(['class' => 'post-body'], 'Article body'); |
||
140 | * // outputs: '<article class='post-body'>Article body</article> |
||
141 | * |
||
142 | * $builder->someTag(); // <some-tag></some-tag> |
||
143 | * |
||
144 | * @param string $method |
||
145 | * @param array $args |
||
146 | * |
||
147 | * @return Tag |
||
148 | */ |
||
149 | 2 | public function __call($method, $args) |
|
165 | } |
||
166 |