diff --git a/src/AdamWathan/BootForms/BasicFormBuilder.php b/src/AdamWathan/BootForms/BasicFormBuilder.php index 5e6b9f6..62051b5 100644 --- a/src/AdamWathan/BootForms/BasicFormBuilder.php +++ b/src/AdamWathan/BootForms/BasicFormBuilder.php @@ -7,15 +7,32 @@ use AdamWathan\BootForms\Elements\InputGroup; use AdamWathan\Form\FormBuilder; +/** + * Class BasicFormBuilder + * @package AdamWathan\BootForms + */ class BasicFormBuilder { + /** + * @var FormBuilder + */ protected $builder; + /** + * BasicFormBuilder constructor. + * @param FormBuilder $builder + */ public function __construct(FormBuilder $builder) { $this->builder = $builder; } + /** + * @param $label + * @param $name + * @param $control + * @return GroupWrapper + */ protected function formGroup($label, $name, $control) { $label = $this->builder->label($label)->addClass('control-label')->forId($name); @@ -31,11 +48,21 @@ protected function formGroup($label, $name, $control) return $this->wrap($formGroup); } + /** + * @param $group + * @return GroupWrapper + */ protected function wrap($group) { return new GroupWrapper($group); } + /** + * @param $label + * @param $name + * @param null $value + * @return GroupWrapper + */ public function text($label, $name, $value = null) { $control = $this->builder->text($name)->value($value); @@ -43,6 +70,11 @@ public function text($label, $name, $value = null) return $this->formGroup($label, $name, $control); } + /** + * @param $label + * @param $name + * @return GroupWrapper + */ public function password($label, $name) { $control = $this->builder->password($name); @@ -50,16 +82,33 @@ public function password($label, $name) return $this->formGroup($label, $name, $control); } + /** + * @param $value + * @param null $name + * @param string $type + * @return \AdamWathan\Form\Elements\Button + */ public function button($value, $name = null, $type = "btn-default") { return $this->builder->button($value, $name)->addClass('btn')->addClass($type); } + /** + * @param string $value + * @param string $type + * @return \AdamWathan\Form\Elements\Button + */ public function submit($value = "Submit", $type = "btn-default") { return $this->builder->submit($value)->addClass('btn')->addClass($type); } + /** + * @param $label + * @param $name + * @param array $options + * @return GroupWrapper + */ public function select($label, $name, $options = []) { $control = $this->builder->select($name, $options); @@ -67,6 +116,11 @@ public function select($label, $name, $options = []) return $this->formGroup($label, $name, $control); } + /** + * @param $label + * @param $name + * @return GroupWrapper + */ public function checkbox($label, $name) { $control = $this->builder->checkbox($name); @@ -74,17 +128,34 @@ public function checkbox($label, $name) return $this->checkGroup($label, $name, $control); } + /** + * @param $label + * @param $name + * @return $this + */ public function inlineCheckbox($label, $name) { return $this->checkbox($label, $name)->inline(); } + /** + * @param $label + * @param $name + * @param $control + * @return GroupWrapper + */ protected function checkGroup($label, $name, $control) { $checkGroup = $this->buildCheckGroup($label, $name, $control); return $this->wrap($checkGroup->addClass('checkbox')); } + /** + * @param $label + * @param $name + * @param $control + * @return CheckGroup + */ protected function buildCheckGroup($label, $name, $control) { $label = $this->builder->label($label, $name)->after($control)->addClass('control-label'); @@ -98,6 +169,12 @@ protected function buildCheckGroup($label, $name, $control) return $checkGroup; } + /** + * @param $label + * @param $name + * @param null $value + * @return GroupWrapper + */ public function radio($label, $name, $value = null) { if (is_null($value)) { @@ -109,17 +186,34 @@ public function radio($label, $name, $value = null) return $this->radioGroup($label, $name, $control); } + /** + * @param $label + * @param $name + * @param null $value + * @return \AdamWathan\Form\Elements\RadioButton + */ public function inlineRadio($label, $name, $value = null) { return $this->radio($label, $name, $value)->inline(); } + /** + * @param $label + * @param $name + * @param $control + * @return GroupWrapper + */ protected function radioGroup($label, $name, $control) { $checkGroup = $this->buildCheckGroup($label, $name, $control); return $this->wrap($checkGroup->addClass('radio')); } + /** + * @param $label + * @param $name + * @return GroupWrapper + */ public function textarea($label, $name) { $control = $this->builder->textarea($name); @@ -127,6 +221,12 @@ public function textarea($label, $name) return $this->formGroup($label, $name, $control); } + /** + * @param $label + * @param $name + * @param null $value + * @return GroupWrapper + */ public function date($label, $name, $value = null) { $control = $this->builder->date($name)->value($value); @@ -134,6 +234,12 @@ public function date($label, $name, $value = null) return $this->formGroup($label, $name, $control); } + /** + * @param $label + * @param $name + * @param null $value + * @return GroupWrapper + */ public function email($label, $name, $value = null) { $control = $this->builder->email($name)->value($value); @@ -141,6 +247,12 @@ public function email($label, $name, $value = null) return $this->formGroup($label, $name, $control); } + /** + * @param $label + * @param $name + * @param null $value + * @return GroupWrapper + */ public function file($label, $name, $value = null) { $control = $this->builder->file($name)->value($value); @@ -157,6 +269,12 @@ public function file($label, $name, $value = null) return $this->wrap($formGroup); } + /** + * @param $label + * @param $name + * @param null $value + * @return GroupWrapper + */ public function inputGroup($label, $name, $value = null) { $control = new InputGroup($name); @@ -167,6 +285,11 @@ public function inputGroup($label, $name, $value = null) return $this->formGroup($label, $name, $control); } + /** + * @param $method + * @param $parameters + * @return mixed + */ public function __call($method, $parameters) { return call_user_func_array([$this->builder, $method], $parameters); diff --git a/src/AdamWathan/BootForms/BootForm.php b/src/AdamWathan/BootForms/BootForm.php index 5ba43e9..2f03b70 100644 --- a/src/AdamWathan/BootForms/BootForm.php +++ b/src/AdamWathan/BootForms/BootForm.php @@ -1,23 +1,73 @@ basicFormBuilder = $basicFormBuilder; $this->horizontalFormBuilder = $horizontalFormBuilder; } + /** + * @return \AdamWathan\Form\Elements\FormOpen + */ public function open() { $this->builder = $this->basicFormBuilder; return $this->builder->open(); } + /** + * @param $columnSizes + * @return \AdamWathan\Form\Elements\FormOpen + */ public function openHorizontal($columnSizes) { $this->horizontalFormBuilder->setColumnSizes($columnSizes); diff --git a/src/AdamWathan/BootForms/Elements/CheckGroup.php b/src/AdamWathan/BootForms/Elements/CheckGroup.php index 9c25485..2e7c049 100644 --- a/src/AdamWathan/BootForms/Elements/CheckGroup.php +++ b/src/AdamWathan/BootForms/Elements/CheckGroup.php @@ -2,16 +2,33 @@ use AdamWathan\Form\Elements\Label; +/** + * Class CheckGroup + * @package AdamWathan\BootForms\Elements + */ class CheckGroup extends FormGroup { + /** + * @var Label + */ protected $label; + /** + * @var bool + */ protected $inline = false; + /** + * CheckGroup constructor. + * @param Label $label + */ public function __construct(Label $label) { $this->label = $label; } + /** + * @return string + */ public function render() { if ($this->inline === true) { @@ -29,6 +46,9 @@ public function render() return $html; } + /** + * @return $this + */ public function inline() { $this->inline = true; @@ -39,11 +59,19 @@ public function inline() return $this; } + /** + * @return \AdamWathan\Form\Elements\Element + */ public function control() { return $this->label->getControl(); } + /** + * @param $method + * @param $parameters + * @return $this + */ public function __call($method, $parameters) { call_user_func_array([$this->label->getControl(), $method], $parameters); diff --git a/src/AdamWathan/BootForms/Elements/FormGroup.php b/src/AdamWathan/BootForms/Elements/FormGroup.php index 091f809..3f054b1 100644 --- a/src/AdamWathan/BootForms/Elements/FormGroup.php +++ b/src/AdamWathan/BootForms/Elements/FormGroup.php @@ -3,12 +3,30 @@ use AdamWathan\Form\Elements\Element; use AdamWathan\Form\Elements\Label; +/** + * Class FormGroup + * @package AdamWathan\BootForms\Elements + */ class FormGroup extends Element { + /** + * @var Label + */ protected $label; + /** + * @var Element + */ protected $control; + /** + * @var + */ protected $helpBlock; + /** + * FormGroup constructor. + * @param Label $label + * @param Element $control + */ public function __construct(Label $label, Element $control) { $this->label = $label; @@ -16,6 +34,9 @@ public function __construct(Label $label, Element $control) $this->addClass('form-group'); } + /** + * @return string + */ public function render() { $html = 'helpBlock)) { @@ -39,6 +64,9 @@ public function helpBlock($text) return $this; } + /** + * @return string + */ protected function renderHelpBlock() { if ($this->helpBlock) { @@ -48,16 +76,27 @@ protected function renderHelpBlock() return ''; } + /** + * @return Element + */ public function control() { return $this->control; } + /** + * @return Label + */ public function label() { return $this->label; } + /** + * @param $method + * @param $parameters + * @return $this + */ public function __call($method, $parameters) { call_user_func_array([$this->control, $method], $parameters); diff --git a/src/AdamWathan/BootForms/Elements/GroupWrapper.php b/src/AdamWathan/BootForms/Elements/GroupWrapper.php index 14b6254..55704f1 100644 --- a/src/AdamWathan/BootForms/Elements/GroupWrapper.php +++ b/src/AdamWathan/BootForms/Elements/GroupWrapper.php @@ -2,87 +2,149 @@ use AdamWathan\Form\Elements\Label; +/** + * Class GroupWrapper + * @package AdamWathan\BootForms\Elements + */ class GroupWrapper { + /** + * @var FormGroup + */ protected $formGroup; + + /** + * @var + */ protected $target; - public function __construct($formGroup) + /** + * GroupWrapper constructor. + * @param FormGroup $formGroup + */ + public function __construct(FormGroup $formGroup) { $this->formGroup = $formGroup; $this->target = $formGroup->control(); } + /** + * @return string + */ public function render() { return $this->formGroup->render(); } + /** + * @param $text + * @return $this + */ public function helpBlock($text) { $this->formGroup->helpBlock($text); return $this; } + /** + * @return string + */ public function __toString() { return $this->render(); } + /** + * @param string $class + * @return $this + */ public function addGroupClass($class) { $this->formGroup->addClass($class); return $this; } + /** + * @param string $class + * @return $this + */ public function removeGroupClass($class) { $this->formGroup->removeClass($class); return $this; } + /** + * @param string $attribute + * @param string $value + * @return $this + */ public function groupData($attribute, $value) { $this->formGroup->data($attribute, $value); return $this; } + /** + * @param string $class + * @return $this + */ public function labelClass($class) { $this->formGroup->label()->addClass($class); return $this; } + /** + * @return $this + */ public function hideLabel() { $this->labelClass('sr-only'); return $this; } + /** + * @return $this + */ public function inline() { $this->formGroup->inline(); return $this; } + /** + * @return $this + */ public function group() { $this->target = $this->formGroup; return $this; } + /** + * @return $this + */ public function label() { $this->target = $this->formGroup->label(); return $this; } + /** + * @return $this + */ public function control() { $this->target = $this->formGroup->control(); return $this; } + /** + * @param $method + * @param $parameters + * @return $this + */ public function __call($method, $parameters) { call_user_func_array([$this->target, $method], $parameters); diff --git a/src/AdamWathan/BootForms/Elements/HelpBlock.php b/src/AdamWathan/BootForms/Elements/HelpBlock.php index 421a23c..f7407bb 100644 --- a/src/AdamWathan/BootForms/Elements/HelpBlock.php +++ b/src/AdamWathan/BootForms/Elements/HelpBlock.php @@ -2,16 +2,30 @@ use AdamWathan\Form\Elements\Element; +/** + * Class HelpBlock + * @package AdamWathan\BootForms\Elements + */ class HelpBlock extends Element { + /** + * @var string + */ private $message; + /** + * HelpBlock constructor. + * @param $message + */ public function __construct($message) { $this->message = $message; $this->addClass('help-block'); } + /** + * @return string + */ public function render() { $html = 'controlSizes = $controlSizes; } + /** + * @return string + */ public function render() { $html = 'control, $method], $parameters); diff --git a/src/AdamWathan/BootForms/Elements/InputGroup.php b/src/AdamWathan/BootForms/Elements/InputGroup.php index 6cadad8..25f9acd 100644 --- a/src/AdamWathan/BootForms/Elements/InputGroup.php +++ b/src/AdamWathan/BootForms/Elements/InputGroup.php @@ -2,12 +2,26 @@ use AdamWathan\Form\Elements\Text; +/** + * Class InputGroup + * @package AdamWathan\BootForms\Elements + */ class InputGroup extends Text { + /** + * @var array + */ protected $beforeAddon = []; + /** + * @var array + */ protected $afterAddon = []; + /** + * @param $addon + * @return $this + */ public function beforeAddon($addon) { $this->beforeAddon[] = $addon; @@ -15,6 +29,10 @@ public function beforeAddon($addon) return $this; } + /** + * @param $addon + * @return $this + */ public function afterAddon($addon) { $this->afterAddon[] = $addon; @@ -22,12 +40,20 @@ public function afterAddon($addon) return $this; } + /** + * @param $type + * @return $this + */ public function type($type) { $this->attributes['type'] = $type; return $this; } + /** + * @param array $addons + * @return string + */ protected function renderAddons($addons) { $html = ''; @@ -41,6 +67,9 @@ protected function renderAddons($addons) return $html; } + /** + * @return string + */ public function render() { $html = '
'; diff --git a/src/AdamWathan/BootForms/Elements/OffsetFormGroup.php b/src/AdamWathan/BootForms/Elements/OffsetFormGroup.php index 9dc96df..77f12f5 100644 --- a/src/AdamWathan/BootForms/Elements/OffsetFormGroup.php +++ b/src/AdamWathan/BootForms/Elements/OffsetFormGroup.php @@ -1,16 +1,34 @@ control = $control; $this->columnSizes = $columnSizes; } + /** + * @return string + */ public function render() { $html = '
'; @@ -23,12 +41,19 @@ public function render() return $html; } - public function setColumnSizes($columnSizes) + /** + * @param array $columnSizes + * @return $this + */ + public function setColumnSizes(array $columnSizes) { $this->columnSizes = $columnSizes; return $this; } + /** + * @return string + */ protected function getControlClass() { $class = ''; @@ -38,11 +63,19 @@ protected function getControlClass() return trim($class); } + /** + * @return string + */ public function __toString() { return $this->render(); } + /** + * @param $method + * @param $parameters + * @return $this + */ public function __call($method, $parameters) { call_user_func_array([$this->control, $method], $parameters); diff --git a/src/AdamWathan/BootForms/HorizontalFormBuilder.php b/src/AdamWathan/BootForms/HorizontalFormBuilder.php index 03de8a1..67702bb 100644 --- a/src/AdamWathan/BootForms/HorizontalFormBuilder.php +++ b/src/AdamWathan/BootForms/HorizontalFormBuilder.php @@ -6,29 +6,54 @@ use AdamWathan\BootForms\Elements\OffsetFormGroup; use AdamWathan\Form\FormBuilder; +/** + * Class HorizontalFormBuilder + * @package AdamWathan\BootForms + */ class HorizontalFormBuilder extends BasicFormBuilder { protected $columnSizes; + /** + * @var FormBuilder + */ protected $builder; + /** + * HorizontalFormBuilder constructor. + * @param FormBuilder $builder + * @param array $columnSizes + */ public function __construct(FormBuilder $builder, $columnSizes = ['lg' => [2, 10]]) { - $this->builder = $builder; + parent::__construct($builder); $this->columnSizes = $columnSizes; } + /** + * @param $columnSizes + * @return $this + */ public function setColumnSizes($columnSizes) { $this->columnSizes = $columnSizes; return $this; } + /** + * @return \AdamWathan\Form\Elements\FormOpen + */ public function open() { return $this->builder->open()->addClass('form-horizontal'); } + /** + * @param $label + * @param $name + * @param $control + * @return Elements\GroupWrapper + */ protected function formGroup($label, $name, $control) { $label = $this->builder->label($label, $name) @@ -48,6 +73,9 @@ protected function formGroup($label, $name, $control) return $this->wrap($formGroup); } + /** + * @return array + */ protected function getControlSizes() { $controlSizes = []; @@ -57,6 +85,9 @@ protected function getControlSizes() return $controlSizes; } + /** + * @return string + */ protected function getLabelClass() { $class = ''; @@ -66,18 +97,34 @@ protected function getLabelClass() return trim($class); } + /** + * @param $value + * @param null $name + * @param string $type + * @return OffsetFormGroup + */ public function button($value, $name = null, $type = "btn-default") { $button = $this->builder->button($value, $name)->addClass('btn')->addClass($type); return new OffsetFormGroup($button, $this->columnSizes); } + /** + * @param string $value + * @param string $type + * @return OffsetFormGroup + */ public function submit($value = "Submit", $type = "btn-default") { $button = $this->builder->submit($value)->addClass('btn')->addClass($type); return new OffsetFormGroup($button, $this->columnSizes); } + /** + * @param $label + * @param $name + * @return OffsetFormGroup + */ public function checkbox($label, $name) { $control = $this->builder->checkbox($name); @@ -86,6 +133,12 @@ public function checkbox($label, $name) return new OffsetFormGroup($this->wrap($checkGroup), $this->columnSizes); } + /** + * @param $label + * @param $name + * @param $control + * @return CheckGroup + */ protected function checkGroup($label, $name, $control) { $label = $this->builder->label($label, $name)->after($control); @@ -100,6 +153,12 @@ protected function checkGroup($label, $name, $control) return $checkGroup; } + /** + * @param $label + * @param $name + * @param null $value + * @return OffsetFormGroup + */ public function radio($label, $name, $value = null) { if (is_null($value)) { @@ -112,6 +171,12 @@ public function radio($label, $name, $value = null) return new OffsetFormGroup($this->wrap($checkGroup), $this->columnSizes); } + /** + * @param $label + * @param $name + * @param null $value + * @return HorizontalFormGroup + */ public function file($label, $name, $value = null) { $control = $this->builder->file($name)->value($value); @@ -132,6 +197,11 @@ public function file($label, $name, $value = null) return $formGroup; } + /** + * @param $method + * @param $parameters + * @return mixed + */ public function __call($method, $parameters) { return call_user_func_array([$this->builder, $method], $parameters);