PHPDoc, some trailing PHP tags removed
This commit is contained in:
@ -13,21 +13,31 @@ abstract class Form
|
||||
{
|
||||
|
||||
const SUCCESS = 'success';
|
||||
const ERROR = 'error';
|
||||
|
||||
|
||||
const ERROR = 'error';
|
||||
|
||||
/**
|
||||
* @var FormField[]
|
||||
*/
|
||||
protected $fields = array();
|
||||
protected $messages = array(self::SUCCESS => 'Form data valid',
|
||||
self::ERROR => 'Form data invalid');
|
||||
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $messages = array(
|
||||
self::SUCCESS => 'Form data valid',
|
||||
self::ERROR => 'Form data invalid');
|
||||
|
||||
protected $valid = true;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param bool|string $message
|
||||
* @return FormField
|
||||
*/
|
||||
protected function addField($name, $message = false)
|
||||
@ -35,13 +45,13 @@ abstract class Form
|
||||
$this->fields[$name] = new FormField($message);
|
||||
return $this->fields[$name];
|
||||
}
|
||||
|
||||
|
||||
public function isValid($data)
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
throw new InitializationException(__CLASS__ . '::' . __METHOD__ . ' expects an array');
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->fields as $field_name => $field) {
|
||||
if (isset($data[$field_name])) {
|
||||
$this->valid &= $field->isValid($data[$field_name], $data);
|
||||
@ -54,7 +64,7 @@ abstract class Form
|
||||
}
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
|
||||
public function getMessages()
|
||||
{
|
||||
$messages = array();
|
||||
@ -65,7 +75,7 @@ abstract class Form
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
||||
public function getValue($key)
|
||||
{
|
||||
if (isset($this->fields[$key])) {
|
||||
@ -73,7 +83,10 @@ abstract class Form
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
$values = array();
|
||||
@ -84,7 +97,10 @@ abstract class Form
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSourceValues()
|
||||
{
|
||||
$values = array();
|
||||
@ -93,35 +109,49 @@ abstract class Form
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessageType()
|
||||
{
|
||||
return ($this->valid) ? self::SUCCESS : self::ERROR;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->messages[$this->getMessageType()];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return Form
|
||||
*/
|
||||
public function setSuccessMessage($message)
|
||||
{
|
||||
$this->messages[self::SUCCESS] = (string) $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return Form
|
||||
*/
|
||||
public function setErrorMessage($message)
|
||||
{
|
||||
$this->messages[self::ERROR] = (string) $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
protected function fillHelperData()
|
||||
{
|
||||
$data['messages'] = $this->getMessages();
|
||||
$data['values'] = $this->getSourceValues();
|
||||
Session::set(get_class($this), $data);
|
||||
}
|
||||
|
||||
|
||||
abstract protected function init();
|
||||
}
|
Reference in New Issue
Block a user