本文整理汇总了PHP中sfToolkit::isArrayValuesEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP sfToolkit::isArrayValuesEmpty方法的具体用法?PHP sfToolkit::isArrayValuesEmpty怎么用?PHP sfToolkit::isArrayValuesEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfToolkit
的用法示例。
在下文中一共展示了sfToolkit::isArrayValuesEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validates a file or parameter.
*
* @param string A file or parameter name
* @param array Data associated with the file or parameter
* @param string A parent name
*
* @return bool true, if validation completes successfully, otherwise false
*/
protected function validate(&$name, &$data, $parent)
{
// get defaults
$error = null;
$errorName = null;
$force = null !== $data['group'] ? $data['group']['_force'] : false;
$retval = true;
$value = null;
// get our parameter value
if ($parent == null) {
// normal file/parameter
$errorName = $name;
if ($data['is_file']) {
// file
$value = $this->request->getFile($name);
} else {
// parameter
$value = $this->request->getParameterHolder()->get($name);
}
} else {
// we have a parent
$errorName = $parent . '{' . $name . '}';
if ($data['is_file']) {
// file
$parent = $this->request->getFile($parent . '[' . $name . ']');
if ($parent != null) {
$value = $parent;
}
} else {
// parameter
$parent = $this->request->getParameterHolder()->get($parent);
if ($parent != null && isset($parent[$name])) {
$value = $parent[$name];
}
}
}
// now for the dirty work
if ($data['is_file'] && !$value['name'] || !$data['is_file'] && (is_array($value) ? sfToolkit::isArrayValuesEmpty($value) : $value === null || strlen($value) == 0)) {
if ($data['required'] || $force) {
// it's empty!
$error = $data['required_msg'];
$retval = false;
} else {
// we don't have to validate it
$retval = true;
}
} else {
// time for the fun
$error = null;
// get group force status
if ($data['group'] != null) {
// we set this because we do have a value for a parameter in this group
$data['group']['_force'] = true;
}
if (count($data['validators']) > 0) {
// loop through our validators
foreach ($data['validators'] as $validator) {
if (!$validator->execute($value, $error)) {
$retval = false;
break;
}
}
}
}
if (!$retval) {
// set validation status
$data['validation_status'] = false;
// set the request error
$this->request->setError($errorName, $error);
}
return $retval;
}
示例2: validate
protected function validate(&$name, &$data, $parent)
{
$error = null;
$errorName = null;
$force = null !== $data['group'] ? $data['group']['_force'] : false;
$retval = true;
$value = null;
if ($parent == null) {
$errorName = $name;
if ($data['is_file']) {
$value = $this->request->getFile($name);
} else {
$value = $this->request->getParameterHolder()->get($name);
}
} else {
$errorName = $parent . '{' . $name . '}';
if ($data['is_file']) {
$parent = $this->request->getFile($parent . '[' . $name . ']');
if ($parent != null) {
$value = $parent;
}
} else {
$parent = $this->request->getParameterHolder()->get($parent);
if ($parent != null && isset($parent[$name])) {
$value = $parent[$name];
}
}
}
if ($data['is_file'] && !$value['name'] || !$data['is_file'] && (is_array($value) ? sfToolkit::isArrayValuesEmpty($value) : $value === null || strlen($value) == 0)) {
if ($data['required'] || $force) {
$error = $data['required_msg'];
$retval = false;
} else {
$retval = true;
}
} else {
$error = null;
if ($data['group'] != null) {
$data['group']['_force'] = true;
}
if (count($data['validators']) > 0) {
foreach ($data['validators'] as $validator) {
if (!$validator->execute($value, $error)) {
$retval = false;
break;
}
}
}
}
if (!$retval) {
$data['validation_status'] = false;
$this->request->setError($errorName, $error);
}
return $retval;
}