123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace crmeb\form\components;
- use crmeb\form\BaseComponent;
- use crmeb\form\BuildInterface;
- class Select extends BaseComponent implements BuildInterface
- {
-
- const NAME = 'select';
-
- protected $rule = [
- 'title' => '',
- 'value' => '',
- 'type' => '',
- 'field' => '',
- 'info' => '',
- 'placeholder' => '',
- 'options' => [],
- ];
-
- public function __construct(string $field, string $title, $value = null)
- {
- $this->rule['title'] = $title;
- $this->rule['field'] = $field;
- $this->rule['value'] = !is_null($value) ? $value : null;
- }
-
- public function toArray(): array
- {
- $this->rule['name'] = self::NAME;
- $this->before();
- return $this->rule;
- }
-
- public function __call($name, $arguments)
- {
- if (in_array($name, ['title', 'field'])) {
- return $this;
- }
- $keys = array_keys($this->rule);
- if (in_array($name, $keys)) {
- $this->rule[$name] = $arguments[0] ?? null;
- }
- return $this;
- }
- }
|