Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

add phpdoc to every method for autocompletion #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions src/AdamWathan/BootForms/BasicFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -31,60 +48,114 @@ 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);

return $this->formGroup($label, $name, $control);
}

/**
* @param $label
* @param $name
* @return GroupWrapper
*/
public function password($label, $name)
{
$control = $this->builder->password($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);

return $this->formGroup($label, $name, $control);
}

/**
* @param $label
* @param $name
* @return GroupWrapper
*/
public function checkbox($label, $name)
{
$control = $this->builder->checkbox($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');
Expand All @@ -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)) {
Expand All @@ -109,38 +186,73 @@ 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);

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);

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);

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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
54 changes: 52 additions & 2 deletions src/AdamWathan/BootForms/BootForm.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,73 @@
<?php namespace AdamWathan\BootForms;

/**
* Class BootForm
* @package AdamWathan\BootForms
* @method \AdamWathan\Form\Elements\Text text($name)
* @method \AdamWathan\Form\Elements\Date date($name)
* @method \AdamWathan\Form\Elements\Email email($name)
* @method \AdamWathan\Form\Elements\Hidden hidden($name)
* @method \AdamWathan\Form\Elements\TextArea textarea($name)
* @method \AdamWathan\Form\Elements\Password password($name)
* @method \AdamWathan\Form\Elements\Checkbox checkbox($name, $value = 1)
* @method \AdamWathan\Form\Elements\RadioButton radio($name, $value = null)
* @method \AdamWathan\Form\Elements\Button button($value, $name = null)
* @method \AdamWathan\Form\Elements\Button submit($value = 'Submit')
* @method \AdamWathan\Form\Elements\Select select($name, $options = [])
* @method \AdamWathan\Form\Elements\Label label($label)
* @method \AdamWathan\Form\Elements\File file($name)
* @method setOldInputProvider(\AdamWathan\Form\OldInput\OldInputInterface $oldInputProvider)
* @method setErrorStore(\AdamWathan\Form\ErrorStore\ErrorStoreInterface $errorStore)
* @method setToken($token)
* @method string close()
* @method string token()
* @method bool hasError($name)
* @method string getError($name, $format = null)
* @method bind($data)
* @method mixed getValueFor($name)
* @method \AdamWathan\Form\Elements\Select selectMonth($name)
*/
class BootForm
{
/**
* @var BasicFormBuilder
*/
protected $builder;
protected $basicFormBuilder;
protected $horizontalFormBuilder;

/**
* @var BasicFormBuilder
*/
protected $basicFormBuilder;

/**
* @var HorizontalFormBuilder
*/
protected $horizontalFormBuilder;

/**
* BootForm constructor.
* @param BasicFormBuilder $basicFormBuilder
* @param HorizontalFormBuilder $horizontalFormBuilder
*/
public function __construct(BasicFormBuilder $basicFormBuilder, HorizontalFormBuilder $horizontalFormBuilder)
{
$this->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);
Expand Down
28 changes: 28 additions & 0 deletions src/AdamWathan/BootForms/Elements/CheckGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -29,6 +46,9 @@ public function render()
return $html;
}

/**
* @return $this
*/
public function inline()
{
$this->inline = true;
Expand All @@ -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);
Expand Down
Loading