本文整理汇总了PHP中CRM_Utils_Rule::validContact方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Rule::validContact方法的具体用法?PHP CRM_Utils_Rule::validContact怎么用?PHP CRM_Utils_Rule::validContact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Rule
的用法示例。
在下文中一共展示了CRM_Utils_Rule::validContact方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: typecheck
/**
* Validate a value against a CustomField type.
*
* @param string $type
* The type of the data.
* @param string $value
* The data to be validated.
*
* @return bool
* True if the value is of the specified type
*/
public static function typecheck($type, $value)
{
switch ($type) {
case 'Memo':
return TRUE;
case 'String':
return CRM_Utils_Rule::string($value);
case 'Int':
return CRM_Utils_Rule::integer($value);
case 'Float':
case 'Money':
return CRM_Utils_Rule::numeric($value);
case 'Date':
if (is_numeric($value)) {
return CRM_Utils_Rule::dateTime($value);
} else {
return CRM_Utils_Rule::date($value);
}
case 'Boolean':
return CRM_Utils_Rule::boolean($value);
case 'ContactReference':
return CRM_Utils_Rule::validContact($value);
case 'StateProvince':
//fix for multi select state, CRM-3437
$valid = FALSE;
$mulValues = explode(',', $value);
foreach ($mulValues as $key => $state) {
$valid = array_key_exists(strtolower(trim($state)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvinceAbbreviation()), CASE_LOWER)) || array_key_exists(strtolower(trim($state)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvince()), CASE_LOWER));
if (!$valid) {
break;
}
}
return $valid;
case 'Country':
//fix multi select country, CRM-3437
$valid = FALSE;
$mulValues = explode(',', $value);
foreach ($mulValues as $key => $country) {
$valid = array_key_exists(strtolower(trim($country)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::countryIsoCode()), CASE_LOWER)) || array_key_exists(strtolower(trim($country)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::country()), CASE_LOWER));
if (!$valid) {
break;
}
}
return $valid;
case 'Link':
return CRM_Utils_Rule::url($value);
}
return FALSE;
}
示例2: validate
/**
* Verify that a variable is of a given type.
*
* @param mixed $data
* The value to validate.
* @param string $type
* The type to validate against.
* @param bool $abort
* If TRUE, the operation will CRM_Core_Error::fatal() on invalid data.
* @name string $name
* The name of the attribute
*
* @return mixed
* The data, escaped if necessary
*/
public static function validate($data, $type, $abort = TRUE, $name = 'One of parameters ')
{
switch ($type) {
case 'Integer':
case 'Int':
if (CRM_Utils_Rule::integer($data)) {
return (int) $data;
}
break;
case 'Positive':
if (CRM_Utils_Rule::positiveInteger($data)) {
return $data;
}
break;
case 'Boolean':
if (CRM_Utils_Rule::boolean($data)) {
return $data;
}
break;
case 'Float':
case 'Money':
if (CRM_Utils_Rule::numeric($data)) {
return $data;
}
break;
case 'Text':
case 'String':
case 'Link':
case 'Memo':
return $data;
case 'Date':
// a null date is valid
if (strlen(trim($data)) == 0) {
return trim($data);
}
if (preg_match('/^\\d{8}$/', $data) && CRM_Utils_Rule::mysqlDate($data)) {
return $data;
}
break;
case 'Timestamp':
// a null timestamp is valid
if (strlen(trim($data)) == 0) {
return trim($data);
}
if ((preg_match('/^\\d{14}$/', $data) || preg_match('/^\\d{8}$/', $data)) && CRM_Utils_Rule::mysqlDate($data)) {
return $data;
}
break;
case 'ContactReference':
// null is valid
if (strlen(trim($data)) == 0) {
return trim($data);
}
if (CRM_Utils_Rule::validContact($data)) {
return $data;
}
break;
default:
CRM_Core_Error::fatal("Cannot recognize {$type} for {$data}");
break;
}
if ($abort) {
$data = htmlentities($data);
CRM_Core_Error::fatal("{$name} (value: {$data}) is not of the type {$type}");
}
return NULL;
}
示例3: escape
/**
* Verify that a variable is of a given type
*
* @param mixed $data The variable
* @param string $type The type
* @param boolean $abort Should we abort if invalid
* @return mixed The data, escaped if necessary
* @access public
* @static
*/
public static function escape($data, $type, $abort = true)
{
require_once 'CRM/Utils/Rule.php';
switch ($type) {
case 'Integer':
case 'Int':
if (CRM_Utils_Rule::integer($data)) {
return $data;
}
break;
case 'Positive':
if (CRM_Utils_Rule::positiveInteger($data)) {
return $data;
}
break;
case 'Boolean':
if (CRM_Utils_Rule::boolean($data)) {
return $data;
}
break;
case 'Float':
case 'Money':
if (CRM_Utils_Rule::numeric($data)) {
return $data;
}
break;
case 'String':
case 'Memo':
return CRM_Core_DAO::escapeString($data);
break;
case 'Date':
case 'Timestamp':
// a null date or timestamp is valid
if (strlen(trim($data)) == 0) {
return trim($data);
}
if ((preg_match('/^\\d{8}$/', $data) || preg_match('/^\\d{14}$/', $data)) && CRM_Utils_Rule::mysqlDate($data)) {
return $data;
}
break;
case 'ContactReference':
if (strlen(trim($data)) == 0) {
return trim($data);
}
if (CRM_Utils_Rule::validContact($data)) {
return $data;
}
break;
default:
CRM_Core_Error::fatal("Cannot recognize {$type} for {$data}");
break;
}
if ($abort) {
CRM_Core_Error::fatal("{$data} is not of the type {$type}");
}
return null;
}