Skip to content

Commit

Permalink
Merge pull request #51 from jedi58/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jedi58 committed May 7, 2016
2 parents ca66c5e + f6bd5c7 commit 2c2bf8f
Show file tree
Hide file tree
Showing 15 changed files with 385 additions and 373 deletions.
192 changes: 96 additions & 96 deletions src/Inachis/Common/Form/AbstractFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,101 +10,101 @@
*/
abstract class AbstractFormType
{
/**
* @var string The id of the element
*/
protected $id;
/**
* @var string The name of the element
*/
protected $name;
/**
* @var string[] The array of classes to apply to the object
*/
protected $cssClasses = array();
/**
* @var string[] Array of attributes for the element; e.g. 'item' => 'test'
* would be output as `data-item="test"` by the view
*/
protected $dataAttributes = array();
/**
* @var string The id of the element
*/
protected $id;
/**
* @var string The name of the element
*/
protected $name;
/**
* @var string[] The array of classes to apply to the object
*/
protected $cssClasses = array();
/**
* @var string[] Array of attributes for the element; e.g. 'item' => 'test'
* would be output as `data-item="test"` by the view
*/
protected $dataAttributes = array();
/**
* Returns the type of the current element
* @return string The type of the current element
*/
abstract public function getType();
/**
* Sets the ID for the current form element
* @var string $value The new ID for the form
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
*/
public function setId($value)
{
if (!empty($value) && !preg_match('/^[a-zA-Z0-9\-\_]+$/', $value)) {
throw new FormBuilderConfigurationException(sprintf('Invalid id attribute \'%s\'.', $value));
}
$this->id = $value;
abstract public function getType();
/**
* Sets the ID for the current form element
* @var string $value The new ID for the form
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
*/
public function setId($value)
{
if (!empty($value) && !preg_match('/^[a-zA-Z0-9\-\_]+$/', $value)) {
throw new FormBuilderConfigurationException(sprintf('Invalid id attribute \'%s\'.', $value));
}
$this->id = $value;
return $this;
}
/**
* Returns the ID of the current form element
* @return string The ID of the form element
*/
public function getId()
{
return $this->id;
}
/**
* Sets the name for the current form element
* @var string $value The new name for the form
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
*/
public function setName($value)
{
if (!$this->isValidName($value)) {
throw new FormBuilderConfigurationException(sprintf('Invalid name attribute \'%s\'.', $value));
}
if (in_array($this->getType(), array('checkbox', 'radio')) && !mb_strpos($value, '[]')) {
$value .= '[]';
}
$this->name = $value;
}
/**
* Returns the ID of the current form element
* @return string The ID of the form element
*/
public function getId()
{
return $this->id;
}
/**
* Sets the name for the current form element
* @var string $value The new name for the form
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
*/
public function setName($value)
{
if (!$this->isValidName($value)) {
throw new FormBuilderConfigurationException(sprintf('Invalid name attribute \'%s\'.', $value));
}
if (in_array($this->getType(), array('checkbox', 'radio')) && !mb_strpos($value, '[]')) {
$value .= '[]';
}
$this->name = $value;
return $this;
}
/**
* Returns the name of the current form element
* @return string The name of the form element
*/
public function getName()
{
return $this->name;
}
}
/**
* Returns the name of the current form element
* @return string The name of the form element
*/
public function getName()
{
return $this->name;
}
/**
* Sets the array of CSS classes to apply to the element
* @var string[] $value The CSS to apply to the element
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
* Sets the array of CSS classes to apply to the element
* @var string[] $value The CSS to apply to the element
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
*/
public function setCssClasses($value)
{
if (!is_array($value)) {
throw new FormBuilderConfigurationException(sprintf('Array required, %s provided', gettype($value)));
}
$this->cssClasses = $value;
return $this;
if (!is_array($value)) {
throw new FormBuilderConfigurationException(sprintf('Array required, %s provided', gettype($value)));
}
$this->cssClasses = $value;
return $this;
}
public function setCssClassesFromString($value)
{
$this->cssClasses = explode(' ', $value);
return $this;
$this->cssClasses = explode(' ', $value);
return $this;
}
/**
* Returns the array of CSS classes for the form element
* @return string[] The array of CSS classes for the element
*/
public function getCssClasses()
{
return $this->cssClasses;
return $this->cssClasses;
}
/**
* Returns the array of CSS classes as a string so it can be used
Expand All @@ -113,37 +113,37 @@ public function getCssClasses()
*/
public function getCssClassesAsString()
{
return implode(' ', $this->cssClasses);
return implode(' ', $this->cssClasses);
}
/**
* Adds a CSS classname to the form element
* @var string $value The CSS class to add
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
* Adds a CSS classname to the form element
* @var string $value The CSS class to add
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
*/
public function addCssClass($value)
{
if (!$this->isValidName($value)) {
throw new FormBuilderConfigurationException(sprintf('Class name \'%s\' is invalid', $value));
}
$this->cssClasses[] = $value;
return $this;
if (!$this->isValidName($value)) {
throw new FormBuilderConfigurationException(sprintf('Class name \'%s\' is invalid', $value));
}
$this->cssClasses[] = $value;
return $this;
}
/**
* Removes a CSS classname to the form element
* @var string $value The CSS class to remove
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
* Removes a CSS classname to the form element
* @var string $value The CSS class to remove
* @return AbstractFormType A reference to itself
* @throws FormBuilderConfigurationException
*/
public function removeCssClass($value)
{
if (!isset($this->cssClasses[$value])) {
throw new FormBuilderConfigurationException(
sprintf('Class \'%s\' does not exist - could not be removed', $value)
);
}
unset($this->cssClasses[$value]);
return $this;
if (!isset($this->cssClasses[$value])) {
throw new FormBuilderConfigurationException(
sprintf('Class \'%s\' does not exist - could not be removed', $value)
);
}
unset($this->cssClasses[$value]);
return $this;
}
/**
* Validates the name for the form to confirm it's valid in HTML
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/AbstractSelectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Inachis\Component\Common\Form\FormComponent;
use Inachis\Component\Common\Exception\FormBuilderConfigurationException;

/**
* Object for handling select fields
*/
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/ButtonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Inachis\Component\Common\Form\FormComponent;
use Inachis\Component\Common\Exception\FormBuilderConfigurationException;

/**
* Object for handling `type="button|submit"` buttons
*/
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Inachis\Component\Common\Form\FormComponent;
use Inachis\Component\Common\Exception\FormBuilderConfigurationException;

/**
* Object for handling `type="checkbox"` fields
*/
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/FileUploadType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Inachis\Component\Common\Form\FormComponent;
use Inachis\Component\Common\Exception\FormBuilderConfigurationException;

/**
* Object for handling `type="file"` fields
*/
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/HiddenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Inachis\Component\Common\Form\Fields;

use Inachis\Component\Common\Form\FormComponent;

/**
* Object for handling `type="hidden"` buttons
*/
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/NumberType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Inachis\Component\Common\Form\FormComponent;
use Inachis\Component\Common\Exception\FormBuilderConfigurationException;

/**
* Object for handling `type="date|datetime|datetime-local"` fields
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Inachis/Common/Form/Fields/SelectOptionGroupType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Inachis\Component\Common\Form\Fields;

use Inachis\Component\Common\Form\FormComponent;

/**
* Object for handling select fields
*/
Expand Down Expand Up @@ -54,6 +55,6 @@ public function getLabel()
*/
public function getLabelAsId()
{
return preg_replace('/[^a-zA-Z0-9\-\_]/','', lcfirst(ucwords(strtolower($this->label))));
return preg_replace('/[^a-zA-Z0-9\-\_]/', '', lcfirst(ucwords(strtolower($this->label))));
}
}
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/SelectOptionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Inachis\Component\Common\Form\Fields;

use Inachis\Component\Common\Form\FormComponent;

/**
* Object for handling select fields
*/
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/SelectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Inachis\Component\Common\Form\Fields;

use Inachis\Component\Common\Form\FormComponent;

/**
* Object for handling select fields
*/
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/TextAreaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Inachis\Component\Common\Form\FormComponent;
use Inachis\Component\Common\Exception\FormBuilderConfigurationException;

/**
* Object for handling textarea fields
*/
Expand Down
1 change: 1 addition & 0 deletions src/Inachis/Common/Form/Fields/TextType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Inachis\Component\Common\Form\FormComponent;
use Inachis\Component\Common\Exception\FormBuilderConfigurationException;

/**
* Object for handling `type="text"` fields
*/
Expand Down
Loading

0 comments on commit 2c2bf8f

Please sign in to comment.