diff --git a/extend/catcher/CatchForm.php b/extend/catcher/CatchForm.php index ee6747a..c8f0fae 100644 --- a/extend/catcher/CatchForm.php +++ b/extend/catcher/CatchForm.php @@ -6,12 +6,14 @@ namespace catcher; * @package catcher * * - * @method CatchForm text($column, $label = '') - * @method CatchForm image($column, $label = '') - * @method CatchForm radio($column, $label = '') - * @method CatchForm select($column, $label = '') - * @method CatchForm textarea($column, $label = '') - * @method CatchForm password($column, $label = '') + * @method CatchForm text($column, $label = '', $required = false) + * @method CatchForm image($column, $label = '', $required = false) + * @method CatchForm radio($column, $label = '', $required = false) + * @method CatchForm select($column, $label = '', $required = false) + * @method CatchForm textarea($column, $label = '', $required = false) + * @method CatchForm password($column, $label = '', $required = false) + * @method CatchForm hidden($column, $label = '', $required = false) + * @method CatchForm dom($column, $label = '', $required = false) * */ class CatchForm @@ -30,35 +32,65 @@ class CatchForm protected $btn; - public function action($acton) + /** + * + * @time 2019年12月10日 + * @param $acton + * @return CatchForm + */ + public function action($acton): CatchForm { $this->action = $acton; return $this; } - public function method($method) + /** + * + * @time 2019年12月10日 + * @param $method + * @return CatchForm + */ + public function method($method): CatchForm { $this->method = $method; return $this; } - public function formId($formId) + /** + * + * @time 2019年12月10日 + * @param $formId + * @return CatchForm + */ + public function formId($formId): CatchForm { $this->formId = $formId; return $this; } - public function enctype($enctype ="multipart/form-data") + /** + * + * @time 2019年12月10日 + * @param string $enctype + * @return CatchForm + */ + public function enctype($enctype ="multipart/form-data"): CatchForm { $this->enctype = $enctype; return $this; } - public function id($id) + /** + * + * @time 2019年12月10日 + * @param $id + * @return CatchForm + */ + public function id($id): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'id' => sprintf('id="%s"', $id), @@ -66,8 +98,15 @@ class CatchForm return $this; } - - public function class($class='', $labelClass = '', $inlineClass = '') + /** + * + * @time 2019年12月10日 + * @param string $class + * @param string $labelClass + * @param string $inlineClass + * @return CatchForm + */ + public function class($class='', $labelClass = '', $inlineClass = ''): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'class' => $class, @@ -78,7 +117,13 @@ class CatchForm return $this; } - public function options(array $options) + /** + * + * @time 2019年12月10日 + * @param array $options + * @return CatchForm + */ + public function options(array $options): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'options' => $options, @@ -87,7 +132,13 @@ class CatchForm return $this; } - public function default($value) + /** + * + * @time 2019年12月10日 + * @param $value + * @return CatchForm + */ + public function default($value): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'default' => $value, @@ -96,8 +147,12 @@ class CatchForm return $this; } - - public function disabled() + /** + * + * @time 2019年12月10日 + * @return CatchForm + */ + public function disabled(): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'disabled' => '', @@ -106,7 +161,14 @@ class CatchForm return $this; } - public function placeholder($content) + + /** + * + * @time 2019年12月10日 + * @param $content + * @return CatchForm + */ + public function placeholder($content): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'placeholder' => 'placeholder='.$content, @@ -115,7 +177,12 @@ class CatchForm return $this; } - public function readonly() + /** + * + * @time 2019年12月10日 + * @return CatchForm + */ + public function readonly(): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'readonly' => 'readonly', @@ -124,24 +191,35 @@ class CatchForm return $this; } - - public function render() + /** + * + * @time 2019年12月10日 + * @return string + */ + public function render(): string { $form = sprintf('
'; } - public function append($append) + /** + * + * @time 2019年12月10日 + * @param $append + * @return CatchForm + */ + public function append($append): CatchForm { $this->fields[$this->name] = array_merge($this->fields[$this->name], [ 'append' => $append, @@ -150,23 +228,36 @@ class CatchForm return $this; } + /** + * + * @time 2019年12月10日 + * @param $method + * @param $arguments + * @return $this + */ public function __call($method, $arguments) { // TODO: Implement __call() method. $this->name = $arguments[0] ?? ''; $label = $arguments[1] ?? ''; + $required = $arguments[2] ?? false; $this->fields[$this->name] = [ 'name' => $this->name, 'type' => $method, - 'label' => $label, + 'label' => $required ? '* '.$label : $label, 'inline' => false, ]; return $this; } - protected function inline() + /** + * + * @time 2019年12月10日 + * @return CatchForm + */ + protected function inline(): CatchForm { $this->fields[] = array_merge($this->fields, [ 'inline' => true, @@ -175,7 +266,12 @@ class CatchForm return $this; } - private function baseField() + /** + * + * @time 2019年12月10日 + * @return string + */ + private function baseField(): string { return '