From: Kevin Day Date: Sun, 18 Feb 2018 00:12:53 +0000 (-0600) Subject: Update: provide custom error returning static function for NULL returns X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=89e32a78ca17f36807f02be783edd8f18f483dd9;p=koopa Update: provide custom error returning static function for NULL returns NULL does not need any values assigned so provide a static alternative to the by value error return. --- diff --git a/common/base/classes/base_path.php b/common/base/classes/base_path.php index 10545a0..a4d3ab8 100644 --- a/common/base/classes/base_path.php +++ b/common/base/classes/base_path.php @@ -1340,12 +1340,12 @@ class c_base_path extends c_base_rfc_string { protected function pr_sanitize($id, $type, $type_sub = NULL) { if (!is_string($id) && mb_strlen($id) > 0) { $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'id', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_value(NULL, 'c_base_return_null', $error); + return c_base_return_error::s_null($error); } if (!is_int($type)) { $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_value(NULL, 'c_base_return_null', $error); + return c_base_return_error::s_null($error); } if (!is_array($_POST) || !array_key_exists($id, $_POST)) { diff --git a/common/base/classes/base_return.php b/common/base/classes/base_return.php index a71c330..5618920 100644 --- a/common/base/classes/base_return.php +++ b/common/base/classes/base_return.php @@ -1663,6 +1663,37 @@ class c_base_return_error { } /** + * Creates a return NULL with the error value populated. + * + * @param c_base_error|array|null $error + * (optional) a custom error setting. + * Can be an array of c_base_error for returning multiple errors. + * When NULL, no errors are defined. + * + * @return c_base_return_false + * A c_base_return_null object with the error value populated. + */ + public static function s_null($error = NULL) { + $object_return = new c_base_return_null(); + + if (is_null($error)) { + $object_return->set_error(null); + } + elseif (is_array($error)) { + foreach ($error as $delta => $value) { + $object_return->set_error($error, $delta); + } + unset($delta); + unset($value); + } + else { + $object_return->set_error($error); + } + + return $object_return; + } + + /** * Creates a return boolean TRUE with the error value populated. * * This will assign a value to the class.