diff --git a/src/AdamWathan/Form/Binding/BoundData.php b/src/AdamWathan/Form/Binding/BoundData.php index d6a9a50..cb86d05 100644 --- a/src/AdamWathan/Form/Binding/BoundData.php +++ b/src/AdamWathan/Form/Binding/BoundData.php @@ -2,25 +2,46 @@ namespace AdamWathan\Form\Binding; +/** + * Class BoundData + * @package AdamWathan\Form\Binding + */ class BoundData { protected $data; + /** + * BoundData constructor. + * @param $data + */ public function __construct($data) { $this->data = $data; } + /** + * @param $name + * @param null $default + * @return mixed + */ public function get($name, $default = null) { return $this->dotGet($this->transformKey($name), $default); } + /** + * @return mixed + */ public function data() { return $this->data; } + /** + * @param $dotKey + * @param $default + * @return mixed + */ protected function dotGet($dotKey, $default) { $keyParts = explode('.', $dotKey); @@ -28,6 +49,12 @@ protected function dotGet($dotKey, $default) return $this->dataGet($this->data, $keyParts, $default); } + /** + * @param $target + * @param $keyParts + * @param $default + * @return mixed + */ protected function dataGet($target, $keyParts, $default) { if (count($keyParts) == 0) { @@ -45,6 +72,12 @@ protected function dataGet($target, $keyParts, $default) return $default; } + /** + * @param $target + * @param $keyParts + * @param $default + * @return mixed + */ protected function arrayGet($target, $keyParts, $default) { $key = array_shift($keyParts); @@ -56,6 +89,12 @@ protected function arrayGet($target, $keyParts, $default) return $this->dataGet($target[$key], $keyParts, $default); } + /** + * @param $target + * @param $keyParts + * @param $default + * @return mixed + */ protected function objectGet($target, $keyParts, $default) { $key = array_shift($keyParts); @@ -67,6 +106,10 @@ protected function objectGet($target, $keyParts, $default) return $this->dataGet($target->{$key}, $keyParts, $default); } + /** + * @param $key + * @return mixed + */ protected function transformKey($key) { return str_replace(['[]', '[', ']'], ['', '.', ''], $key); diff --git a/src/AdamWathan/Form/Elements/Button.php b/src/AdamWathan/Form/Elements/Button.php index 78fdfac..ade7db9 100644 --- a/src/AdamWathan/Form/Elements/Button.php +++ b/src/AdamWathan/Form/Elements/Button.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class Button + * @package AdamWathan\Form\Elements + */ class Button extends FormControl { protected $attributes = [ @@ -10,18 +14,29 @@ class Button extends FormControl protected $value; - public function __construct($value, $name = null) + /** + * Button constructor. + * @param string $value + * @param null $name + */ + public function __construct($value, $name = null) { parent::__construct($name); $this->value($value); } + /** + * @return string + */ public function render() { return sprintf('%s', $this->renderAttributes(), $this->value); } + /** + * @param $value + */ public function value($value) { $this->value = $value; diff --git a/src/AdamWathan/Form/Elements/Checkbox.php b/src/AdamWathan/Form/Elements/Checkbox.php index 900ef4f..9763506 100644 --- a/src/AdamWathan/Form/Elements/Checkbox.php +++ b/src/AdamWathan/Form/Elements/Checkbox.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class Checkbox + * @package AdamWathan\Form\Elements + */ class Checkbox extends Input { protected $attributes = [ @@ -12,6 +16,11 @@ class Checkbox extends Input protected $oldValue; + /** + * Checkbox constructor. + * @param $name + * @param int $value + */ public function __construct($name, $value = 1) { parent::__construct($name); @@ -19,6 +28,9 @@ public function __construct($name, $value = 1) $this->setValue($value); } + /** + * @param $oldValue + */ public function setOldValue($oldValue) { $this->oldValue = $oldValue; @@ -29,6 +41,9 @@ public function unsetOldValue() $this->oldValue = null; } + /** + * @return $this + */ public function defaultToChecked() { if (! isset($this->checked) && is_null($this->oldValue)) { @@ -38,6 +53,9 @@ public function defaultToChecked() return $this; } + /** + * @return $this + */ public function defaultToUnchecked() { if (! isset($this->checked) && is_null($this->oldValue)) { @@ -47,6 +65,10 @@ public function defaultToUnchecked() return $this; } + /** + * @param $state + * @return $this + */ public function defaultCheckedState($state) { $state ? $this->defaultToChecked() : $this->defaultToUnchecked(); @@ -54,6 +76,9 @@ public function defaultCheckedState($state) return $this; } + /** + * @return $this + */ public function check() { $this->unsetOldValue(); @@ -62,6 +87,9 @@ public function check() return $this; } + /** + * @return $this + */ public function uncheck() { $this->unsetOldValue(); @@ -70,6 +98,9 @@ public function uncheck() return $this; } + /** + * @param bool $checked + */ protected function setChecked($checked = true) { $this->checked = $checked; @@ -80,6 +111,9 @@ protected function setChecked($checked = true) } } + /** + * @return Checkbox + */ protected function checkBinding() { $currentValue = (string) $this->getAttribute('value'); @@ -93,6 +127,9 @@ protected function checkBinding() } } + /** + * @return string + */ public function render() { $this->checkBinding(); diff --git a/src/AdamWathan/Form/Elements/Date.php b/src/AdamWathan/Form/Elements/Date.php index e0b4f4b..7156798 100644 --- a/src/AdamWathan/Form/Elements/Date.php +++ b/src/AdamWathan/Form/Elements/Date.php @@ -2,13 +2,21 @@ namespace AdamWathan\Form\Elements; +/** + * Class Date + * @package AdamWathan\Form\Elements + */ class Date extends Text { protected $attributes = [ 'type' => 'date', ]; - public function value($value) + /** + * @param $value + * @return $this + */ + public function value($value) { if ($value instanceof \DateTime) { $value = $value->format('Y-m-d'); diff --git a/src/AdamWathan/Form/Elements/Element.php b/src/AdamWathan/Form/Elements/Element.php index c593be2..02abae0 100644 --- a/src/AdamWathan/Form/Elements/Element.php +++ b/src/AdamWathan/Form/Elements/Element.php @@ -2,10 +2,18 @@ namespace AdamWathan\Form\Elements; +/** + * Class Element + * @package AdamWathan\Form\Elements + */ abstract class Element { protected $attributes = []; + /** + * @param $attribute + * @param null $value + */ protected function setAttribute($attribute, $value = null) { if (is_null($value)) { @@ -15,16 +23,28 @@ protected function setAttribute($attribute, $value = null) $this->attributes[$attribute] = $value; } + /** + * @param $attribute + */ protected function removeAttribute($attribute) { unset($this->attributes[$attribute]); } + /** + * @param $attribute + * @return mixed + */ public function getAttribute($attribute) { return $this->attributes[$attribute]; } + /** + * @param $attribute + * @param null $value + * @return $this + */ public function data($attribute, $value = null) { if (is_array($attribute)) { @@ -38,6 +58,11 @@ public function data($attribute, $value = null) return $this; } + /** + * @param $attribute + * @param $value + * @return $this + */ public function attribute($attribute, $value) { $this->setAttribute($attribute, $value); @@ -45,6 +70,10 @@ public function attribute($attribute, $value) return $this; } + /** + * @param $attribute + * @return $this + */ public function clear($attribute) { if (! isset($this->attributes[$attribute])) { @@ -56,6 +85,10 @@ public function clear($attribute) return $this; } + /** + * @param $class + * @return $this + */ public function addClass($class) { if (isset($this->attributes['class'])) { @@ -67,6 +100,10 @@ public function addClass($class) return $this; } + /** + * @param $class + * @return $this + */ public function removeClass($class) { if (! isset($this->attributes['class'])) { @@ -84,6 +121,10 @@ public function removeClass($class) return $this; } + /** + * @param $id + * @return $this + */ public function id($id) { $this->setId($id); @@ -91,6 +132,9 @@ public function id($id) return $this; } + /** + * @param $id + */ protected function setId($id) { $this->setAttribute('id', $id); @@ -103,6 +147,9 @@ public function __toString() return $this->render(); } + /** + * @return string + */ protected function renderAttributes() { list($attributes, $values) = $this->splitKeysAndValues($this->attributes); @@ -112,6 +159,10 @@ protected function renderAttributes() }, $attributes, $values)); } + /** + * @param $array + * @return array + */ protected function splitKeysAndValues($array) { // Disgusting crap because people might have passed a collection @@ -126,6 +177,11 @@ protected function splitKeysAndValues($array) return [$keys, $values]; } + /** + * @param $method + * @param $params + * @return $this + */ public function __call($method, $params) { $params = count($params) ? $params : [$method]; diff --git a/src/AdamWathan/Form/Elements/Email.php b/src/AdamWathan/Form/Elements/Email.php index 95a81d7..78ba75d 100644 --- a/src/AdamWathan/Form/Elements/Email.php +++ b/src/AdamWathan/Form/Elements/Email.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class Email + * @package AdamWathan\Form\Elements + */ class Email extends Text { protected $attributes = [ diff --git a/src/AdamWathan/Form/Elements/File.php b/src/AdamWathan/Form/Elements/File.php index 65004bc..144b222 100644 --- a/src/AdamWathan/Form/Elements/File.php +++ b/src/AdamWathan/Form/Elements/File.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class File + * @package AdamWathan\Form\Elements + */ class File extends Input { protected $attributes = [ diff --git a/src/AdamWathan/Form/Elements/FormControl.php b/src/AdamWathan/Form/Elements/FormControl.php index ff233f7..b28f74e 100644 --- a/src/AdamWathan/Form/Elements/FormControl.php +++ b/src/AdamWathan/Form/Elements/FormControl.php @@ -2,18 +2,32 @@ namespace AdamWathan\Form\Elements; +/** + * Class FormControl + * @package AdamWathan\Form\Elements + */ abstract class FormControl extends Element { + /** + * FormControl constructor. + * @param $name + */ public function __construct($name) { $this->setName($name); } + /** + * @param $name + */ protected function setName($name) { $this->setAttribute('name', $name); } + /** + * @return $this + */ public function required() { $this->setAttribute('required', 'required'); @@ -21,6 +35,9 @@ public function required() return $this; } + /** + * @return $this + */ public function optional() { $this->removeAttribute('required'); @@ -28,6 +45,9 @@ public function optional() return $this; } + /** + * @return $this + */ public function disable() { $this->setAttribute('disabled', 'disabled'); @@ -35,6 +55,9 @@ public function disable() return $this; } + /** + * @return $this + */ public function readonly() { $this->setAttribute('readonly', 'readonly'); @@ -42,6 +65,9 @@ public function readonly() return $this; } + /** + * @return $this + */ public function enable() { $this->removeAttribute('disabled'); @@ -50,6 +76,9 @@ public function enable() return $this; } + /** + * @return $this + */ public function autofocus() { $this->setAttribute('autofocus', 'autofocus'); @@ -57,6 +86,9 @@ public function autofocus() return $this; } + /** + * @return $this + */ public function unfocus() { $this->removeAttribute('autofocus'); diff --git a/src/AdamWathan/Form/Elements/FormOpen.php b/src/AdamWathan/Form/Elements/FormOpen.php index 73992d2..767b10f 100644 --- a/src/AdamWathan/Form/Elements/FormOpen.php +++ b/src/AdamWathan/Form/Elements/FormOpen.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class FormOpen + * @package AdamWathan\Form\Elements + */ class FormOpen extends Element { protected $attributes = [ @@ -13,6 +17,9 @@ class FormOpen extends Element protected $hiddenMethod; + /** + * @return string + */ public function render() { $tags = [sprintf('', $this->renderAttributes())]; @@ -28,16 +35,25 @@ public function render() return implode($tags); } + /** + * @return bool + */ protected function hasToken() { return isset($this->token); } + /** + * @return bool + */ protected function hasHiddenMethod() { return isset($this->hiddenMethod); } + /** + * @return $this + */ public function post() { $this->setMethod('POST'); @@ -45,6 +61,9 @@ public function post() return $this; } + /** + * @return $this + */ public function get() { $this->setMethod('GET'); @@ -52,21 +71,34 @@ public function get() return $this; } + /** + * @return FormOpen + */ public function put() { return $this->setHiddenMethod('PUT'); } + /** + * @return FormOpen + */ public function patch() { return $this->setHiddenMethod('PATCH'); } + /** + * @return FormOpen + */ public function delete() { return $this->setHiddenMethod('DELETE'); } + /** + * @param $token + * @return $this + */ public function token($token) { $this->token = new Hidden('_token'); @@ -75,6 +107,10 @@ public function token($token) return $this; } + /** + * @param $method + * @return $this + */ protected function setHiddenMethod($method) { $this->setMethod('POST'); @@ -84,6 +120,10 @@ protected function setHiddenMethod($method) return $this; } + /** + * @param $method + * @return $this + */ public function setMethod($method) { $this->setAttribute('method', $method); @@ -91,6 +131,10 @@ public function setMethod($method) return $this; } + /** + * @param $action + * @return $this + */ public function action($action) { $this->setAttribute('action', $action); @@ -98,6 +142,10 @@ public function action($action) return $this; } + /** + * @param $type + * @return $this + */ public function encodingType($type) { $this->setAttribute('enctype', $type); @@ -105,6 +153,9 @@ public function encodingType($type) return $this; } + /** + * @return FormOpen + */ public function multipart() { return $this->encodingType('multipart/form-data'); diff --git a/src/AdamWathan/Form/Elements/Hidden.php b/src/AdamWathan/Form/Elements/Hidden.php index 6d92428..8210339 100644 --- a/src/AdamWathan/Form/Elements/Hidden.php +++ b/src/AdamWathan/Form/Elements/Hidden.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class Hidden + * @package AdamWathan\Form\Elements + */ class Hidden extends Input { protected $attributes = [ diff --git a/src/AdamWathan/Form/Elements/Input.php b/src/AdamWathan/Form/Elements/Input.php index 17451e8..2cacbdb 100644 --- a/src/AdamWathan/Form/Elements/Input.php +++ b/src/AdamWathan/Form/Elements/Input.php @@ -2,13 +2,24 @@ namespace AdamWathan\Form\Elements; +/** + * Class Input + * @package AdamWathan\Form\Elements + */ abstract class Input extends FormControl { + /** + * @return string + */ public function render() { return sprintf('', $this->renderAttributes()); } + /** + * @param $value + * @return $this + */ public function value($value) { $this->setValue($value); @@ -16,6 +27,10 @@ public function value($value) return $this; } + /** + * @param $value + * @return $this + */ protected function setValue($value) { $this->setAttribute('value', $value); diff --git a/src/AdamWathan/Form/Elements/Label.php b/src/AdamWathan/Form/Elements/Label.php index 8acdb24..3c55b2e 100644 --- a/src/AdamWathan/Form/Elements/Label.php +++ b/src/AdamWathan/Form/Elements/Label.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class Label + * @package AdamWathan\Form\Elements + */ class Label extends Element { protected $element; @@ -10,11 +14,18 @@ class Label extends Element protected $label; + /** + * Label constructor. + * @param $label + */ public function __construct($label) { $this->label = $label; } + /** + * @return string + */ public function render() { $tags = [sprintf('', $this->renderAttributes())]; @@ -34,6 +45,10 @@ public function render() return implode($tags); } + /** + * @param $name + * @return $this + */ public function forId($name) { $this->setAttribute('for', $name); @@ -41,6 +56,10 @@ public function forId($name) return $this; } + /** + * @param Element $element + * @return $this + */ public function before(Element $element) { $this->element = $element; @@ -49,6 +68,10 @@ public function before(Element $element) return $this; } + /** + * @param Element $element + * @return $this + */ public function after(Element $element) { $this->element = $element; @@ -57,6 +80,9 @@ public function after(Element $element) return $this; } + /** + * @return string + */ protected function renderElement() { if (! $this->element) { @@ -66,6 +92,9 @@ protected function renderElement() return $this->element->render(); } + /** + * @return mixed + */ public function getControl() { return $this->element; diff --git a/src/AdamWathan/Form/Elements/Password.php b/src/AdamWathan/Form/Elements/Password.php index a6f00f5..a996492 100644 --- a/src/AdamWathan/Form/Elements/Password.php +++ b/src/AdamWathan/Form/Elements/Password.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class Password + * @package AdamWathan\Form\Elements + */ class Password extends Text { protected $attributes = [ diff --git a/src/AdamWathan/Form/Elements/RadioButton.php b/src/AdamWathan/Form/Elements/RadioButton.php index f587731..5e88b6a 100644 --- a/src/AdamWathan/Form/Elements/RadioButton.php +++ b/src/AdamWathan/Form/Elements/RadioButton.php @@ -2,13 +2,22 @@ namespace AdamWathan\Form\Elements; +/** + * Class RadioButton + * @package AdamWathan\Form\Elements + */ class RadioButton extends Checkbox { protected $attributes = [ 'type' => 'radio', ]; - public function __construct($name, $value = null) + /** + * RadioButton constructor. + * @param $name + * @param null $value + */ + public function __construct($name, $value = null) { parent::__construct($name); diff --git a/src/AdamWathan/Form/Elements/Select.php b/src/AdamWathan/Form/Elements/Select.php index fca2696..3beb2f2 100644 --- a/src/AdamWathan/Form/Elements/Select.php +++ b/src/AdamWathan/Form/Elements/Select.php @@ -2,18 +2,31 @@ namespace AdamWathan\Form\Elements; +/** + * Class Select + * @package AdamWathan\Form\Elements + */ class Select extends FormControl { protected $options; protected $selected; + /** + * Select constructor. + * @param $name + * @param array $options + */ public function __construct($name, $options = []) { $this->setName($name); $this->setOptions($options); } + /** + * @param $option + * @return $this + */ public function select($option) { $this->selected = $option; @@ -21,11 +34,18 @@ public function select($option) return $this; } + /** + * @param $options + */ protected function setOptions($options) { $this->options = $options; } + /** + * @param $options + * @return $this + */ public function options($options) { $this->setOptions($options); @@ -33,6 +53,9 @@ public function options($options) return $this; } + /** + * @return string + */ public function render() { return implode([ @@ -42,6 +65,9 @@ public function render() ]); } + /** + * @return string + */ protected function renderOptions() { list($values, $labels) = $this->splitKeysAndValues($this->options); @@ -56,6 +82,11 @@ protected function renderOptions() return implode($tags); } + /** + * @param $label + * @param $options + * @return string + */ protected function renderOptGroup($label, $options) { list($values, $labels) = $this->splitKeysAndValues($options); @@ -71,6 +102,11 @@ protected function renderOptGroup($label, $options) ]); } + /** + * @param $value + * @param $label + * @return string + */ protected function renderOption($value, $label) { return implode([ @@ -80,11 +116,20 @@ protected function renderOption($value, $label) ]); } + /** + * @param $value + * @return bool + */ protected function isSelected($value) { return in_array($value, (array) $this->selected); } + /** + * @param $value + * @param $label + * @return $this + */ public function addOption($value, $label) { $this->options[$value] = $label; @@ -92,6 +137,10 @@ public function addOption($value, $label) return $this; } + /** + * @param $value + * @return $this + */ public function defaultValue($value) { if (isset($this->selected)) { @@ -103,6 +152,9 @@ public function defaultValue($value) return $this; } + /** + * @return $this + */ public function multiple() { $name = $this->attributes['name']; diff --git a/src/AdamWathan/Form/Elements/Text.php b/src/AdamWathan/Form/Elements/Text.php index b319f56..2e5309e 100644 --- a/src/AdamWathan/Form/Elements/Text.php +++ b/src/AdamWathan/Form/Elements/Text.php @@ -2,12 +2,20 @@ namespace AdamWathan\Form\Elements; +/** + * Class Text + * @package AdamWathan\Form\Elements + */ class Text extends Input { protected $attributes = [ 'type' => 'text', ]; + /** + * @param $placeholder + * @return $this + */ public function placeholder($placeholder) { $this->setAttribute('placeholder', $placeholder); @@ -15,6 +23,10 @@ public function placeholder($placeholder) return $this; } + /** + * @param $value + * @return $this + */ public function defaultValue($value) { if (! $this->hasValue()) { @@ -24,6 +36,9 @@ public function defaultValue($value) return $this; } + /** + * @return bool + */ protected function hasValue() { return isset($this->attributes['value']); diff --git a/src/AdamWathan/Form/Elements/TextArea.php b/src/AdamWathan/Form/Elements/TextArea.php index c3a68e1..8a9b39a 100644 --- a/src/AdamWathan/Form/Elements/TextArea.php +++ b/src/AdamWathan/Form/Elements/TextArea.php @@ -2,6 +2,10 @@ namespace AdamWathan\Form\Elements; +/** + * Class TextArea + * @package AdamWathan\Form\Elements + */ class TextArea extends FormControl { protected $attributes = [ @@ -12,6 +16,9 @@ class TextArea extends FormControl protected $value; + /** + * @return string + */ public function render() { return implode([ @@ -21,6 +28,10 @@ public function render() ]); } + /** + * @param $rows + * @return $this + */ public function rows($rows) { $this->setAttribute('rows', $rows); @@ -28,6 +39,10 @@ public function rows($rows) return $this; } + /** + * @param $cols + * @return $this + */ public function cols($cols) { $this->setAttribute('cols', $cols); @@ -35,6 +50,10 @@ public function cols($cols) return $this; } + /** + * @param $value + * @return $this + */ public function value($value) { $this->value = $value; @@ -42,6 +61,10 @@ public function value($value) return $this; } + /** + * @param $placeholder + * @return $this + */ public function placeholder($placeholder) { $this->setAttribute('placeholder', $placeholder); @@ -49,6 +72,10 @@ public function placeholder($placeholder) return $this; } + /** + * @param $value + * @return $this + */ public function defaultValue($value) { if (! $this->hasValue()) { @@ -58,6 +85,9 @@ public function defaultValue($value) return $this; } + /** + * @return bool + */ protected function hasValue() { return isset($this->value); diff --git a/src/AdamWathan/Form/ErrorStore/ErrorStoreInterface.php b/src/AdamWathan/Form/ErrorStore/ErrorStoreInterface.php index b1e0906..8a13013 100644 --- a/src/AdamWathan/Form/ErrorStore/ErrorStoreInterface.php +++ b/src/AdamWathan/Form/ErrorStore/ErrorStoreInterface.php @@ -2,9 +2,21 @@ namespace AdamWathan\Form\ErrorStore; +/** + * Interface ErrorStoreInterface + * @package AdamWathan\Form\ErrorStore + */ interface ErrorStoreInterface { - public function hasError($key); + /** + * @param $key + * @return mixed + */ + public function hasError($key); - public function getError($key); + /** + * @param $key + * @return mixed + */ + public function getError($key); } diff --git a/src/AdamWathan/Form/ErrorStore/IlluminateErrorStore.php b/src/AdamWathan/Form/ErrorStore/IlluminateErrorStore.php index 00052e2..083e637 100644 --- a/src/AdamWathan/Form/ErrorStore/IlluminateErrorStore.php +++ b/src/AdamWathan/Form/ErrorStore/IlluminateErrorStore.php @@ -4,15 +4,27 @@ use Illuminate\Session\Store as Session; +/** + * Class IlluminateErrorStore + * @package AdamWathan\Form\ErrorStore + */ class IlluminateErrorStore implements ErrorStoreInterface { private $session; + /** + * IlluminateErrorStore constructor. + * @param Session $session + */ public function __construct(Session $session) { $this->session = $session; } + /** + * @param $key + * @return bool + */ public function hasError($key) { if (! $this->hasErrors()) { @@ -24,6 +36,10 @@ public function hasError($key) return $this->getErrors()->has($key); } + /** + * @param $key + * @return null + */ public function getError($key) { if (! $this->hasError($key)) { @@ -35,16 +51,26 @@ public function getError($key) return $this->getErrors()->first($key); } + /** + * @return mixed + */ protected function hasErrors() { return $this->session->has('errors'); } + /** + * @return null + */ protected function getErrors() { return $this->hasErrors() ? $this->session->get('errors') : null; } + /** + * @param $key + * @return mixed + */ protected function transformKey($key) { return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key); diff --git a/src/AdamWathan/Form/Facades/Form.php b/src/AdamWathan/Form/Facades/Form.php index dccaed5..5aae4ad 100644 --- a/src/AdamWathan/Form/Facades/Form.php +++ b/src/AdamWathan/Form/Facades/Form.php @@ -4,9 +4,16 @@ use Illuminate\Support\Facades\Facade; +/** + * Class Form + * @package AdamWathan\Form\Facades + */ class Form extends Facade { - protected static function getFacadeAccessor() + /** + * @return string + */ + protected static function getFacadeAccessor() { return 'adamwathan.form'; } diff --git a/src/AdamWathan/Form/FormBuilder.php b/src/AdamWathan/Form/FormBuilder.php index ab97569..ed96323 100644 --- a/src/AdamWathan/Form/FormBuilder.php +++ b/src/AdamWathan/Form/FormBuilder.php @@ -19,6 +19,10 @@ use AdamWathan\Form\ErrorStore\ErrorStoreInterface; use AdamWathan\Form\OldInput\OldInputInterface; +/** + * Class FormBuilder + * @package AdamWathan\Form + */ class FormBuilder { protected $oldInput; @@ -29,21 +33,33 @@ class FormBuilder protected $boundData; + /** + * @param OldInputInterface $oldInputProvider + */ public function setOldInputProvider(OldInputInterface $oldInputProvider) { $this->oldInput = $oldInputProvider; } + /** + * @param ErrorStoreInterface $errorStore + */ public function setErrorStore(ErrorStoreInterface $errorStore) { $this->errorStore = $errorStore; } + /** + * @param $token + */ public function setToken($token) { $this->csrfToken = $token; } + /** + * @return FormOpen + */ public function open() { $open = new FormOpen; @@ -55,11 +71,17 @@ public function open() return $open; } + /** + * @return bool + */ protected function hasToken() { return isset($this->csrfToken); } + /** + * @return string + */ public function close() { $this->unbindData(); @@ -67,6 +89,10 @@ public function close() return ''; } + /** + * @param $name + * @return Text + */ public function text($name) { $text = new Text($name); @@ -78,6 +104,10 @@ public function text($name) return $text; } + /** + * @param $name + * @return Date + */ public function date($name) { $date = new Date($name); @@ -89,6 +119,10 @@ public function date($name) return $date; } + /** + * @param $name + * @return Email + */ public function email($name) { $email = new Email($name); @@ -100,6 +134,10 @@ public function email($name) return $email; } + /** + * @param $name + * @return Hidden + */ public function hidden($name) { $hidden = new Hidden($name); @@ -111,6 +149,10 @@ public function hidden($name) return $hidden; } + /** + * @param $name + * @return TextArea + */ public function textarea($name) { $textarea = new TextArea($name); @@ -122,11 +164,20 @@ public function textarea($name) return $textarea; } + /** + * @param $name + * @return Password + */ public function password($name) { return new Password($name); } + /** + * @param $name + * @param int $value + * @return Checkbox + */ public function checkbox($name, $value = 1) { $checkbox = new Checkbox($name, $value); @@ -137,6 +188,11 @@ public function checkbox($name, $value = 1) return $checkbox; } + /** + * @param $name + * @param null $value + * @return RadioButton + */ public function radio($name, $value = null) { $radio = new RadioButton($name, $value); @@ -147,11 +203,20 @@ public function radio($name, $value = null) return $radio; } + /** + * @param $value + * @param null $name + * @return Button + */ public function button($value, $name = null) { return new Button($value, $name); } + /** + * @param string $value + * @return Button + */ public function submit($value = 'Submit') { $submit = new Button($value); @@ -160,6 +225,11 @@ public function submit($value = 'Submit') return $submit; } + /** + * @param $name + * @param array $options + * @return Select + */ public function select($name, $options = []) { $select = new Select($name, $options); @@ -170,16 +240,27 @@ public function select($name, $options = []) return $select; } + /** + * @param $label + * @return Label + */ public function label($label) { return new Label($label); } + /** + * @param $name + * @return File + */ public function file($name) { return new File($name); } + /** + * @return Hidden + */ public function token() { $token = $this->hidden('_token'); @@ -191,6 +272,10 @@ public function token() return $token; } + /** + * @param $name + * @return bool + */ public function hasError($name) { if (! isset($this->errorStore)) { @@ -200,6 +285,11 @@ public function hasError($name) return $this->errorStore->hasError($name); } + /** + * @param $name + * @param null $format + * @return mixed|null|string + */ public function getError($name, $format = null) { if (! isset($this->errorStore)) { @@ -219,11 +309,18 @@ public function getError($name, $format = null) return $message; } + /** + * @param $data + */ public function bind($data) { $this->boundData = new BoundData($data); } + /** + * @param $name + * @return null|string + */ public function getValueFor($name) { if ($this->hasOldInput()) { @@ -237,6 +334,9 @@ public function getValueFor($name) return null; } + /** + * @return bool + */ protected function hasOldInput() { if (! isset($this->oldInput)) { @@ -246,21 +346,37 @@ protected function hasOldInput() return $this->oldInput->hasOldInput(); } + /** + * @param $name + * @return string + */ protected function getOldInput($name) { return $this->escape($this->oldInput->getOldInput($name)); } + /** + * @return bool + */ protected function hasBoundData() { return isset($this->boundData); } + /** + * @param $name + * @param $default + * @return string + */ protected function getBoundValue($name, $default) { return $this->escape($this->boundData->get($name, $default)); } + /** + * @param $value + * @return string + */ protected function escape($value) { if (! is_string($value)) { @@ -275,6 +391,10 @@ protected function unbindData() $this->boundData = null; } + /** + * @param $name + * @return Select + */ public function selectMonth($name) { $options = [ diff --git a/src/AdamWathan/Form/FormServiceProvider.php b/src/AdamWathan/Form/FormServiceProvider.php index b11fe7a..7786605 100644 --- a/src/AdamWathan/Form/FormServiceProvider.php +++ b/src/AdamWathan/Form/FormServiceProvider.php @@ -6,6 +6,10 @@ use AdamWathan\Form\OldInput\IlluminateOldInputProvider; use Illuminate\Support\ServiceProvider; +/** + * Class FormServiceProvider + * @package AdamWathan\Form + */ class FormServiceProvider extends ServiceProvider { protected $defer = false; @@ -43,6 +47,9 @@ protected function registerFormBuilder() }); } + /** + * @return array + */ public function provides() { return ['adamwathan.form']; diff --git a/src/AdamWathan/Form/OldInput/IlluminateOldInputProvider.php b/src/AdamWathan/Form/OldInput/IlluminateOldInputProvider.php index 3cb9c60..5afc277 100644 --- a/src/AdamWathan/Form/OldInput/IlluminateOldInputProvider.php +++ b/src/AdamWathan/Form/OldInput/IlluminateOldInputProvider.php @@ -4,25 +4,44 @@ use Illuminate\Session\Store as Session; +/** + * Class IlluminateOldInputProvider + * @package AdamWathan\Form\OldInput + */ class IlluminateOldInputProvider implements OldInputInterface { private $session; + /** + * IlluminateOldInputProvider constructor. + * @param Session $session + */ public function __construct(Session $session) { $this->session = $session; } + /** + * @return bool + */ public function hasOldInput() { return ($this->session->get('_old_input')) ? true : false ; } + /** + * @param $key + * @return mixed + */ public function getOldInput($key) { return $this->session->getOldInput($this->transformKey($key)); } + /** + * @param $key + * @return mixed + */ protected function transformKey($key) { return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key); diff --git a/src/AdamWathan/Form/OldInput/OldInputInterface.php b/src/AdamWathan/Form/OldInput/OldInputInterface.php index f7b1388..101ddf2 100644 --- a/src/AdamWathan/Form/OldInput/OldInputInterface.php +++ b/src/AdamWathan/Form/OldInput/OldInputInterface.php @@ -2,9 +2,17 @@ namespace AdamWathan\Form\OldInput; +/** + * Interface OldInputInterface + * @package AdamWathan\Form\OldInput + */ interface OldInputInterface { public function hasOldInput(); - public function getOldInput($key); + /** + * @param $key + * @return mixed + */ + public function getOldInput($key); }