X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FType.php;h=ec544d5e2acba4ba3118ab20973268afc4eaacee;hb=8a6d5abdadbd87133744a0d66552f66226beb838;hp=b57ea91540dd41a52eae6b4a5883da15f255967e;hpb=cc58f6c5756ba74b4a914e21bb011332d5d79c80;p=civicrm-core.git diff --git a/CRM/Utils/Type.php b/CRM/Utils/Type.php index b57ea91540..ec544d5e2a 100644 --- a/CRM/Utils/Type.php +++ b/CRM/Utils/Type.php @@ -213,7 +213,7 @@ class CRM_Utils_Type { * @param string $type * The type to verify against. * @param bool $abort - * If TRUE, the operation will CRM_Core_Error::fatal() on invalid data. + * If TRUE, the operation will throw an CRM_Core_Exception on invalid data. * * @return mixed * The data, escaped if necessary. @@ -326,17 +326,16 @@ class CRM_Utils_Type { break; default: - CRM_Core_Error::fatal( + throw new CRM_Core_Exception( $type . " is not a recognised (camel cased) data type." ); - break; } // @todo Use exceptions instead of CRM_Core_Error::fatal(). if ($abort) { $data = htmlentities($data); - CRM_Core_Error::fatal("$data is not of the type $type"); + throw new CRM_Core_Exception("$data is not of the type $type"); } return NULL; } @@ -352,15 +351,13 @@ class CRM_Utils_Type { * If TRUE, the operation will CRM_Core_Error::fatal() on invalid data. * @param string $name * The name of the attribute - * @param bool $isThrowException - * Should an exception be thrown rather than a using a deprecated fatal error. * * @return mixed * The data, escaped if necessary * * @throws \CRM_Core_Exception */ - public static function validate($data, $type, $abort = TRUE, $name = 'One of parameters ', $isThrowException = TRUE) { + public static function validate($data, $type, $abort = TRUE, $name = 'One of parameters ') { $possibleTypes = [ 'Integer', @@ -386,10 +383,7 @@ class CRM_Utils_Type { 'Color', ]; if (!in_array($type, $possibleTypes)) { - if ($isThrowException) { - throw new CRM_Core_Exception(ts('Invalid type, must be one of : ' . implode($possibleTypes))); - } - CRM_Core_Error::fatal(ts('Invalid type, must be one of : ' . implode($possibleTypes))); + throw new CRM_Core_Exception(ts('Invalid type, must be one of : ' . implode($possibleTypes))); } switch ($type) { case 'Integer': @@ -466,10 +460,7 @@ class CRM_Utils_Type { if ($abort) { $data = htmlentities($data); - if ($isThrowException) { - throw new CRM_Core_Exception("$name (value: $data) is not of the type $type"); - } - CRM_Core_Error::fatal("$name (value: $data) is not of the type $type"); + throw new CRM_Core_Exception("$name (value: $data) is not of the type $type"); } return NULL;