Permalink
Browse files

BackwardsCompatibilityBreak - removed fValidation::setEmailFields(), …

…fValidation::setEmailHeaderFields(), fValidation::setRequiredFields() - fixed ticket #50
  • Loading branch information...
wbond committed Aug 26, 2008
1 parent a4ef0d5 commit b942184ff768c078154eb28abdda2758d6adc64a
Showing with 52 additions and 109 deletions.
  1. +52 −109 classes/request/fValidation.php
@@ -47,7 +47,18 @@ class fValidation
public function addEmailFields()
{
$args = func_get_args();
$this->setEmailFields(array_merge($this->email_fields, $args));
foreach ($args as $arg) {
if (!fCore::stringlike($arg)) {
fCore::toss(
'fProgrammerException',
fGrammar::compose(
'The field specified, %s, does not appear to be a valid field name',
fCore::dump($arg)
)
);
}
}
$this->email_fields = array_merge($this->email_fields, $args);
}
@@ -63,7 +74,18 @@ public function addEmailFields()
public function addEmailHeaderFields()
{
$args = func_get_args();
$this->setEmailHeaderFields(array_merge($this->email_header_fields, $args));
foreach ($args as $arg) {
if (!fCore::stringlike($arg)) {
fCore::toss(
'fProgrammerException',
fGrammar::compose(
'The field specified, %s, does not appear to be a valid field name',
fCore::dump($arg)
)
);
}
}
$this->email_header_fields = array_merge($this->email_header_fields, $args);
}
@@ -88,8 +110,34 @@ public function addEmailHeaderFields()
*/
public function addRequiredFields()
{
$args = func_get_args();
$this->setRequiredFields(array_merge($this->required_fields, $args));
$args = func_get_args();
$fixed_args = array();
foreach ($args as $arg) {
// This handles normal field validation
if (fCore::stringlike($arg)) {
$fixed_args[] = $arg;
// This allows for 'or' validation
} elseif (is_array($arg) && sizeof($arg) > 1) {
$fixed_args[] = $arg;
// This handles conditional validation
} elseif (is_array($arg) && sizeof($arg) == 1 && fCore::stringlike(key($arg)) && is_array(reset($arg))) {
$fixed_args[key($arg)] = reset($arg);
} else {
fCore::toss(
'fProgrammerException',
fGrammar::compose(
'The field specified, %s, does not appear to be a valid required field definition',
fCore::dump($arg)
)
);
}
}
$this->required_fields = array_merge($this->required_fields, $fixed_args);
}
@@ -185,111 +233,6 @@ private function checkRequiredFields(&$messages)
}
/**
* Sets form fields to be required to be blank or a valid email address
*
* Use {@link fValidation::setRequiredFields()} to not allow blank values.
*
* @param string $field,... Any number of fields to required valid email addresses for
* @return void
*/
public function setEmailFields()
{
$args = func_get_args();
foreach ($args as $arg) {
if (!fCore::stringlike($arg)) {
fCore::toss(
'fProgrammerException',
fGrammar::compose(
'The field specified, %s, does not appear to be a valid field name',
fCore::dump($arg)
)
);
}
}
$this->email_fields = $args;
}
/**
* Sets form fields to be checked for email injection
*
* Every field that is included in email headers should be passed to this
* method.
*
* @param string $field,... Any number of fields to be checked for email injection
* @return void
*/
public function setEmailHeaderFields()
{
$args = func_get_args();
foreach ($args as $arg) {
if (!fCore::stringlike($arg)) {
fCore::toss(
'fProgrammerException',
fGrammar::compose(
'The field specified, %s, does not appear to be a valid field name',
fCore::dump($arg)
)
);
}
}
$this->email_header_fields = $args;
}
/**
* Sets form fields to be required, taking each parameter as a field name
*
* To require one of multiple fields, pass an array of fields as the parameter.
*
* To conditionally require fields, pass an associative array of with the
* key being the field that will trigger the other fields to be required:
* <pre>
* array(
* 'trigger_field' => array(
* 'conditionally_required_field',
* 'second_conditionally_required_field'
* )
* )
* </pre>
*
* @param mixed $field,... Any number of fields to check
* @return void
*/
public function setRequiredFields()
{
$args = func_get_args();
$fixed_args = array();
foreach ($args as $arg) {
// This handles normal field validation
if (fCore::stringlike($arg)) {
$fixed_args[] = $arg;
// This allows for 'or' validation
} elseif (is_array($arg) && sizeof($arg) > 1) {
$fixed_args[] = $arg;
// This handles conditional validation
} elseif (is_array($arg) && sizeof($arg) == 1 && fCore::stringlike(key($arg)) && is_array(reset($arg))) {
$fixed_args[key($arg)] = reset($arg);
} else {
fCore::toss(
'fProgrammerException',
fGrammar::compose(
'The field specified, %s, does not appear to be a valid required field definition',
fCore::dump($arg)
)
);
}
}
$this->required_fields = $fixed_args;
}
/**
* Checks for required fields, email field formatting and email header injection using values previously set
*

0 comments on commit b942184

Please sign in to comment.