Skip to content

Commit

Permalink
Abstract method
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen committed Aug 3, 2014
1 parent 91445d3 commit e5e898e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/Former/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ public static function hasInstanceOpened()
* Change the form's action
*
* @param string $action The new action
*
* @return $this
*/
public function action($action)
{
Expand All @@ -197,6 +199,8 @@ public function action($action)
* Change the form's method
*
* @param string $method The method to use
*
* @return $this
*/
public function method($method)
{
Expand All @@ -209,6 +213,8 @@ public function method($method)
* Whether the form should be secure
*
* @param boolean $secure Secure or not
*
* @return $this
*/
public function secure($secure = true)
{
Expand All @@ -227,15 +233,7 @@ public function secure($secure = true)
*/
public function route($name, $params = array())
{
// Set the form action
$this->action = $this->url->route($name, $params);

// Set the proper method
if ($method = $this->findRouteMethod($name)) {
$this->method($method);
}

return $this;
return $this->setRouteOrAction($name, $params, 'route');
}

/**
Expand All @@ -248,14 +246,7 @@ public function route($name, $params = array())
*/
public function controller($name, $params = array())
{
$this->action = $this->url->action($name, $params);

// Set the proper method
if ($method = $this->findRouteMethod($name)) {
$this->method($method);
}

return $this;
return $this->setRouteOrAction($name, $params, 'action');
}

/**
Expand Down Expand Up @@ -300,6 +291,8 @@ public function rules()
* Populate a form with specific values
*
* @param array|object $values
*
* @return $this
*/
public function populate($values)
{
Expand Down Expand Up @@ -358,6 +351,26 @@ protected function findRouteMethod($name)
return $method;
}

/**
* @param $name
* @param $params
* @param $type
*
* @return $this
*/
protected function setRouteOrAction($name, $params, $type)
{
// Set the form action
$this->action = $this->url->$type($name, $params);

// Set the proper method
if ($method = $this->findRouteMethod($name)) {
$this->method($method);
}

return $this;
}

/**
* Apply various parameters according to form type
*
Expand Down
2 changes: 2 additions & 0 deletions src/Former/Traits/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public function createIcon($iconType, $attributes = array(), $iconSettings = arr
*
* @param Field $field
* @param array $classes
*
* @return \Former\Traits\Field
*/
protected function addClassesToField($field, $classes)
{
Expand Down

0 comments on commit e5e898e

Please sign in to comment.