From: Kevin Day Date: Wed, 22 Feb 2017 04:55:04 +0000 (-0600) Subject: Progress: continuing development, more http header support, implemented error reporting X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=3240def4dfd0652aebe9c3b316b58362cc16e01b;p=koopa Progress: continuing development, more http header support, implemented error reporting I noticed that there are a lot of incomplete functions in the http class. This, in particular, implements cookie support. There is still a lot more incomplete code in the http class. My initial error reporting work is done. Expect major refactoring as I continue developing. After some testing, I have foind the php-xz module to be lacking and defunct. I also noticed that there are multiple relevant repositories to choose from (added both to documentation). Numerous other changes. --- diff --git a/common/base/classes/base_access.php b/common/base/classes/base_access.php index 93e3f17..162d190 100644 --- a/common/base/classes/base_access.php +++ b/common/base/classes/base_access.php @@ -105,11 +105,13 @@ class c_base_roles { */ public function set_role($role, $value) { if (!is_int($role)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'role')), i_base_error_messages::INVALID_ARGUMENT); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'role', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($value)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'value')), i_base_error_messages::INVALID_ARGUMENT); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'value', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($role === self::NONE) { @@ -178,7 +180,8 @@ class c_base_roles { */ public function get_role($role) { if (!is_int($role)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'role')), i_base_error_messages::INVALID_ARGUMENT); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'role', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($role === self::NONE) { diff --git a/common/base/classes/base_charset.php b/common/base/classes/base_charset.php index 0e978d1..16d1f75 100644 --- a/common/base/classes/base_charset.php +++ b/common/base/classes/base_charset.php @@ -42,7 +42,8 @@ class c_base_charset { */ public static function s_is_valid($charset) { if (!is_int($charset)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'charset')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'charset', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($charset < self::ASCII || $charset > self::ISO_8859_16) { @@ -64,7 +65,8 @@ class c_base_charset { */ public static function s_to_string($charset) { if (!is_int($charset)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'charset')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'charset', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } switch ($charset) { @@ -110,6 +112,7 @@ class c_base_charset { return c_base_return_string::s_new('ISO-8859-16'); } - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => __CLASS__ . '::' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '::' . __FUNCTION__), i_base_error_messages::FUNCTION_FAILURE)); + return c_base_return_error::s_false($error); } } diff --git a/common/base/classes/base_cookie.php b/common/base/classes/base_cookie.php index 89d7daf..4b08163 100644 --- a/common/base/classes/base_cookie.php +++ b/common/base/classes/base_cookie.php @@ -16,12 +16,16 @@ require_once('common/base/classes/base_return.php'); * This class overrides c_base_return_array() such that some of its return values are in a different form than expected. * This will utilize c_base_return_* as return values. * + * @todo: review this class, for some reason I decided to use c_base_return_array as this class supertype. + * Is that a good idea, because it feels a bit abusive? + * * @see: http://us.php.net/manual/en/features.cookies.php * @see: setcookie() */ class c_base_cookie extends c_base_return_array { const DEFAULT_LIFETIME = 172800; // 48 hours const DEFAULT_PATH = '/'; + const DEFAULT_JSON_ENCODE_DEPTH = 512; const CHECKSUM_ALGORITHM = 'sha256'; private $name; @@ -33,6 +37,7 @@ class c_base_cookie extends c_base_return_array { private $http_only; private $first_only; private $data; + private $json_encode_depth; /** @@ -48,6 +53,7 @@ class c_base_cookie extends c_base_return_array { $this->http_only = FALSE; $this->first_only = TRUE; $this->data = array(); + $this->json_encode_depth = self::DEFAULT_JSON_ENCODE_DEPTH; $this->p_set_lifetime_default(); @@ -67,6 +73,7 @@ class c_base_cookie extends c_base_return_array { unset($this->http_only); unset($this->first_only); unset($this->data); + unset($this->json_encode_depth); parent::__destruct(); } @@ -103,11 +110,13 @@ class c_base_cookie extends c_base_return_array { */ public function set_name($name) { if (!is_string($name) || empty($name)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (mb_strlen($name) == 0 || preg_match('/^(\w|-)+$/iu', $name) != 1) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':format_name' => 'name')), i_base_error_messages::INVALID_FORMAT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':format_name' => 'name', ':expected_format' => '. Alphanumeric and dash characters only', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_FORMAT); + return c_base_return_error::s_false($error); } $this->name = preg_replace('/(^\s+)|(\s+$)/us', '', rawurlencode($name)); @@ -138,7 +147,8 @@ class c_base_cookie extends c_base_return_array { */ public function set_secure($secure) { if (!is_bool($secure)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'secure')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'secure', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->secure = $secure; @@ -184,11 +194,13 @@ class c_base_cookie extends c_base_return_array { $expires = (int) $expires; if ($expires < 0) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'expires')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'expires', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } else { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'expires')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'expires', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } @@ -238,11 +250,13 @@ class c_base_cookie extends c_base_return_array { $max_age = (int) $max_age; if ($max_age < 0) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'max_age')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'max_age', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } else { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'max_age')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'max_age', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } @@ -279,14 +293,16 @@ class c_base_cookie extends c_base_return_array { */ public function set_path($path) { if (!is_string($path) || empty($path)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'path')), i_base_error_messages::INVALID_ARGUMENT)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'path', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // sanitize the path string, only allowing the path portion of the url. $parsed = parse_url($path, PHP_URL_PATH); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'parse_url(path)')), i_base_error_messages::OPERATION_FAILURE)); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'parse_url'), i_base_error_messages::OPERATION_FAILURE)); + return c_base_return_error::s_false($error); } $this->path = preg_replace('/(^\s+)|(\s+$)/us', '', $parsed); @@ -321,14 +337,16 @@ class c_base_cookie extends c_base_return_array { */ public function set_domain($domain) { if (!is_string($domain) || empty($domain)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'domain')), i_base_error_messages::INVALID_ARGUMENT); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'domain', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // sanitize the domain string, only allowing the host portion of the url. $parsed = parse_url('stub://' . $domain, PHP_URL_HOST); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'parse_url(stub://domain, PHP_URL_HOST)')), i_base_error_messages::OPERATION_FAILURE); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'parse_url', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->domain = preg_replace('/(^\s+)|(\s+$)/us', '', $parsed); @@ -361,7 +379,8 @@ class c_base_cookie extends c_base_return_array { */ public function set_http_only($http_only) { if (!is_bool($http_only)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'http_only')), i_base_error_messages::INVALID_ARGUMENT); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'http_only', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->http_only = $http_only; @@ -397,7 +416,8 @@ class c_base_cookie extends c_base_return_array { */ public function set_first_only($first_only) { if (!is_bool($first_only)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'first_only')), i_base_error_messages::INVALID_ARGUMENT); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'first_only', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->first_only = $first_only; @@ -429,13 +449,15 @@ class c_base_cookie extends c_base_return_array { * @param array $data * Any value so long as it is an array. * NULL is not allowed. + * FALSE with the error bit set is returned on error. * * @return c_base_return_status * TRUE on success, FALSE otherwise. */ public function set_data($data) { if (!is_array($data)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'data')), i_base_error_messages::INVALID_ARGUMENT); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'data', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->data = $data; @@ -445,9 +467,10 @@ class c_base_cookie extends c_base_return_array { /** * Return the data. * - * @return c_base_return_array $data + * @return c_base_return_array * The value array stored within this class. * NULL may be returned if there is no defined valid array. + * FALSE with the error bit set is returned on error. */ public function get_data() { if (!is_null($this->data) && !is_array($this->data)) { @@ -458,95 +481,124 @@ class c_base_cookie extends c_base_return_array { } /** - * Save the cookie to the HTTP headers for sending to the client. - * - * This function sends an HTTP header and therefore should only be used when ready to send headers. - * - * Both name and value are required to be set before calling this function. - * - * The functions setcookie() and setrawcookie() do not provide advanced customization. - * Instead of using those functions, use header() to directly generate the cookie. + * Generate and return a cookie string prepared for HTTP header usage. * * @param bool $checksum - * When set to TRUE, the array will be converted to a json string and have a checksum created for it. + * (optional) When set to TRUE, the array will be converted to a json string and have a checksum created for it. * This checksum value will then be placed inside the array and a final json string will be submitted. * - * Warning: any top-level key in the array with the name of 'checksum' will be lost when using this. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * - * @see: self::validate() - * @see: setcookie() - * @see: setrawcookie() - * @see: header() + * @return c_base_return_string + * The value array stored within this class. + * NULL may be returned if there is no defined valid array. + * FALSE with the error bit set is returned on error. */ - public function do_push($checksum = TRUE) { - if (is_null($this->name)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name')), i_base_error_messages::INVALID_ARGUMENT); + public function get_cookie($checksum = TRUE) { + if (!is_bool($checksum)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'checksum', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($this->data)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'data')), i_base_error_messages::INVALID_ARGUMENT); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->data', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } - if ($checksum) { - unset($this->data['checksum']); - $this->data['checksum'] = $this->p_build_checksum(); - - if (is_null($this->data['checksum'])) { - unset($this->data['checksum']); - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_build_checksum()')), i_base_error_messages::OPERATION_FAILURE); - } + $cookie = $this->p_build_cookie($checksum); + if ($cookie instanceof c_base_return_false) { + return c_base_return_error::s_false($cookie->get_error()); } - // @todo: consider adding support for assigning the json depth setting. - $json = json_encode($this->data); - if ($json === FALSE) { - unset($json); - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'json_encode(this->data)')), i_base_error_messages::OPERATION_FAILURE); - } + return $cookie; + } - $data = rawurlencode(preg_replace('/(^\s+)|(\s+$)/us', '', $json)); - unset($json); + /** + * Assigns the default json encode depth to be used. + * + * Sets the maximum json encode depth used when processing cookie data via json_encode(). + * + * @param int $json_encode_depth + * The json encode max depth. + * + * @return c_base_return_status + * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. + * + * @see: json_encode() + */ + public function set_json_encode_depth($json_encode_depth) { + if (!is_int($json_encode_depth) || $json_encode_depth < 1) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'json_encode_depth', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - //$result = setrawcookie($this->name, $data, $this->max_age, $this->path, $this->domain, $this->secure, $this->http_only); - $cookie = 'Set-Cookie: ' . rawurlencode($this->name) . '=' . $data . ';'; + $this->json_encode_depth = $json_encode_depth; + return new c_base_return_true(); + } - if (!is_null($this->domain)) { - $cookie .= ' domain=' . $this->domain . ';'; - } + /** + * Returns the stored cookie json_encode_depth. + * + * @return c_base_return_int + * The cookie json_encode_depth string or NULL if undefined. + * FALSE with the error bit set is returned on error. + */ + public function get_json_encode_depth() { + return c_base_return_int::s_new($this->json_encode_depth); + } - if (!is_null($this->path)) { - $cookie .= ' path=' . $this->path . ';'; + /** + * Save the cookie to the HTTP headers for sending to the client. + * + * This function sends an HTTP header and therefore should only be used when ready to send headers. + * + * @param bool $checksum + * (optional) When set to TRUE, the array will be converted to a json string and have a checksum created for it. + * This checksum value will then be placed inside the array and a final json string will be submitted. + * + * Warning: any top-level key in the array with the name of 'checksum' will be lost when using this. + * @param bool $force + * (optional) If TRUE, will send cookie header even if header_sent() returns TRUE. + * If FALSE, cookie headers are not sent when headers_sent() returns TRUE. + * + * @return c_base_return_status + * TRUE on success, FALSE otherwise. + * FALSE with error bit is returned on error. + * FALSE without error bit set is returned when the php headers have already been sent according to headers_sent(). + * + * @see: header() + * @see: headers_sent(). + */ + public function do_push($checksum = TRUE, $force = FALSE) { + if (!is_bool($checksum)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'checksum', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_null($this->max_age)) { - $cookie .= ' max-age=' . $this->max_age . ';'; - - // provide an expires for compatibility purposes if one is not specified. - if (is_null($this->expires)) { - $cookie .= ' expires=' . gmdate('D, d-M-Y H:i:s T', strtotime('+' . $this->max_age . ' seconds')) . ';'; - } + if (!is_bool($force)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'force', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_null($this->expires)) { - $cookie .= ' expires=' . gmdate('D, d-M-Y H:i:s T', $this->expires) . ';'; + if (is_null($this->name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } - if ($this->secure) { - $cookie .= ' secure;'; + if (is_null($this->data)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->data', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } - if ($this->http_only) { - $cookie .= ' httponly;'; + $cookie = $this->p_build_cookie($checksum); + if ($cookie instanceof c_base_return_false) { + return c_base_return_error::s_false($cookie->get_error()); } - if ($this->first_only) { - $cookie .= ' first-party;'; + if (headers_sent() && !$force) { + return new c_base_return_false(); } - header($cookie, FALSE); + header($cookie->get_value_exact(), FALSE); unset($cookie); unset($data); @@ -554,34 +606,6 @@ class c_base_cookie extends c_base_return_array { return new c_base_return_true(); } -/** - * Deletes the cookie by setting both the expires and max-age to -1. - * - * This does not need to be called when updating the cookie. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * - * @see: self::push() - */ - public function delete() { - $original_max_age = $this->max_age; - $original_expires = $this->expires; - - $this->max_age = -1; - $this->expires = -1; - - $result = $this->push(FALSE); - - $this->max_age = $original_max_age; - $this->expires = $original_expires; - - unset($original_max_age); - unset($original_expires); - - return $result; - } - /** * Retrieve the cookie from the HTTP headers sent by the client. * @@ -603,7 +627,8 @@ class c_base_cookie extends c_base_return_array { unset($json); if ($data === FALSE) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'json_decode(json, TRUE)')), i_base_error_messages::OPERATION_FAILURE); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'json_decode', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->data = $data; @@ -613,19 +638,6 @@ class c_base_cookie extends c_base_return_array { } /** - * Assigns a default value for the expiration based on php's session.cookie_lifetime. - */ - private function p_set_lifetime_default() { - $lifetime = ini_get('session.cookie_lifetime'); - if ($lifetime <= 0) { - $lifetime = self::DEFAULT_LIFETIME; - } - - $this->max_age = $lifetime; - unset($lifetime); - } - - /** * Validate a checksum key. * * This is only meaningful when called after self::do_pull() is used. @@ -640,7 +652,8 @@ class c_base_cookie extends c_base_return_array { */ public function validate() { if (!is_array($this->data)) { - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->data')), i_base_error_messages::INVALID_VARIABLE); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->data')), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if (!array_key_exists('checksum', $this->data)) { @@ -658,6 +671,34 @@ class c_base_cookie extends c_base_return_array { } /** + * Deletes the cookie by setting both the expires and max-age to -1. + * + * This does not need to be called when updating the cookie. + * + * @return c_base_return_status + * TRUE on success, FALSE otherwise. + * + * @see: self::push() + */ + public function delete() { + $original_max_age = $this->max_age; + $original_expires = $this->expires; + + $this->max_age = -1; + $this->expires = -1; + + $result = $this->push(FALSE); + + $this->max_age = $original_max_age; + $this->expires = $original_expires; + + unset($original_max_age); + unset($original_expires); + + return $result; + } + + /** * Builds a checksum of the data array. * * This does not assign the checksum to the array. @@ -675,7 +716,21 @@ class c_base_cookie extends c_base_return_array { } unset($checksum); - return c_base_return_error::s_false(c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_build_checksum()')), i_base_error_messages::OPERATION_FAILURE); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_build_checksum', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); + } + + /** + * Assigns a default value for the expiration based on php's session.cookie_lifetime. + */ + private function p_set_lifetime_default() { + $lifetime = ini_get('session.cookie_lifetime'); + if ($lifetime <= 0) { + $lifetime = self::DEFAULT_LIFETIME; + } + + $this->max_age = $lifetime; + unset($lifetime); } /** @@ -700,7 +755,7 @@ class c_base_cookie extends c_base_return_array { unset($this->data['checksum']); } - $json = json_encode($this->data); + $json = json_encode($this->data, 0, $this->json_encode_depth); if ($json === FALSE) { if ($has_checksum) { $this->data['checksum'] = $checksum; @@ -709,6 +764,7 @@ class c_base_cookie extends c_base_return_array { unset($has_checksum); unset($checksum); unset($json); + return NULL; } @@ -723,4 +779,91 @@ class c_base_cookie extends c_base_return_array { return $generated; } + + /** + * Build the cookie HTTP headers for sending to the client. + * + * This function sends an HTTP header and therefore should only be used when ready to send headers. + * + * Both name and value are required to be set before calling this function. + * + * The functions setcookie() and setrawcookie() do not provide advanced customization. + * Instead of using those functions, use header() to directly generate the cookie. + * + * @param bool $checksum + * (optional) When set to TRUE, the array will be converted to a json string and have a checksum created for it. + * This checksum value will then be placed inside the array and a final json string will be submitted. + * + * Warning: any top-level key in the array with the name of 'checksum' will be lost when using this. + * + * @return c_base_return_string|c_base_return_status + * A generated cookie string is returned on success. + * FALSE with error bit is returned on error. + * FALSE without error bit set is returned when the php headers have already been sent according to headers_sent(). + * + * @see: self::validate() + * @see: setcookie() + * @see: setrawcookie() + * @see: header() + * @see: headers_sent(). + */ + private function p_build_cookie($checksum = TRUE) { + if ($checksum) { + unset($this->data['checksum']); + $this->data['checksum'] = $this->p_build_checksum(); + + if (is_null($this->data['checksum'])) { + unset($this->data['checksum']); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_build_checksum', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); + } + } + + $json = json_encode($this->data, 0, $this->json_encode_depth); + if ($json === FALSE) { + unset($json); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'json_encode', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); + } + + $data = rawurlencode(preg_replace('/(^\s+)|(\s+$)/us', '', $json)); + unset($json); + + $cookie = 'Set-Cookie: ' . rawurlencode($this->name) . '=' . $data . ';'; + + if (!is_null($this->domain)) { + $cookie .= ' domain=' . $this->domain . ';'; + } + + if (!is_null($this->path)) { + $cookie .= ' path=' . $this->path . ';'; + } + + if (!is_null($this->max_age)) { + $cookie .= ' max-age=' . $this->max_age . ';'; + + // provide an expires for compatibility purposes if one is not specified. + if (is_null($this->expires)) { + $cookie .= ' expires=' . gmdate('D, d-M-Y H:i:s T', strtotime('+' . $this->max_age . ' seconds')) . ';'; + } + } + + if (!is_null($this->expires)) { + $cookie .= ' expires=' . gmdate('D, d-M-Y H:i:s T', $this->expires) . ';'; + } + + if ($this->secure) { + $cookie .= ' secure;'; + } + + if ($this->http_only) { + $cookie .= ' httponly;'; + } + + if ($this->first_only) { + $cookie .= ' first-party;'; + } + + return c_base_return_string::s_new($cookie); + } } diff --git a/common/base/classes/base_database.php b/common/base/classes/base_database.php index 3cd2c6a..327fb4f 100644 --- a/common/base/classes/base_database.php +++ b/common/base/classes/base_database.php @@ -42,7 +42,7 @@ class c_base_connection_string extends c_base_return_string { private $host; private $host_addr; private $port; - private $dbname; + private $database_name; private $user; private $password; private $connect_timeout; @@ -59,7 +59,7 @@ class c_base_connection_string extends c_base_return_string { $this->host = NULL; $this->host_addr = NULL; $this->port = NULL; - $this->dbname = NULL; + $this->database_name = NULL; $this->user = NULL; $this->password = NULL; $this->connect_timeout = NULL; @@ -81,7 +81,7 @@ class c_base_connection_string extends c_base_return_string { unset($this->host); unset($this->host_addr); unset($this->port); - unset($this->dbname); + unset($this->database_name); unset($this->user); unset($this->password); unset($this->connect_timeout); @@ -123,10 +123,12 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_host($host) { if (!is_string($host)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'host', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->host = $host; @@ -138,6 +140,7 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_string * The host information string. + * The error bit set is on error. */ public function get_host() { if (!is_string($this->host)) { @@ -155,10 +158,12 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_host_addr($host_addr) { if (!is_string($host_addr)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'host_addr', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->host_addr = $host_addr; @@ -170,6 +175,7 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_string * The host address information string. + * The error bit set is on error. */ public function get_host_addr() { if (!is_string($this->host_addr)) { @@ -187,17 +193,20 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_port($port) { if (!is_int($port)) { if (is_string($port) && is_numeric($port)) { $port = (int) $port; if ($port < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'port', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } else { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'port', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } @@ -209,7 +218,8 @@ class c_base_connection_string extends c_base_return_string { * Returns the port number. * * @return c_base_return_int - * The port number. + * The port number on success. + * The error bit set is on error. */ public function get_port() { if (!is_int($this->port)) { @@ -222,18 +232,20 @@ class c_base_connection_string extends c_base_return_string { /** * Assign database name. * - * @param string $dbname + * @param string $database_name * The database name string. * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ - public function set_dbname($dbname) { - if (!is_string($dbname)) { - return c_base_return_error::s_false(); + public function set_database_name($database_name) { + if (!is_string($database_name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - $this->dbname = $dbname; + $this->database_name = $database_name; return new c_base_return_true(); } @@ -241,14 +253,15 @@ class c_base_connection_string extends c_base_return_string { * Returns the database name. * * @return c_base_return_string - * The database name string. + * The database name string on success. + * The error bit set is on error. */ - public function get_dbname() { - if (!is_string($this->dbname)) { - $this->dbname = ''; + public function get_database_name() { + if (!is_string($this->database_name)) { + $this->database_name = ''; } - return c_base_return_string::s_new($this->dbname); + return c_base_return_string::s_new($this->database_name); } /** @@ -259,10 +272,12 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_user($user) { if (!is_string($user)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->user = $user; @@ -273,7 +288,8 @@ class c_base_connection_string extends c_base_return_string { * Returns the user name. * * @return c_base_return_string - * The user name string. + * The user name string on success. + * The error bit set is on error. */ public function get_user() { if (!is_string($this->user)) { @@ -291,10 +307,12 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_password($password) { if (!is_null($password) && !is_string($password)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'password', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->password = $password; @@ -304,9 +322,10 @@ class c_base_connection_string extends c_base_return_string { /** * Returns the password. * - * @return c_base_return_string|c_base_return_status + * @return c_base_return_string * The password string. * FALSE is returned if there is no assigned password. + * The error bit set is on error. */ public function get_password() { if (is_null($this->password)) { @@ -328,17 +347,20 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_connect_timeout($connect_timeout) { if (!is_int($connect_timeout)) { if (is_string($connect_timeout) && is_numeric($connect_timeout)) { $connect_timeout = (int) $connect_timeout; if ($connect_timeout < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'connect_timeout', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } else { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'connect_timeout', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } @@ -351,6 +373,7 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_int * The connect timeout number. + * The error bit set is on error. */ public function get_connect_timeout() { if (!is_int($this->connect_timeout)) { @@ -368,10 +391,12 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_options($options) { if (!is_string($options)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->options = $options; @@ -382,7 +407,8 @@ class c_base_connection_string extends c_base_return_string { * Returns the options information. * * @return c_base_return_string - * The options information string. + * The options information string on success. + * The error bit set is on error. */ public function get_options() { if (!is_string($this->options)) { @@ -405,10 +431,12 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_ssl_mode($ssl_mode) { if (!is_string($ssl_mode)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ssl_mode', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->ssl_mode = $ssl_mode; @@ -420,6 +448,7 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_string * The ssl mode information string. + * The error bit set is on error. */ public function get_ssl_mode() { if (!is_string($this->ssl_mode)) { @@ -437,10 +466,12 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_service($service) { if (!is_string($service)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'service', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->service = $service; @@ -452,6 +483,7 @@ class c_base_connection_string extends c_base_return_string { * * @return c_base_return_string * The service information string. + * The error bit set is on error. */ public function get_service() { if (!is_string($this->service)) { @@ -481,8 +513,8 @@ class c_base_connection_string extends c_base_return_string { $this->value .= ' port=' . $this->p_escape_string($this->port); } - if (!empty($this->dbname)) { - $this->value .= ' dbname=' . $this->p_escape_string($this->dbname); + if (!empty($this->database_name)) { + $this->value .= ' database_name=' . $this->p_escape_string($this->database_name); } if (!empty($this->user)) { @@ -610,10 +642,12 @@ class c_base_database { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_session($session) { if (!is_object($session) || !($session instanceof c_base_session)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'session', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->session = $session; @@ -624,6 +658,8 @@ class c_base_database { * Returns the session information. * * @return c_base_session_return + * A session object on success. + * The error bit set is on error. */ public function get_session() { if (!is_object($session) || !($session instanceof c_base_session)) { @@ -641,24 +677,29 @@ class c_base_database { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_connection_string($connection_string) { if (!is_object($connection_string) || !($connection_string instanceof c_base_connection_string)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'connection_string', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->connection_string = $connection_string; $this->connection_string->build(); + return new c_base_return_true(); } /** * Returns the connection string. * - * @return c_base_connection_string_return + * @return c_base_connection_string + * A connection string object on success. + * The error bit set is on error. */ public function get_connection_string() { - if (!is_object($connection_string) || !($connection_string instanceof c_base_connection_string)) { + if (!is_object($this->connection_string) || !($this->connection_string instanceof c_base_connection_string)) { $this->connection_string = new c_base_connection_string(); } @@ -682,11 +723,13 @@ class c_base_database { * TRUE to enable a persistent connection, FALSE otherwise. * * @param c_base_return_status - * TRUE on success, FALSE otherwise + * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_persistent($persistent) { if (!is_bool($persistent)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'persistent', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->persistent = $persistent; @@ -699,6 +742,7 @@ class c_base_database { * * @return c_base_return_status * TRUE on enabled, FALSE on disabled. + * The error bit set is on error. */ public function get_persistent() { if (!is_bool($this->persistent)) { @@ -719,11 +763,13 @@ class c_base_database { * TRUE to enable a asynchronous connection, FALSE otherwise. * * @param c_base_return_status - * TRUE on success, FALSE otherwise + * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function set_asynchronous($asynchronous) { if (!is_bool($asynchronous)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'asynchronous', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->asynchronous = $asynchronous; @@ -734,6 +780,7 @@ class c_base_database { * * @return c_base_return_status * TRUE on enabled, FALSE on disabled. + * The error bit set is on error. */ public function get_asynchronous() { if (!is_bool($this->asynchronous)) { @@ -759,22 +806,25 @@ class c_base_database { * TRUE on success, FALSE otherwise * c_base_return_true is returned if the database is connected. * c_base_return_false is returned if the database is disconnected. - * The error flag is set if there is a problem. - * If the database is already connected when this is called, c_base_return_true is returned with the error flag set. + * FALSE with the error bit set is returned on error. + * If the database is already connected when this is called, c_base_return_true is returned with the error bit set. * * @see: pg_connect() */ public function do_connect($force = FALSE) { if (!is_bool($force)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'force', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($this->connection_string)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'connection_string', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_resource($this->database)) { - return c_base_return_error::s_true(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_UNECESSARY); + return c_base_return_error::s_true($error); } $type = 0; @@ -802,7 +852,9 @@ class c_base_database { unset($type); if ($database === FALSE) { unset($database); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $this->connection_string->get_database_name()->get_value_exact(), ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_CONNECTION_FAILURE); + return c_base_return_error::s_false($error); } $this->database = $database; @@ -822,13 +874,17 @@ class c_base_database { * If there is open large object resource on the connection, do not close the connection before closing all large object resources. * * @param c_base_return_status - * TRUE on success, FALSE otherwise + * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. * * @see: pg_close() */ public function do_disconnect() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if (pg_close($this->database)) { @@ -836,7 +892,8 @@ class c_base_database { return new c_base_return_true(); } - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_close', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -844,13 +901,16 @@ class c_base_database { * * @return c_base_return_status * TRUE on success, FALSE on partial flush. - * FALSE with error flag set on error. + * FALSE with the error bit set is returned on error. * * @see: pg_flush() */ public function do_flush() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $result = pg_flush($this->database); @@ -859,7 +919,8 @@ class c_base_database { } if ($result === FALSE) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_flush', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return new c_base_return_false(); @@ -870,6 +931,7 @@ class c_base_database { * * @return c_base_return_status * TRUE on connected, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function is_connected() { if ($this->connected === TRUE && pg_connection_status($this->database) === PGSQL_CONNECTION_OK) { @@ -892,7 +954,8 @@ class c_base_database { */ public function is_busy() { if (!$this->asynchronous) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->asynchronous', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if (pg_connection_busy($this->database)) { @@ -910,18 +973,21 @@ class c_base_database { * * @return c_base_return_status|c_base_return_string * String containing the status or FALSE on failure. + * FALSE with the error bit set is returned on error. * * @see: pg_parameter_status() */ public function get_parameter_status($name) { if (!is_string($name) || empty($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $result = pg_parameter_status($this->database, $name); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_parameter_status', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($result); @@ -932,15 +998,17 @@ class c_base_database { * * This is used for asynchronous connections. * - * @return c_base_return_int + * @return c_base_return_int|c_base_return_status * The integer is returned on success or failure. * The failure flag will be set accordingly. + * FALSE with the error bit set is returned on error. * * @see: pg_connect_poll() */ public function do_poll() { if (!$this->asynchronous) { - return c_base_return_error::value(0, 'c_base_return_int'); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->database', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_value_exact(pg_connect_poll($this->database)); @@ -951,19 +1019,24 @@ class c_base_database { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. * * @see: pg_connection_reset() */ public function do_reset() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if (pg_connection_reset($this->database)) { return new c_base_return_true(); } - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_connection_reset', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -971,6 +1044,7 @@ class c_base_database { * * @return c_base_return_int * PGSQL_CONNECTION_OK or PGSQL_CONNECTION_BAD. + * The error bit set is on error. * * @see: pg_connection_status() */ @@ -993,7 +1067,10 @@ class c_base_database { */ public function do_ping() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if (pg_status($this->database) === PGSQL_CONNECTION_OK) { @@ -1004,7 +1081,8 @@ class c_base_database { return new c_base_return_false(); } - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::FUNCTION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1024,11 +1102,15 @@ class c_base_database { */ public function escape_literal($literal) { if (!is_string($literal)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'literal', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } return c_base_return_string::s_value_exact(pg_escape_literal($this->database, $literal)); @@ -1051,11 +1133,15 @@ class c_base_database { */ public function escape_bytea($bytea) { if (!is_string($bytea)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'bytea', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } return c_base_return_string::s_value_exact(pg_escape_bytea($this->database, $bytea)); @@ -1078,11 +1164,15 @@ class c_base_database { */ public function escape_identifier($identifier) { if (!is_string($identifier)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'identifier', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } return c_base_return_string::s_value_exact(pg_escape_identifier($this->database, $identifier)); @@ -1105,11 +1195,15 @@ class c_base_database { */ public function unescape_bytea($bytea) { if (!is_string($bytea)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'bytea', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } return c_base_return_string::s_value_exact(pg_unescape_bytea($this->database, $bytea)); @@ -1129,11 +1223,15 @@ class c_base_database { */ public function set_client_encoding($encoding) { if (!is_string($encoding)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'encoding', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } // this function has a strange return status. @@ -1142,7 +1240,8 @@ class c_base_database { return new c_base_return_true(); } - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_set_client_encoding', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1150,19 +1249,24 @@ class c_base_database { * * @return c_base_return_string|c_base_return_status * The string to be returned. - * FALSE is returned on error + * FALSE with the error bit set is returned on error. * * @see: pg_client_encoding() */ public function get_client_encoding() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $encoding = pg_client_encoding($this->database); if ($encoding === FALSE) { unset($encoding); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_client_encoding', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_value_exact($encoding); @@ -1184,14 +1288,18 @@ class c_base_database { */ public function consume_input() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if (pg_consume_input($this->database)) { return new c_base_return_true(); } - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_consume_input', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1214,25 +1322,32 @@ class c_base_database { */ public function do_convert($table, $array, $options = 0) { if (!is_string($table) || empty($table)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'table', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($array)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'array', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($options)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $converted = pg_connect_status($this->database, $table, $array, $options); if ($converted === FALSE) { unset($converted); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_connect_status', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_value_exact($converted); @@ -1265,15 +1380,20 @@ class c_base_database { */ public function do_execute($name, $parameters = array()) { if (!is_string($name) || empty($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($parameters)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'parameters', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if ($this->asynchronous) { @@ -1288,7 +1408,8 @@ class c_base_database { } unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => ($this->asynchronous ? 'pg_send_execute' : 'pg_execute'), ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1321,15 +1442,20 @@ class c_base_database { */ public function do_query($query, $parameters = array()) { if (!is_string($query) || empty($query)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'query', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($parameters)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'parameters', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if ($this->asynchronous) { @@ -1354,7 +1480,24 @@ class c_base_database { } unset($result); - return c_base_return_error::s_false(); + if ($this->asynchronous) { + if (empty($parameters)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_send_query', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + } + else { + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_send_query_params', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + } + } + else { + if (empty($parameters)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_query', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + } + else { + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_query_params', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + } + } + + return c_base_return_error::s_false($error); } /** @@ -1377,21 +1520,22 @@ class c_base_database { * @see: pg_prepare() * @see: pg_send_prepare() */ - public function do_prepare($name) { + public function do_prepare($name, $query) { if (!is_string($name) || empty($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_string($query) || empty($query)) { - return c_base_return_error::s_false(); - } - - if (!is_array($parameters)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'query', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if ($this->asynchronous) { @@ -1406,7 +1550,8 @@ class c_base_database { } unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => ($this->asynchronous ? 'pg_send_prepare' :'pg_prepare'), ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1416,12 +1561,15 @@ class c_base_database { * * @return c_base_database_result|c_base_return_status * A database result is returned on success. - * FALSE is returned on failure. + * FALSE with the error bit set is returned on error. * When asynchronous is not enabled, FALSE is returned without an error flag set. */ public function get_result() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if (!$this->asynchronous) { @@ -1434,7 +1582,8 @@ class c_base_database { } unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_get_result', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1470,7 +1619,10 @@ class c_base_database { */ public function do_cancel() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if (!$this->asynchronous) { @@ -1481,7 +1633,8 @@ class c_base_database { return new c_base_return_true(); } - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_cancel_query', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1527,19 +1680,25 @@ class c_base_database { */ public function do_insert($table, $values, $options = NULL) { if (!is_string($table) || empty($table)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'table', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($values)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'values', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_null($values) || !is_int($options)) { - return c_base_return_error::s_false(); + if (!is_null($options) && !is_int($options)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $this->p_handle_asynchronous_options_parameter($options); @@ -1562,7 +1721,8 @@ class c_base_database { } unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_insert', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1604,23 +1764,30 @@ class c_base_database { */ function do_update($table, $values, $conditions, $options = NULL) { if (!is_string($table) || empty($table)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'table', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($values)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'values', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($conditions)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'conditions', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_null($values) || !is_int($options)) { - return c_base_return_error::s_false(); + if (!is_null($options) && !is_int($options)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $this->p_handle_asynchronous_options_parameter($options); @@ -1643,7 +1810,8 @@ class c_base_database { } unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_update', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1686,19 +1854,25 @@ class c_base_database { */ function do_select($table, $conditions, $options = NULL) { if (!is_string($table) || empty($table)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'table', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_array($values)) { - return c_base_return_error::s_false(); + if (!is_array($conditions)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'conditions', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_array($conditions)) { - return c_base_return_error::s_false(); + if (!is_null($options) && !is_int($options)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $this->p_handle_asynchronous_options_parameter($options); @@ -1724,7 +1898,8 @@ class c_base_database { } unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_select', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1761,21 +1936,27 @@ class c_base_database { * * @see: pg_delete() */ - function do_delete() { - if (!is_string($table) || empty($table)) { - return c_base_return_error::s_false(); + function do_delete($table, $conditions, $options = NULL) { + if (!is_string($table) || empty($table)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'table', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_array($values)) { - return c_base_return_error::s_false(); + if (!is_array($conditions)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'conditions', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_array($conditions)) { - return c_base_return_error::s_false(); + if (!is_null($options) && !is_int($options)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $this->p_handle_asynchronous_options_parameter($options); @@ -1798,7 +1979,8 @@ class c_base_database { } unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_select', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -1812,27 +1994,35 @@ class c_base_database { * TRUE for extended additional information, FALSE for normal additional information. * * @return c_base_return_status|c_base_return_array - * An array containing the additional information or FALSE on error. + * An array containing the additional information. + * FALSE with the error bit set is returned on error. * * @see: pg_meta_data() */ public function get_meta_data($table, $extended = FALSE) { if (!is_string($table) || empty($table)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'table', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($extended)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'extended', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $result = pg_meta_data($this->database, $table, $extended); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_meta_data', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($result); @@ -1854,11 +2044,15 @@ class c_base_database { */ public function set_error_verbosity($verbosity) { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } if (!is_int($verbosity)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'verbosity', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new(pg_set_error_verbosity($this->database, $verbosity)); @@ -1869,18 +2063,24 @@ class c_base_database { * * @return c_base_return_status|c_base_return_string * Message string on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. * * @see: pg_last_error() */ public function get_last_error() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $result = pg_last_error($this->database); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_last_error', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($result); @@ -1891,18 +2091,24 @@ class c_base_database { * * @return c_base_return_status|c_base_return_string * Message string on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. * * @see: pg_last_notice() */ public function get_last_notice() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $result = pg_last_notice($this->database); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_last_notice', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($result); @@ -1920,18 +2126,24 @@ class c_base_database { * - PGSQL_TRANSACTION_INERROR: idle, in a failed transaction block. * - PGSQL_TRANSACTION_UNKNOWN: invalid connection. * - PGSQL_TRANSACTION_ACTIVE: query sent to server, but not yet completed. + * FALSE with the error bit set is returned on error. * * @see: pg_transaction_status() */ public function get_transaction_status() { if (!is_resource($this->database)) { - return c_base_return_error::s_false(); + $database_name = ($this->connection_string instanceof c_base_connection_string) ? $this->connection_string->get_database_name()->get_value_exact() : ''; + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + return c_base_return_error::s_false($error); } $result = pg_transaction_status($this->database); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_transaction_status', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($result); @@ -2004,7 +2216,7 @@ class c_base_database_result extends c_base_return_resource { * Fetch all columns in result set. * * This is not fetching all columns in the result set as in all column names. - * Instead it is fetch all values from every row that belongs to a single column. + * Instead it will fetch all values from every row that belongs to a single column. * * This would be more aptly named something like fetch_all_column_rows($column). * But even that is not the best of names. @@ -2023,8 +2235,22 @@ class c_base_database_result extends c_base_return_resource { */ public function fetch_all_columns($column) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); + } + + if (!is_int($column) || $column < 0) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'column', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $result = pg_fetch_all_columns($this->value, $column); + if ($result === FALSE) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_fetch_all_columns', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } + + return c_base_return_array::s_new($result); } /** @@ -2037,12 +2263,14 @@ class c_base_database_result extends c_base_return_resource { */ public function fetch_all() { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } $result = pg_fetch_all($this->value); if ($result === FALSE) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_fetch_all', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($result); @@ -2067,16 +2295,24 @@ class c_base_database_result extends c_base_return_resource { */ public function fetch_array($row = NULL, $type = PGSQL_ASSOC) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_null($row) && (!is_int($row) || $row < 0)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'row', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_int($type)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - $result = pg_fetch_array($this->value, $row, $column); + $result = pg_fetch_array($this->value, $row, $type); if ($result === FALSE) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_fetch_array', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($result); @@ -2104,19 +2340,23 @@ class c_base_database_result extends c_base_return_resource { */ public function fetch_object($row = NULL, $class = NULL, $parameters = NULL) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_null($row) && (!is_int($row) || $row < 0)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'row', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($class) && !is_string($class)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'class', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($parameters) && !is_array($parameters)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'parameters', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_string($class) && !empty($class)) { @@ -2127,7 +2367,8 @@ class c_base_database_result extends c_base_return_resource { } if ($result === FALSE) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_fetch_object', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_object::s_new($result); @@ -2149,15 +2390,18 @@ class c_base_database_result extends c_base_return_resource { */ public function fetch_result($row, $column) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } - if (!is_null($row) && !is_int($row)) { - return c_base_return_error::s_false(); + if (!is_null($row) && (!is_int($row) || $row < 0)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'row', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_int($row) && !is_string($row) || is_int($row) && $row < 0 || is_string($row) && empty($row)) { - return c_base_return_error::s_false(); + if (!is_int($column) && !is_string($column) || is_int($column) && $column < 0 || is_string($column) && empty($column)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'column', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($row)) { @@ -2169,7 +2413,8 @@ class c_base_database_result extends c_base_return_resource { if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_fetch_result', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_value::s_new($result); @@ -2189,16 +2434,19 @@ class c_base_database_result extends c_base_return_resource { */ public function fetch_row($row = NULL) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_null($row) && (!is_int($row) || $row < 0)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'row', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $result = pg_fetch_row($this->value, $row); if ($result === FALSE) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_fetch_row', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_value::s_new($result); @@ -2230,11 +2478,13 @@ class c_base_database_result extends c_base_return_resource { */ public function error($code = NULL) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_null($code) && !is_int($code)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'code', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($code)) { @@ -2263,7 +2513,8 @@ class c_base_database_result extends c_base_return_resource { */ public function affected_rows() { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new(pg_affected_rows($this->value)); @@ -2274,17 +2525,20 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status|c_base_return_int * The number of rows or FALSE on failure. + * FALSE with the error bit set is returned on error. * * @see: pg_num_rows() */ public function number_of_rows() { if (!is_resource($this->value)) { - return new c_base_return_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } $result = pg_num_rows($this->value); if ($result < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_num_rows', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($result); @@ -2295,17 +2549,20 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status|c_base_return_int * The number of rows or FALSE on failure. + * FALSE with the error bit set is returned on error. * * @see: pg_num_fields() */ public function number_of_columns() { if (!is_resource($this->value)) { - return new c_base_return_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } $result = pg_num_fields($this->value); if ($result < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_num_fields', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($result); @@ -2319,22 +2576,26 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status|c_base_return_string * The name of the field or FALSE on error. + * FALSE with the error bit set is returned on error. * * @see: pg_field_name() */ public function field_name($number) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_int($number) || $number < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'number', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $result = pg_field_name($this->value, $number); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_field_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($result); @@ -2348,23 +2609,27 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status|c_base_return_int * The number of the field or FALSE on error. + * FALSE with the error bit set is returned on error. * * @see: pg_field_num() */ public function field_number($name) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_string($name) || mb_strlen($name) == 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // this returnes -1 on error and >= 0 on success, so translate the codes appropriately. $result = pg_field_number($this->value, $name); if ($result < 0) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_field_number', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($result); @@ -2385,21 +2650,25 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status|c_base_return_int * The printed length of the 'field' or FALSE on error. + * FALSE with the error bit set is returned on error. * * @see: self::field_bytes() * @see: pg_field_prtlen() */ public function field_length($row, $name_or_number) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_null($row) && (!is_int($row) || $row < 0)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'row', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($name_or_number) && !(is_string($name_or_number) && mb_strlen($name) > 0)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name_or_number', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($row)) { @@ -2411,7 +2680,8 @@ class c_base_database_result extends c_base_return_resource { if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_field_prtlen', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($result); @@ -2426,23 +2696,27 @@ class c_base_database_result extends c_base_return_resource { * @return c_base_return_status|c_base_return_int * The size of the column or FALSE on error. * The returned size may be -1, in which case means the size is variable. + * FALSE with the error bit set is returned on error. * * @see: self::field_length() * @see: pg_field_size() */ public function field_bytes($column) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_int($column) || $column < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'column', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $result = pg_size($this->value, $column); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_size', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($result); @@ -2463,27 +2737,32 @@ class c_base_database_result extends c_base_return_resource { * @return c_base_return_status|c_base_return_int|c_base_return_string * The name of the table that the given column belongs to or FALSE on error. * If oid is set to TRUE, then the oid. + * FALSE with the error bit set is returned on error. * * @see: pg_field_table() * @see: http://www.postgresql.org/docs/current/static/datatype-oid.html */ public function field_table($column, $oid = FALSE) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_int($column) || $column < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'column', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($oid)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'oid', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $result = pg_field_table($this->value, $column, $oid); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_field_table', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if ($oid) { @@ -2501,23 +2780,27 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status|c_base_return_int * The oid of the requested column to or FALSE on error. + * FALSE with the error bit set is returned on error. * * @see: pg_field_type_oid() * @see: http://www.postgresql.org/docs/current/static/datatype-oid.html */ public function field_type_oid($column) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_int($column) || $column < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'column', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $result = pg_field_type_oid($this->value, $column); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_field_type_oid', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($result); @@ -2531,6 +2814,7 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status|c_base_return_string * A string containing the oid assigned to the most recently inserted row on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. * * @see: pg_last_oid() * @see: pg_result_status() @@ -2538,13 +2822,15 @@ class c_base_database_result extends c_base_return_resource { */ public function last_oid() { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } $result = pg_last_oid($this->database); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_last_oid', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($result); @@ -2558,22 +2844,26 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status|c_base_return_int * The oid of the requested column to or FALSE on error. + * FALSE with the error bit set is returned on error. * * @see: pg_field_type() */ public function field_type($column) { if (!is_resource($this->value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_RESOURCE); + return c_base_return_error::s_false($error); } if (!is_int($column) || $column < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'column', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $result = pg_field_type($this->value, $column); if ($result === FALSE) { unset($result); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'pg_field_type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($result); @@ -2584,7 +2874,7 @@ class c_base_database_result extends c_base_return_resource { * * @return c_base_return_status * TRUE is returned on success, FALSE is returned if nothing to free. - * FALSE with the error flag set is returned on error. + * FALSE with the error bit set is returned on error. * * @see: pg_free_result() */ @@ -2597,7 +2887,8 @@ class c_base_database_result extends c_base_return_resource { return new c_base_return_true(); } - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::FUNCTION_FAILURE); + return c_base_return_error::s_false($error); } } @@ -2662,15 +2953,18 @@ class c_base_database_query extends c_base_return_array { * * @return c_base_return_status * TRUE on success, FALSE otherwise. + * FALSE with the error bit set is returned on error. */ public function import($import) { if (!is_string($import) || empty($import)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'import', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $decoded = json_decode($import, TRUE); if (!is_array($decoded) || empty($decoded)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'json_decode', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->p_initialize(); @@ -2686,6 +2980,7 @@ class c_base_database_query extends c_base_return_array { * @return c_base_return_status|c_base_return_string * FALSE is returned when there is no content to export. * Otherwise, a json encoded string is returned. + * FALSE with the error bit set is returned on error. */ public function export() { if ($this->count_table == 0 || empty($this->value)) { @@ -2696,7 +2991,8 @@ class c_base_database_query extends c_base_return_array { // everything else has to be re-created on import for security reasons. $encoded = json_encode($this->value); if (!is_string($encoded)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'json_encode', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($encoded); diff --git a/common/base/classes/base_debug.php b/common/base/classes/base_debug.php index 2815dc7..6092260 100644 --- a/common/base/classes/base_debug.php +++ b/common/base/classes/base_debug.php @@ -66,7 +66,8 @@ class c_base_debug { */ public static function s_set_debugging($debug) { if (!is_bool($debug)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'debug', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } self::$ps_debugging = $debug; @@ -162,11 +163,13 @@ class c_base_debug { } if (!is_bool($milliseconds)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'milliseconds', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($this->time_start) || is_null($this->time_stop)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->time_stop', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if ($milliseconds) { @@ -199,13 +202,20 @@ class c_base_debug { return new c_base_return_false(); } - if (!is_int($option) || $option < 1 || $option > 3 || !is_bool($megabytes)) { - return c_base_return_error::s_false(); + if (!is_int($option) || $option < 1 || $option > 3) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'option', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_bool($megabytes)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'megabytes', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($option == 1) { if (is_null($this->memory_usage_peak)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->memory_usage_peak', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if ($megabytes) { @@ -216,7 +226,8 @@ class c_base_debug { } elseif ($option == 2) { if (is_null($this->time_stop)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->time_stop', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if ($megabytes) { @@ -226,8 +237,14 @@ class c_base_debug { return c_base_return_int::s_new($this->memory_usage_stop); } else { - if (is_null($this->time_start) || is_null($this->time_stop)) { - return c_base_return_error::s_false(); + if (is_null($this->time_start)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->time_start', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); + } + + if (is_null($this->time_stop)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->time_stop', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if ($megabytes) { diff --git a/common/base/classes/base_error.php b/common/base/classes/base_error.php index cd1e5e4..185c3f1 100644 --- a/common/base/classes/base_error.php +++ b/common/base/classes/base_error.php @@ -11,6 +11,9 @@ * Therefore, it is an exception case to the use of base_return classes as a return value and must instead return raw/native PHP values. * * This provides a custom facility for syslog/openlog calls so that a 'none' facility can be supported. + * + * @todo: I either need to create a global/static (aka: non-threadsafe) class for assigning error settings OR I need to add a variable to each class object to assign error settings (uses more resources). + * This needs to be done so that stuff like debug_backtrace() is called only once and is only called if needed. */ class c_base_error { const SEVERITY_NONE = 0; @@ -59,6 +62,7 @@ class c_base_error { private $backtrace; private $code; private $ignore_arguments; + private $backtrace_performed; /** @@ -72,6 +76,7 @@ class c_base_error { $this->backtrace = array(); $this->code = NULL; $this->ignore_arguments = TRUE; + $this->backtrace_performed = FALSE; } /** @@ -85,6 +90,7 @@ class c_base_error { unset($this->backtrace); unset($this->code); unset($this->ignore_arguments); + unset($this->backtrace_performed); } /** @@ -118,28 +124,28 @@ class c_base_error { if (is_string($message)) { $entry->set_message($message); } - elseif (is_null($this->message)) { + elseif (is_null($message)) { $entry->set_message(''); } if (is_array($details)) { $entry->set_details($details); } - elseif (is_null($this->details)) { + elseif (is_null($details)) { $entry->set_details(array()); } if (is_int($code)) { $entry->set_code($code); } - elseif (is_null($this->message)) { + elseif (is_null($message)) { $entry->set_code(0); } if (is_int($severity) && $severity >= self::SEVERITY_EMERGENCY && $severity < self::SEVERITY_UNKNOWN) { $entry->set_severity($severity); } - elseif (is_null($this->message)) { + elseif (is_null($severity)) { $entry->set_severity(self::SEVERITY_ERROR); } @@ -148,7 +154,7 @@ class c_base_error { } // build the backtrace, but ignore this function call when generating. - $this->set_backtrace(1); + $entry->set_backtrace(1); return $entry; } @@ -472,6 +478,8 @@ class c_base_error { $this->backtrace = $backtrace; } unset($backtrace); + + $this->backtrace_performed = TRUE; } } @@ -487,11 +495,21 @@ class c_base_error { * @see: http://www.loc.gov/standards/iso639-2/php/code_list.php */ interface i_base_error_messages { - const NONE = 0; - const ARGUMENT_INVALID = 1; - const OPERATION_FAILURE = 2; - const INVALID_FORMAT = 3; - const INVALID_VARIABLE = 4; + const NONE = 0; + const INVALID_ARGUMENT = 1; + const INVALID_FORMAT = 2; + const INVALID_VARIABLE = 3; + const OPERATION_FAILURE = 4; + const OPERATION_UNECESSARY = 5; + const FUNCTION_FAILURE = 6; + const NOT_FOUND_ARRAY_INDEX = 7; + const NOT_FOUND_DIRECTORY = 8; + const NOT_FOUND_FILE = 9; + const NO_CONNECTION = 10; + const NO_SUPPORT = 11; + const POSTGRESQL_CONNECTION_FAILURE = 12; + const POSTGRESQL_NO_CONNECTION = 13; + const POSTGRESQL_NO_RESOURCE = 14; /** diff --git a/common/base/classes/base_error_messages_english.php b/common/base/classes/base_error_messages_english.php index f163772..d2e8f3c 100644 --- a/common/base/classes/base_error_messages_english.php +++ b/common/base/classes/base_error_messages_english.php @@ -21,41 +21,133 @@ class c_base_error_messages_eng extends i_base_error_messages { * (optional) When TRUE, argument placeholders are added. * When FALSE, no placeholders are provided. * All placeholders should begin with a single colon ':'. + * @param bool $function_name + * (optional) When TRUE, the function name is included with the message. + * When FALSE, no funciton name is provided. + * + * @return c_base_return_string + * A processed string is returned on success. + * FALSE with error bit set is returned on error. */ - static function s_get_message($code, $arguments = TRUE) { - if ($code === self::ARGUMENT_INVALID) { + static function s_get_message($code, $arguments = TRUE, $function_name = FALSE) { + $function_name_string = NULL; + if ($function_name) { + $function_name_string = ' while calling :function_name'; + } + + if ($code === self::INVALID_ARGUMENT) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('An invalid argument, :argument_name, has been specified' . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('An invalid argument has been specified' . $function_name_string . '.'); + } + } + elseif ($code === self::INVALID_FORMAT) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('The argument, :format_name, has an invalid format' . $function_name_string . '.:expected_format'); + } + else { + return c_base_return_string::s_new('An invalid format has been specified.'); + } + } + elseif ($code === self::INVALID_VARIABLE) { if ($arguments === TRUE) { - return 'An invalid argument, :argument_name, has been specified.'; + return c_base_return_string::s_new('The variable, :variable_name, is invalid' . $function_name_string . '.'); } else { - return 'An invalid argument has been specified.'; + return c_base_return_string::s_new('An invalid variable has been specified.'); } } elseif ($code === self::OPERATION_FAILURE) { if ($arguments === TRUE) { - return 'Failed to perform operation: :operation_name.'; + return c_base_return_string::s_new('Failed to perform operation, :operation_name' . (is_null($function_name_string) ? '' : ',') . $function_name_string . '.'); } else { - return 'Failed to perform operation.'; + return c_base_return_string::s_new('Failed to perform operation.'); } } - elseif ($code === self::INVALID_FORMAT) { + elseif ($code === self::OPERATION_UNECESSARY) { if ($arguments === TRUE) { - return 'The argument, :format_name, has an invalid format.'; + return c_base_return_string::s_new('Did not perform unecessary operation, :operation_name' . (is_null($function_name_string) ? '' : ',') . $function_name_string . '.'); } else { - return 'An invalid format has been specified.'; + return c_base_return_string::s_new('Did not perform unecessary operation.'); } } - elseif ($code === self::INVALID_VARIABLE) { + elseif ($code === self::FUNCTION_FAILURE) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('The function, :function_name, has failed execution.'); + } + else { + return c_base_return_string::s_new('A function has failed execution.'); + } + } + elseif ($code === self::NOT_FOUND_ARRAY_INDEX) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('The index, :index_name, was not found in the array, :array_name' . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('Failed to find index within specified array.'); + } + } + elseif ($code === self::NOT_FOUND_FILE) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('The file, :file_name, was not found or cannot be accessed' . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('File not found or cannot be accessed.'); + } + } + elseif ($code === self::NOT_FOUND_DIRECTORY) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('The directory, :direction_name, was not found or cannot be accessed' . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('File not found or cannot be accessed.'); + } + } + elseif ($code === self::NO_CONNECTION) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('The resource, :resource_name, is not connected' . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('The resource is not connected.'); + } + } + elseif ($code === self::NO_SUPPORT) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('The functionality, :functionality_name, is currently not supported.' . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('The requested functionality is not supported.'); + } + } + elseif ($code === self::POSTGRESQL_CONNECTION_FAILURE) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('Failed to connect to the database, :database_name' . (is_null($function_name_string) ? '' : ',') . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('Failed to connect to the database.'); + } + } + elseif ($code === self::POSTGRESQL_NO_CONNECTION) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('The database, :database_name, is not connected' . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('The database is not connected.'); + } + } + elseif ($code === self::POSTGRESQL_NO_RESOURCE) { if ($arguments === TRUE) { - return 'The variable, :variable_name, is invalid.'; + return c_base_return_string::s_new('No database resource is available' . $function_name_string . '.'); } else { - return 'An invalid variable has been specified.'; + return c_base_return_string::s_new('No database resource is available.'); } } - return ''; + return c_base_return_string::s_new(''); } } diff --git a/common/base/classes/base_html.php b/common/base/classes/base_html.php index 7d3db75..d1c7dac 100644 --- a/common/base/classes/base_html.php +++ b/common/base/classes/base_html.php @@ -63,7 +63,8 @@ class c_base_html { */ public function set_id($id) { if (!is_int($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->id = $id; @@ -101,7 +102,8 @@ class c_base_html { */ public function set_attribute($attribute, $value) { if (!is_int($attribute)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return $this->p_set_attribute($attribute, $value); @@ -122,7 +124,8 @@ class c_base_html { */ public function set_attribute_body($attribute, $value) { if (!is_int($attribute)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return $this->p_set_attribute($attribute, $value, TRUE); @@ -156,7 +159,8 @@ class c_base_html { */ public function get_attribute($attribute) { if (!is_int($attribute)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return $this->p_get_attribute($attribute); @@ -177,7 +181,8 @@ class c_base_html { */ public function get_attribute_body($attribute) { if (!is_int($attribute)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return $this->p_get_attribute($attribute, TRUE); @@ -198,11 +203,13 @@ class c_base_html { */ public function set_tag($tag, $delta = NULL) { if (!($tag instanceof c_base_markup_tag)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'tag', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($delta) && !is_int($delta)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'delta', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($this->body)) { @@ -231,7 +238,8 @@ class c_base_html { */ public function get_tag($delta) { if (!is_int($delta)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'delta', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!array_key_exists($delta, $this->body)) { @@ -271,11 +279,13 @@ class c_base_html { */ public function set_header($header, $delta = NULL) { if (!($header instanceof c_base_markup_tag)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'header', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($delta) && !is_int($delta)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'delta', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // only certain header types are allowed. @@ -319,7 +329,8 @@ class c_base_html { */ public function get_header($delta) { if (!is_int($delta)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'delta', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!array_key_exists($delta, $this->headers)) { @@ -513,8 +524,7 @@ class c_base_html { switch ($attribute) { case c_base_markup_attributes::ATTRIBUTE_NONE: - // should not be possible, so consider this an error (attributes set to NONE are actually unset from the array). - return c_base_return_error::s_false(); + return new c_base_return_null(); case c_base_markup_attributes::ATTRIBUTE_ABBR: case c_base_markup_attributes::ATTRIBUTE_ACCESS_KEY: diff --git a/common/base/classes/base_http.php b/common/base/classes/base_http.php index 877eb31..f3fb081 100644 --- a/common/base/classes/base_http.php +++ b/common/base/classes/base_http.php @@ -278,7 +278,8 @@ class c_base_http extends c_base_rfc_string { } if (!is_int($header_name) || !array_key_exists($header_name, $this->request)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'header_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->request[$header_name]); @@ -307,7 +308,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_language_class($class_name) { if (!is_string($class_name) || !is_subclass_of('i_base_language', $class_name) ) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'class_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->language_class = $class_name; @@ -662,7 +664,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_access_control_allow_origin($uri) { if (!is_string($uri)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'uri', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($uri == c_base_ascii::ASTERISK) { @@ -672,7 +675,8 @@ class c_base_http extends c_base_rfc_string { $parsed = $this->p_parse_uri($uri); if ($parsed['invalid']) { unset($parsed); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_parse_uri', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($parsed['invalid']); @@ -701,7 +705,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_access_control_allow_credentials($allow_credentials) { if (!is_bool($allow_credentials)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'allowed_credentials', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_CREDENTIALS] = $allow_credentials; @@ -729,20 +734,28 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_access_control_expose_headers($header_name, $append = TRUE) { if (!is_string($header_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'header_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $parsed = $this->p_prepare_token($header_name); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_prepare_token', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if ($append) { + if (!isset($this->response[self::RESPONSE_ACCESS_CONTROL_EXPOSE_HEADERS]) || !is_array($this->response[self::RESPONSE_ACCESS_CONTROL_EXPOSE_HEADERS])) { + $this->response[self::RESPONSE_ACCESS_CONTROL_EXPOSE_HEADERS] = array(); + } + $this->response[self::RESPONSE_ACCESS_CONTROL_EXPOSE_HEADERS][$parsed] = $parsed; } else { @@ -770,7 +783,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_access_control_max_age($timestamp) { if (!is_int($timestamp) && !is_float($timestamp)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'timestamp', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_ACCESS_CONTROL_MAX_AGE] = $timestamp; @@ -796,15 +810,21 @@ class c_base_http extends c_base_rfc_string { * @see: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing */ public function set_response_access_control_allow_methods($method, $append = TRUE) { - if (!is_int($uri)) { - return c_base_return_error::s_false(); + if (!is_int($method)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'method', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($append) { + if (!isset($this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_METHODS]) || !is_array($this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_METHODS])) { + $this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_METHODS] = array(); + } + $this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_METHODS][$method] = $method; } else { @@ -830,20 +850,28 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_access_control_allow_headers($header_name, $append = TRUE) { if (!is_string($header_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'header_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $parsed = $this->p_prepare_token($header_name); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_prepare_token', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if ($append) { + if (!isset($this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_HEADERS]) || !is_array($this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_HEADERS])) { + $this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_HEADERS] = array(); + } + $this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_HEADERS][$parsed] = $parsed; } else { @@ -873,18 +901,21 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_accept_patch($media_type, $append = TRUE) { if (!is_string($media_type)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'media_type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $text = $this->pr_rfc_string_prepare($media_type); if ($text['invalid']) { unset($text); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->pr_rfc_string_prepare', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $parsed = $this->pr_rfc_string_is_media_type($text['ordinals'], $text['characters']); @@ -893,12 +924,17 @@ class c_base_http extends c_base_rfc_string { if ($parsed['invalid']) { unset($parsed); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->pr_rfc_string_is_media_type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($parsed['invalid']); unset($parsed['current']); if ($append) { + if (!isset($this->response[self::RESPONSE_ACCEPT_PATCH]) || !is_array($this->response[self::RESPONSE_ACCEPT_PATCH])) { + $this->response[self::RESPONSE_ACCEPT_PATCH] = array(); + } + $this->response[self::RESPONSE_ACCEPT_PATCH][] = $parsed; } else { @@ -929,13 +965,16 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_accept_ranges($ranges) { if (!is_string($ranges)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ranges', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $parsed = $this->p_prepare_token($ranges); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_prepare_token', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_ACCEPT_RANGES] = $parsed; @@ -958,7 +997,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_age($seconds) { if (!is_int($seconds)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'seconds', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_AGE] = $seconds; @@ -986,11 +1026,13 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_allow($allow, $append = TRUE) { if (!is_int($allow)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'allow', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } switch ($allow) { @@ -1008,7 +1050,8 @@ class c_base_http extends c_base_rfc_string { case self::HTTP_METHOD_DEBUG: break; default: - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'allow', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($allow == self::HTTP_METHOD_NONE) { @@ -1017,6 +1060,10 @@ class c_base_http extends c_base_rfc_string { } if ($append) { + if (!isset($this->response[self::RESPONSE_ALLOW]) || !is_array($this->response[self::RESPONSE_ALLOW])) { + $this->response[self::RESPONSE_ALLOW] = array(); + } + $this->response[self::RESPONSE_ALLOW][$allow] = $allow; } else { @@ -1056,15 +1103,18 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_cache_control($directive_name, $directive_value = NULL, $append = TRUE) { if (!is_int($directive_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'directive_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($directive_value) && !is_string($directive_value)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'directive_value', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } switch($directive_name) { @@ -1083,7 +1133,8 @@ class c_base_http extends c_base_rfc_string { break; default: - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'directive_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $parsed_directive_value = NULL; @@ -1092,7 +1143,8 @@ class c_base_http extends c_base_rfc_string { if ($text['invalid']) { unset($text); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->pr_rfc_string_prepare', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $parsed = $this->pr_rfc_string_is_token_quoted($text['ordinals'], $text['characters']); @@ -1101,12 +1153,17 @@ class c_base_http extends c_base_rfc_string { if ($parsed['invalid']) { unset($parsed); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->pr_rfc_string_is_token_quoted', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($parsed); } if ($append) { + if (!isset($this->response[self::RESPONSE_CACHE_CONTROL]) || !is_array($this->response[self::RESPONSE_CACHE_CONTROL])) { + $this->response[self::RESPONSE_CACHE_CONTROL] = array(); + } + $this->response[self::RESPONSE_CACHE_CONTROL][$directive_name] = $directive_value; } else { @@ -1121,8 +1178,8 @@ class c_base_http extends c_base_rfc_string { /** * Assign HTTP response header: connection. * - * @param string $header_name - * The header name to assign as a connection-specific field. + * @param string $connection_option + * The connection option to assign as a connection-specific field. * These header fields apply only to the immediate client. * The header name format is: * - 1*(tchar) @@ -1136,22 +1193,30 @@ class c_base_http extends c_base_rfc_string { * * @see: https://tools.ietf.org/html/rfc7230#section-6.1 */ - public function set_response_connection($header_name, $append = TRUE) { - if (!is_string($header_name)) { - return c_base_return_error::s_false(); + public function set_response_connection($connection_option, $append = TRUE) { + if (!is_string($connection_option)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'connection_option', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - $parsed = $this->p_prepare_token($header_name); + $parsed = $this->p_prepare_token($connection_option); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_prepare_token', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if ($append) { + if (!isset($this->response[self::RESPONSE_CONNECTION]) || !is_array($this->response[self::RESPONSE_CONNECTION])) { + $this->response[self::RESPONSE_CONNECTION] = array(); + } + $this->response[self::RESPONSE_CONNECTION][$parsed] = $parsed; } else { @@ -1189,15 +1254,18 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_content($content, $append = TRUE, $is_file = FALSE) { if (!is_string($content)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'content', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($is_file)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_file', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($append) { @@ -1253,7 +1321,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_content_disposition($disposition) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response content disposition', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -1315,9 +1385,6 @@ class c_base_http extends c_base_rfc_string { * * @param int $encoding * The encoding to assign to the specified header. - * @param bool $append - * (optional) If TRUE, then append the header name. - * If FALSE, then assign the header name. * * @return c_base_return_status * TRUE on success, FALSE otherwise. @@ -1328,13 +1395,15 @@ class c_base_http extends c_base_rfc_string { * @see: https://tools.ietf.org/html/rfc7231#section-3.1.2.2 * @see: https://tools.ietf.org/html/rfc7230#section-3.3.1 */ - public function set_response_content_encoding($encoding, $append = TRUE) { + public function set_response_content_encoding($encoding) { if (!is_int($encoding)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'encoding', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } switch ($encoding) { @@ -1351,7 +1420,8 @@ class c_base_http extends c_base_rfc_string { case self::ENCODING_PG: break; default: - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'encoding', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CONTENT_ENCODING] = $encoding; @@ -1374,18 +1444,22 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_content_language($language = NULL) { if (!is_null($language) && !is_int($language)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'language', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($language)) { if (!is_object($this->language_class) || !($this->language_class instanceof i_base_language)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->language_class', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $default = $this->language_class->s_get_default_id(); if ($default instanceof c_base_return_false) { unset($default); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->language_class->s_get_default_id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CONTENT_LANGUAGE] = $default; @@ -1393,7 +1467,8 @@ class c_base_http extends c_base_rfc_string { } else { if ($language_class->s_get_names_by_id($language) instanceof c_base_return_false) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'language_class->s_get_names_by_id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CONTENT_LANGUAGE] = $language; @@ -1424,7 +1499,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_content_length($length = NULL) { if (!is_null($length) && !is_int($length) || $length < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'length', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // From the RFC: "A sender MUST NOT send a Content-Length header field in any message that contains a Transfer-Encoding header field." @@ -1443,8 +1519,9 @@ class c_base_http extends c_base_rfc_string { foreach ($this->content as $filename) { if (!file_exists($filename)) { unset($filename); - // @todo: provide a file not found error. - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $filename, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CONTENT_LENGTH] += filesize($filename); @@ -1474,7 +1551,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_content_range($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response content range', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -1496,23 +1575,28 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_content_type($content_type, $charset = c_base_charset::UTF_8) { if (!is_string($content_type)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'content_type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!c_base_charset::s_is_valid($charset)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'charset', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // perform a very basic syntax check. if (strpos($content_type, ';')) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':format_name' => 'content_type', ':expected_format' => '. Semi-colons are not allowed.', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_FORMAT); + return c_base_return_error::s_false($error); } $content_type_part = mb_split('/', $content_type); if (count($content_type_part) != 2) { unset($content_type_part); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'mb_split', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($content_type_part); @@ -1548,7 +1632,8 @@ class c_base_http extends c_base_rfc_string { } if (!is_int($timestamp) && !is_float($timestamp)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'timestamp', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_DATE] = $timestamp; @@ -1583,7 +1668,8 @@ class c_base_http extends c_base_rfc_string { } if (!is_int($timestamp) && !is_float($timestamp)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'timestamp', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_DATE_ACTUAL] = $timestamp; @@ -1614,7 +1700,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_etag($entity_tag = NULL, $weak = FALSE) { if (!is_null($entity_tag) && !is_string($entity_tag) && $entity_tag !== FALSE) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'entity_tag', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $response = array( @@ -1649,8 +1736,8 @@ class c_base_http extends c_base_rfc_string { unset($hash); unset($response); - // @todo: report file not found or other related errors. - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $filename, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } $success = hash_update_file($hash, $filename); @@ -1660,8 +1747,8 @@ class c_base_http extends c_base_rfc_string { unset($hash); unset($response); - // @todo: report failure to hash file. - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $filename, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } } unset($filename); @@ -1714,7 +1801,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_expires($timestamp) { if (!is_int($timestamp) && !is_float($timestamp)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'timestamp', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_EXPIRES] = $timestamp; @@ -1735,7 +1823,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_last_modified($timestamp) { if (!is_int($timestamp) && !is_float($timestamp)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'timestamp', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_LAST_MODIFIED] = $timestamp; @@ -1759,13 +1848,16 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_link($uri) { if (!is_string($uri)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'uri', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } #$parsed = $this->p_parse_uri($uri); // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response link', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -1784,13 +1876,15 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_location($uri) { if (!is_string($uri)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'uri', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $parsed = $this->p_parse_uri($uri); if ($parsed['invalid']) { unset($parsed); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_parse_uri', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($parsed['invalid']); @@ -1815,7 +1909,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_pragma($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response pragma', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -1832,7 +1928,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_proxy_authenticate($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response proxy authenticate', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -1849,7 +1947,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_public_key_pins($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response public key pins', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -1872,7 +1972,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_refresh($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response refresh', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -1892,12 +1994,14 @@ class c_base_http extends c_base_rfc_string { * @see: https://tools.ietf.org/html/rfc7231#section-7.1.3 */ public function set_response_retry_after($date, $seconds = FALSE) { - if (!is_int($date) || !is_float($timestamp)) { - return c_base_return_error::s_false(); + if (!is_int($date)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'date', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($seconds)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'seconds', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_RETRY_AFTER] = array( @@ -1922,22 +2026,54 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_server($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response server', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** - * Assign HTTP response header: set_cookie. + * Assign HTTP response header: set-cookie. * - * @param ?? $value - * The value to assign to the specified header. + * @param c_base_cookie $cookie + * The cookie object to assign as a cookie. + * These header fields apply only to the immediate client. + * The header name format is: + * - 1*(tchar) + * @param bool $append + * (optional) If TRUE, then append the header name. + * If FALSE, then assign the header name. * * @return c_base_return_status * TRUE on success, FALSE otherwise. * FALSE with error bit set is returned on error. + * + * @see: https://tools.ietf.org/html/rfc6265 */ - public function set_response_set_cookie($value) { - // @todo - return new c_base_return_false(); + public function set_response_set_cookie($cookie, $append = TRUE) { + if (!($cookie instanceof c_base_cookie)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'cookie', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_bool($append)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $cookie_name = $cookie->get_name()->get_value_exact(); + if ($append) { + if (!isset($this->response[self::RESPONSE_SET_COOKIE]) || !is_array($this->response[self::RESPONSE_SET_COOKIE])) { + $this->response[self::RESPONSE_SET_COOKIE] = array(); + } + + $this->response[self::RESPONSE_SET_COOKIE][$cookie_name] = $cookie; + } + else { + $this->response[self::RESPONSE_SET_COOKIE] = array($cookie_name => $cookie); + } + unset($cookie_name); + + return new c_base_return_true(); } /** @@ -1954,7 +2090,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_status($code) { if (!is_int($code)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'code', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_STATUS] = $code; @@ -1973,7 +2110,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_strict_transport_security($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response strict transport security', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -1988,7 +2127,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_trailer($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response trailer', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2019,7 +2160,9 @@ class c_base_http extends c_base_rfc_string { // RESPONSE_TRANSFER_ENCODING // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response transfer encoding', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2034,7 +2177,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_upgrade($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response upgrade', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2054,16 +2199,27 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_vary($header_name, $append = TRUE) { if (!is_string($header_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'header_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_bool($append)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $parsed = $this->p_prepare_token($header_name); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_prepare_token', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if ($append) { + if (!isset($this->response[self::RESPONSE_VARY]) || !is_array($this->response[self::RESPONSE_VARY])) { + $this->response[self::RESPONSE_VARY] = array(); + } + $this->response[self::RESPONSE_VARY][$parsed] = $parsed; } else { @@ -2088,7 +2244,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_warning($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response warning', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2105,7 +2263,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_www_authenticate($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response www authenticate', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2120,7 +2280,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_protocol($protocol) { if (!is_string($protocol)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'protocol', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_PROTOCOL] = $protocol; @@ -2140,7 +2301,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_content_security_policy($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response content security policy', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2155,7 +2318,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_x_content_type_options($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response content type options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2170,7 +2335,9 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_x_ua_compatible($value) { // @todo - return new c_base_return_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response ua compatible', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2203,20 +2370,34 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_checksum_header($action = self::CHECKSUM_ACTION_AUTO, $what = NULL, $type = NULL, $checksum = NULL) { if (!is_int($action)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'action', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($action != self::CHECKSUM_ACTION_NONE && $action != self::CHECKSUM_ACTION_AUTO && $action != self::CHECKSUM_ACTION_MANUAL) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'action', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($action == self::CHECKSUM_ACTION_MANUAL) { - if (!is_int($what) || !is_int($type) || !is_string($checksum)) { - return c_base_return_error::s_false(); + if (!is_int($what)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'what', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_int($type)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($checksum)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'checksum', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($what != self::CHECKSUM_WHAT_PARTIAL && $what != self::CHECKSUM_WHAT_FULL) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'what', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } switch ($type) { @@ -2232,7 +2413,8 @@ class c_base_http extends c_base_rfc_string { case CHECKSUM_PG: break; default: - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CHECKSUM_HEADER] = array( @@ -2243,8 +2425,19 @@ class c_base_http extends c_base_rfc_string { ); } else { - if (!is_null($what) || !is_null($type) || !is_null($checksum)) { - return c_base_return_error::s_false(); + if (!is_int($what)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'what', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_int($type)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($checksum)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'checksum', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CHECKSUM_HEADER] = array( @@ -2273,20 +2466,27 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_checksum_headers($header_name, $append = TRUE) { if (!is_string($header_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'header_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($append)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'append', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $parsed = $this->p_prepare_token($header_name); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_prepare_token', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if ($append) { + if (!isset($this->response[self::RESPONSE_CHECKSUM_HEADERS]) || !is_array($this->response[self::RESPONSE_CHECKSUM_HEADERS])) { + $this->response[self::RESPONSE_CHECKSUM_HEADERS] = array(); + } + $this->response[self::RESPONSE_CHECKSUM_HEADERS][$parsed] = $parsed; } else { @@ -2328,20 +2528,34 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_checksum_content($action = self::CHECKSUM_ACTION_AUTO, $what = NULL, $type = NULL, $checksum = NULL) { if (!is_int($action)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'action', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($action != self::CHECKSUM_ACTION_NONE && $action != self::CHECKSUM_ACTION_AUTO && $action != self::CHECKSUM_ACTION_MANUAL) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'action', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($action == self::CHECKSUM_ACTION_MANUAL) { - if (!is_int($what) || !is_int($type) || !is_string($checksum)) { - return c_base_return_error::s_false(); + if (!is_int($what)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'what', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_int($type)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($checksum)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'checksum', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($what != self::CHECKSUM_WHAT_PARTIAL && $what != self::CHECKSUM_WHAT_FULL) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'what', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } switch ($type) { @@ -2357,7 +2571,8 @@ class c_base_http extends c_base_rfc_string { case CHECKSUM_PG: break; default: - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CHECKSUM_CONTENT] = array( @@ -2368,8 +2583,19 @@ class c_base_http extends c_base_rfc_string { ); } else { - if (!is_null($what) || !is_null($type) || !is_null($checksum)) { - return c_base_return_error::s_false(); + if (!is_int($what)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'what', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_int($type)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($checksum)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'checksum', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CHECKSUM_CONTENT] = array( @@ -2397,7 +2623,8 @@ class c_base_http extends c_base_rfc_string { */ public function set_response_content_revision($revision) { if (!is_int($revision)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'revision', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->response[self::RESPONSE_CONTENT_REVISION] = $revision; @@ -2417,7 +2644,8 @@ class c_base_http extends c_base_rfc_string { */ public function unset_response_value($response_id) { if (!is_int($response_id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'response_id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($response_id, $this->response)) { @@ -2433,7 +2661,7 @@ class c_base_http extends c_base_rfc_string { * @todo: I only glanced at the documentation (which was incomplete on wikipedia). * More work is likely needed to be done with this and its structure is subject to change. * - * @return c_base_return_array|bool + * @return c_base_return_array|c_base_return_status * A decoded uri split into its different parts inside an array. * This array also contains a key called 'wildcard' which may be either TRUE or FALSE. * FALSE with error bit set is returned on error, including when the key is not defined. @@ -2442,7 +2670,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_access_control_allow_origin() { if (!array_key_exists(self::RESPONSE_ACCESS_CONTROL_ALLOW_ORIGIN, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ACCESS_CONTROL_ALLOW_ORIGIN, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_ORIGIN]); @@ -2462,7 +2691,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_access_control_allow_credentials() { if (!array_key_exists(self::RESPONSE_ACCESS_CONTROL_ALLOW_CREDENTIALS, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ACCESS_CONTROL_ALLOW_CREDENTIALS, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_bool::s_new($this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_CREDENTIALS]); @@ -2482,7 +2712,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_access_control_expose_headers() { if (!array_key_exists(self::RESPONSE_ACCESS_CONTROL_EXPOSE_HEADERS, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ACCESS_CONTROL_EXPOSE_HEADERS, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_ACCESS_CONTROL_EXPOSE_HEADERS]); @@ -2502,7 +2733,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_access_control_max_age() { if (!array_key_exists(self::RESPONSE_ACCESS_CONTROL_MAX_AGE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ACCESS_CONTROL_MAX_AGE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($this->response[self::RESPONSE_ACCESS_CONTROL_MAX_AGE]); @@ -2514,14 +2746,15 @@ class c_base_http extends c_base_rfc_string { * @todo: I only glanced at the documentation (which was incomplete on wikipedia). * More work is likely needed to be done with this and its structure is subject to change. * - * @return c_base_return_array|bool + * @return c_base_return_array|c_base_return_status * FALSE with error bit set is returned on error, including when the key is not defined. * * @see: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing */ public function get_response_access_control_allow_methods() { if (!array_key_exists(self::RESPONSE_ACCESS_CONTROL_ALLOW_METHODS, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ACCESS_CONTROL_ALLOW_METHODS, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_METHODS]); @@ -2539,7 +2772,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_access_control_allow_headers() { if (!array_key_exists(self::RESPONSE_ACCESS_CONTROL_ALLOW_HEADERS, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ACCESS_CONTROL_ALLOW_HEADERS, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_ACCESS_CONTROL_ALLOW_HEADERS]); @@ -2557,7 +2791,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_accept_patch() { if (!array_key_exists(self::RESPONSE_ACCEPT_PATCH, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ACCEPT_PATCH, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_ACCEPT_PATCH]); @@ -2580,7 +2815,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_accept_ranges() { if (!array_key_exists(self::RESPONSE_ACCEPT_RANGES, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ACCEPT_RANGES, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($this->response[self::RESPONSE_ACCEPT_RANGES]); @@ -2597,7 +2833,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_age() { if (!array_key_exists(self::RESPONSE_AGE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_AGE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($this->response[self::RESPONSE_AGE]); @@ -2614,7 +2851,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_allow() { if (!array_key_exists(self::RESPONSE_ALLOW, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ALLOW, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_ALLOW]); @@ -2647,7 +2885,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_cache_control() { if (!array_key_exists(self::RESPONSE_CACHE_CONTROL, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CACHE_CONTROL, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_CACHE_CONTROL]); @@ -2656,7 +2895,7 @@ class c_base_http extends c_base_rfc_string { /** * Obtain HTTP response header: connection. * - * @return c_base_return_array|bool + * @return c_base_return_array|c_base_return_status * An array of header names assigned to the connection header. * The header name format is: * - 1*(tchar) @@ -2667,7 +2906,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_connection() { if (!array_key_exists(self::RESPONSE_CONNECTION, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CONNECTION, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_CONNECTION]); @@ -2683,11 +2923,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_content_disposition() { if (!array_key_exists(self::RESPONSE_CONTENT_DISPOSITION, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CONTENT_DISPOSITION, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response content disposition', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2699,7 +2942,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_content_encoding() { if (!array_key_exists(self::RESPONSE_CONTENT_ENCODING, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CONTENT_ENCODING, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($this->response[self::RESPONSE_CONTENT_ENCODING]); @@ -2716,7 +2960,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_content_language() { if (!array_key_exists(self::RESPONSE_CONTENT_LANGUAGE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CONTENT_LANGUAGE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($this->response[self::RESPONSE_CONTENT_LANGUAGE]); @@ -2731,7 +2976,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_content_length() { if (!array_key_exists(self::RESPONSE_CONTENT_LENGTH, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CONTENT_LENGTH, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($this->response[self::RESPONSE_CONTENT_LENGTH]); @@ -2747,11 +2993,13 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_content_range() { if (!array_key_exists(self::RESPONSE_CONTENT_RANGE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CONTENT_RANGE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response content range', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2767,7 +3015,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_content_type() { if (!array_key_exists(self::RESPONSE_CONTENT_TYPE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CONTENT_TYPE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_CONTENT_TYPE]); @@ -2784,7 +3033,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_date() { if (!array_key_exists(self::RESPONSE_DATE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_DATE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } if (is_float($this->response[self::RESPONSE_DATE])) { @@ -2809,7 +3059,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_date_actual() { if (!array_key_exists(self::RESPONSE_DATE_ACTUAL, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_DATE_ACTUAL, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } if (is_float($this->response[self::RESPONSE_DATE_ACTUAL])) { @@ -2832,7 +3083,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_etag() { if (!array_key_exists(self::RESPONSE_ETAG, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_ETAG, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_ETAG]); @@ -2849,7 +3101,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_expires() { if (!array_key_exists(self::RESPONSE_EXPIRES, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_EXPIRES, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } if (is_float($this->response[self::RESPONSE_EXPIRES])) { @@ -2870,7 +3123,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_last_modified() { if (!array_key_exists(self::RESPONSE_LAST_MODIFIED, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_LAST_MODIFIED, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } if (is_float($this->response[self::RESPONSE_LAST_MODIFIED])) { @@ -2893,11 +3147,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_link() { if (!array_key_exists(self::RESPONSE_LINK, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_LINK, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response link', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2913,7 +3170,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_location() { if (!array_key_exists(self::RESPONSE_LOCATION, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_LOCATION, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($this->response[self::RESPONSE_LOCATION]); @@ -2931,11 +3189,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_pragma() { if (!array_key_exists(self::RESPONSE_PRAGMA, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_PRAGMA, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response pragma', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2951,11 +3212,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_proxy_authenticate() { if (!array_key_exists(self::RESPONSE_PROXY_AUTHENTICATE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_PROXY_AUTHENTICATE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response proxy authenticate', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2971,11 +3235,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_public_key_pins() { if (!array_key_exists(self::RESPONSE_PUBLIC_KEY_PINS, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_PUBLIC_KEY_PINS, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response public key pins', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -2994,11 +3261,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_refresh() { if (!array_key_exists(self::RESPONSE_REFRESH, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_REFRESH, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response refresh', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3015,44 +3285,48 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_retry_after() { if (!array_key_exists(self::RESPONSE_RETRY_AFTER, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_RETRY_AFTER, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_RETRY_AFTER]); } /** - * Obtain HTTP response header: server. + * Obtain HTTP response header: set-cookie. * - * @return ??|c_base_return_status + * @return c_base_cookie|c_base_return_status * FALSE with error bit set is returned on error, including when the key is not defined. * - * @see: https://tools.ietf.org/html/rfc7231#section-7.4.2 + * @see: https://tools.ietf.org/html/rfc6265 */ - public function get_response_server() { - if (!array_key_exists(self::RESPONSE_SERVER, $this->response)) { - return c_base_return_error::s_false(); + public function get_response_set_cookie() { + if (!array_key_exists(self::RESPONSE_SET_COOKIE, $this->response)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_SET_COOKIE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } - // @todo - return c_base_return_error::s_false(); + return $this->response[self::RESPONSE_SET_COOKIE]; } /** - * Obtain HTTP response header: get_cookie. - * - * @todo: cookie might needs special handling because PHP handles it in a different way from other headers. + * Obtain HTTP response header: server. * * @return ??|c_base_return_status * FALSE with error bit set is returned on error, including when the key is not defined. + * + * @see: https://tools.ietf.org/html/rfc7231#section-7.4.2 */ - public function get_response_cookie() { - if (!array_key_exists(self::RESPONSE_COOKIE, $this->response)) { - return c_base_return_error::s_false(); + public function get_response_server() { + if (!array_key_exists(self::RESPONSE_SERVER, $this->response)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_SERVER, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response server', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3066,7 +3340,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_status() { if (!array_key_exists(self::RESPONSE_STATUS, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_STATUS, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($this->response[self::RESPONSE_STATUS]); @@ -3083,11 +3358,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_strict_transport_security() { if (!array_key_exists(self::RESPONSE_STRICT_TRANSPORT_SECURITY, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_STRICT_TRANSPORT_SECURITY, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response strict transport security', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3106,11 +3384,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_trailer() { if (!array_key_exists(self::RESPONSE_TRAILER, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_TRAILER, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response trailer', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3124,11 +3405,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_transfer_encoding() { if (!array_key_exists(self::RESPONSE_TRANSFER_ENCODING, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_TRANSFER_ENCODING, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response transfer encoding', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3141,11 +3425,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_upgrade() { if (!array_key_exists(self::RESPONSE_UPGRADE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_UPGRADE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response upgrade', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3159,7 +3446,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_vary() { if (!array_key_exists(self::RESPONSE_VARY, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_VARY, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_VARY]); @@ -3176,11 +3464,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_warning() { if (!array_key_exists(self::RESPONSE_WARNING, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_WARNING, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response warning', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3194,11 +3485,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_www_authenticate() { if (!array_key_exists(self::RESPONSE_WWW_AUTHENTICATE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_WWW_AUTHENTICATE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response www authenticate', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3210,7 +3504,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_protocol() { if (!array_key_exists(self::RESPONSE_PROTOCOL, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_PROTOCOL, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($this->response[self::RESPONSE_PROTOCOL]); @@ -3225,11 +3520,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_content_security_policy() { if (!array_key_exists(self::RESPONSE_X_CONTENT_SECURITY_POLICY, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_X_CONTENT_SECURITY_POLICY, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response content security policy', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3241,11 +3539,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_x_content_type_options() { if (!array_key_exists(self::RESPONSE_X_CONTENT_TYPE_OPTIONS, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_X_CONTENT_TYPE_OPTIONS, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response content type options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3257,11 +3558,14 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_x_ua_compatible() { if (!array_key_exists(self::RESPONSE_X_UA_COMPATIBLE, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_X_UA_COMPATIBLE, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } // @todo - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':functionality_name' => 'http response ua compatible', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_SUPPORT); + return c_base_return_error::s_false($error); } /** @@ -3277,7 +3581,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_checksum_header() { if (!array_key_exists(self::RESPONSE_CHECKSUM_HEADER, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CHECKSUM_HEADER, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_CHECKSUM_HEADERS]); @@ -3292,7 +3597,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_checksum_headers() { if (!array_key_exists(self::RESPONSE_CHECKSUM_HEADERS, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CHECKSUM_HEADERS, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_CHECKSUM_HEADERS]); @@ -3311,7 +3617,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_checksum_content() { if (!array_key_exists(self::RESPONSE_CHECKSUM_CONTENT, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CHECKSUM_CONTENT, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($this->response[self::RESPONSE_CHECKSUM_CONTENT]); @@ -3326,7 +3633,8 @@ class c_base_http extends c_base_rfc_string { */ public function get_response_content_revision() { if (!array_key_exists(self::RESPONSE_CONTENT_REVISION, $this->response)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => self::RESPONSE_CONTENT_REVISION, ':array_name' => 'this->response', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($this->response[self::RESPONSE_CONTENT_REVISION]); @@ -3395,15 +3703,13 @@ class c_base_http extends c_base_rfc_string { */ public function send_response_headers($shuffle = TRUE) { if (!is_bool($shuffle)) { - return c_base_return_error::s_false(); - } - - if ($this->headers_sent) { - return c_base_return_false; + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'shuffle', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (headers_sent()) { - return c_base_return_error::s_false(); + if ($this->headers_sent || headers_sent()) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'headers_sent()', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_UNECESSARY); + return c_base_return_error::s_false($error); } $header_id_to_names = $this->p_get_header_response_mapping(TRUE); @@ -3481,9 +3787,7 @@ class c_base_http extends c_base_rfc_string { $this->p_prepare_header_response_refresh($header_output); $this->p_prepare_header_response_retry_after($header_output); $this->p_prepare_header_response_server($header_output); - - // @todo: how is cookie going to be handled? - + $this->p_prepare_header_response_set_cookie($header_output); $this->p_prepare_header_response_strict_transport_security($header_output); $this->p_prepare_header_response_trailer($header_output); $this->p_prepare_header_response_transfer_encoding($header_output); @@ -3505,7 +3809,15 @@ class c_base_http extends c_base_rfc_string { // send header output. foreach ($headers as $header_id => $header_name) { if (array_key_exists($header_id, $header_output)) { - header($header_output[$header_id]); + if (is_array($header_output[$header_id])) { + foreach ($header_output[$header_id] as $sub_header) { + header($sub_header); + } + unset($sub_header); + } + else { + header($header_output[$header_id]); + } } } unset($output); @@ -3575,11 +3887,13 @@ class c_base_http extends c_base_rfc_string { */ public function encode_response_content($compression = NULL, $max_filesize = NULL) { if (!is_null($compression) && !is_int($compression)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'compression', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($max_filesize) && !(is_int($max_filesize) && $max_filesize > 0)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'max_filesize', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $encoding = $this->p_determine_response_encoding(); @@ -3597,8 +3911,9 @@ class c_base_http extends c_base_rfc_string { unset($encoding); unset($filename); unset($content); - // @todo: provide a warning about missing files. - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $filename, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } $content .= file_get_contents($filename); @@ -3623,8 +3938,9 @@ class c_base_http extends c_base_rfc_string { unset($encoding); unset($filename); unset($content); - // @todo: provide a warning about missing files. - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $filename, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } $content_length += filesize($filename); @@ -3677,15 +3993,17 @@ class c_base_http extends c_base_rfc_string { foreach ($this->content as $filename) { if (!file_exists($filename)) { unset($filename); - // @todo: provide a warning about missing files. - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $filename, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } $opened_file = fopen($filename, 'rb'); if ($opened_file === FALSE) { unset($filename); - // @todo: provide a warning about unable to open file. - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $filename, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } fpassthru($opened_file); @@ -4717,7 +5035,7 @@ class c_base_http extends c_base_rfc_string { return; } - $parsed = pr_rfc_string_is_digit($text['ordinals'], $text['characters']); + $parsed = $this->pr_rfc_string_is_digit($text['ordinals'], $text['characters']); unset($text); if ($parsed['invalid']) { @@ -7297,6 +7615,34 @@ class c_base_http extends c_base_rfc_string { } /** + * Prepare HTTP response header: set-cookie. + * + * @param array $header_output + * The header output array to make changes to. + * + * @see: https://tools.ietf.org/html/rfc6265 + */ + private function p_prepare_header_response_set_cookie(&$header_output) { + if (!array_key_exists(self::RESPONSE_SET_COOKIE, $this->response) || !is_array($this->response[self::RESPONSE_SET_COOKIE])) { + return; + } + + $header_output[self::RESPONSE_SET_COOKIE] = array(); + foreach ($this->response[self::RESPONSE_SET_COOKIE] as $cookie) { + if (!($cookie instanceof c_base_cookie)) { + continue; + } + + $cookie_string = $cookie->get_cookie(); + if ($cookie_string instanceof c_base_return_string) { + $header_output[self::RESPONSE_SET_COOKIE][] = $cookie_string->get_value_exact(); + } + unset($cookie_string); + } + unset($cookie); + } + + /** * Prepare HTTP response header: server. * * @param array $header_output @@ -7586,8 +7932,8 @@ class c_base_http extends c_base_rfc_string { unset($algorithm); unset($use_hash); - // @todo: report file not found or other related errors. - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $filename, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } $success = hash_update_file($hash, $filename); @@ -7792,6 +8138,16 @@ class c_base_http extends c_base_rfc_string { * (optional) Determine how the content-length HTTP header is to be calculated: * - FALSE = do not calculate the content length. * - TRUE = calculate and store the content length. + * + * @return bool + * TRUE if content was encoded. + * FALSE otherwise. + * + * @see: https://github.com/adsr/php-lzo + * @see: http://www.oberhumer.com/opensource/lzo/ + * @see: http://content.gpwiki.org/index.php/LZO + * @see: https://github.com/payden/php-xz + * @see: https://github.com/choden/php-xz */ private function p_encode_content($content, $encoding, $compression = NULL, $calculate_content_length = TRUE) { if ($encoding == self::ENCODING_GZIP) { @@ -7810,6 +8166,7 @@ class c_base_http extends c_base_rfc_string { $this->response[self::RESPONSE_CONTENT_LENGTH] = strlen($this->content); } + return TRUE; } elseif ($encoding == self::ENCODING_DEFLATE) { if (is_null($compression) || $compression < -1) { @@ -7826,6 +8183,8 @@ class c_base_http extends c_base_rfc_string { if ($calculate_content_length) { $this->response[self::RESPONSE_CONTENT_LENGTH] = strlen($this->content); } + + return TRUE; } elseif ($encoding == self::ENCODING_BZIP) { if (is_null($compression) || $compression < -1) { @@ -7842,6 +8201,8 @@ class c_base_http extends c_base_rfc_string { if ($calculate_content_length) { $this->response[self::RESPONSE_CONTENT_LENGTH] = strlen($this->content); } + + return TRUE; } elseif ($encoding == self::ENCODING_LZO) { switch ($compression) { @@ -7895,9 +8256,11 @@ class c_base_http extends c_base_rfc_string { if ($calculate_content_length) { $this->response[self::RESPONSE_CONTENT_LENGTH] = strlen($this->content); } + + return TRUE; } elseif ($encoding == self::ENCODING_XZ) { - // @todo, see: https://github.com/payden/php-xz + // @fixme: php-xz module is currently not working. } elseif ($encoding == self::ENCODING_EXI) { // @todo, maybe? (cannot seem to find a php library at this time) @@ -7912,8 +8275,11 @@ class c_base_http extends c_base_rfc_string { // @todo, using ascii armor on entire body. // should be a header field containing the public key. } + + return FALSE; } } + /** * A return class whose value is represented as a generic c_base_markup_tag_return. */ diff --git a/common/base/classes/base_http_status.php b/common/base/classes/base_http_status.php index eb3e43b..01b2ac6 100644 --- a/common/base/classes/base_http_status.php +++ b/common/base/classes/base_http_status.php @@ -91,7 +91,8 @@ class c_base_http_status { */ public static function to_text($status) { if (!is_int($status)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'status', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $string = ""; diff --git a/common/base/classes/base_languages.php b/common/base/classes/base_languages.php index a5c4d3a..40495d4 100644 --- a/common/base/classes/base_languages.php +++ b/common/base/classes/base_languages.php @@ -635,7 +635,8 @@ final class c_base_language_us_only implements i_base_language { */ static function s_get_names_by_id($id) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_names)) { @@ -657,7 +658,8 @@ final class c_base_language_us_only implements i_base_language { */ static function s_get_names_by_alias($alias) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_aliases)) { @@ -679,7 +681,8 @@ final class c_base_language_us_only implements i_base_language { */ static function s_get_id_by_name($name) { if (!is_string($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($name, self::$s_ids)) { @@ -701,7 +704,8 @@ final class c_base_language_us_only implements i_base_language { */ static function s_get_id_by_alias($alias) { if (!is_string($alias)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($alias, self::$s_ids)) { @@ -723,7 +727,8 @@ final class c_base_language_us_only implements i_base_language { */ static function s_get_aliases_by_id($id) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_aliases)) { @@ -745,7 +750,8 @@ final class c_base_language_us_only implements i_base_language { */ static function s_get_aliases_by_name($name) { if (!is_string($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($name, self::$s_aliases)) { @@ -842,7 +848,8 @@ final class c_base_language_us_limited implements i_base_language { */ static function s_get_names_by_id($id) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_names)) { @@ -864,7 +871,8 @@ final class c_base_language_us_limited implements i_base_language { */ static function s_get_names_by_alias($alias) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_aliases)) { @@ -886,7 +894,8 @@ final class c_base_language_us_limited implements i_base_language { */ static function s_get_id_by_name($name) { if (!is_string($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($name, self::$s_ids)) { @@ -908,7 +917,8 @@ final class c_base_language_us_limited implements i_base_language { */ static function s_get_id_by_alias($alias) { if (!is_string($alias)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($alias, self::$s_ids)) { @@ -930,7 +940,8 @@ final class c_base_language_us_limited implements i_base_language { */ static function s_get_aliases_by_id($id) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_aliases)) { @@ -952,7 +963,8 @@ final class c_base_language_us_limited implements i_base_language { */ static function s_get_aliases_by_name($name) { if (!is_string($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($name, self::$s_aliases)) { @@ -2677,7 +2689,8 @@ final class c_base_language_us_all implements i_base_language { */ static function s_get_names_by_id($id) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_names)) { @@ -2699,7 +2712,8 @@ final class c_base_language_us_all implements i_base_language { */ static function s_get_names_by_alias($alias) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_aliases)) { @@ -2721,7 +2735,8 @@ final class c_base_language_us_all implements i_base_language { */ static function s_get_id_by_name($name) { if (!is_string($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($name, self::$s_ids)) { @@ -2743,7 +2758,8 @@ final class c_base_language_us_all implements i_base_language { */ static function s_get_id_by_alias($alias) { if (!is_string($alias)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($alias, self::$s_ids)) { @@ -2765,7 +2781,8 @@ final class c_base_language_us_all implements i_base_language { */ static function s_get_aliases_by_id($id) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($id, self::$s_aliases)) { @@ -2787,7 +2804,8 @@ final class c_base_language_us_all implements i_base_language { */ static function s_get_aliases_by_name($name) { if (!is_string($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (array_key_exists($name, self::$s_aliases)) { diff --git a/common/base/classes/base_ldap.php b/common/base/classes/base_ldap.php index 3a16fb2..04e642e 100644 --- a/common/base/classes/base_ldap.php +++ b/common/base/classes/base_ldap.php @@ -54,14 +54,16 @@ class c_base_ldap { */ public function set_name($name) { if (!is_string($name) || empty($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // sanitize the name string. $parsed = parse_url($name, PHP_URL_HOST); if ($parsed === FALSE) { unset($parsed); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'parse_url', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->name = preg_replace('/(^\s+)|(\s+$)/us', '', $parsed); @@ -92,7 +94,8 @@ class c_base_ldap { */ public function set_bind_name($name) { if (!is_null($name) && (!is_string($name) || empty($name))) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->bind_name = $name; @@ -121,7 +124,8 @@ class c_base_ldap { */ public function set_bind_password($password) { if (!is_null($password) && (!is_string($password) || empty($password))) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'password', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->bind_password = $password; @@ -152,7 +156,8 @@ class c_base_ldap { */ public function do_connect() { if (is_null($this->name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } // already prepared, just return true. @@ -163,7 +168,9 @@ class c_base_ldap { $this->ldap = ldap_connect($this->name); if (!is_resource($this->ldap)) { $this->ldap = NULL; - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_connect', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $bound = ldap_bind($this->ldap, $this->bind_name, $this->bind_password); @@ -173,7 +180,8 @@ class c_base_ldap { } unset($bound); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::FUNCTION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -199,7 +207,8 @@ class c_base_ldap { } unset($unbound); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_unbind', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -232,27 +241,33 @@ class c_base_ldap { */ public function do_search($directory_name, $filter, $attributes, $attributes_only = FALSE, $entry_limit = 0, $time_limit = 0, $dereference = LDAP_DEREF_NEVER) { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } if (!is_string($directory_name) || !is_string($filter)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'directory_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($attributes)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attributes', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($entry_limit) || $entry_limit < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'entry_limit', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($time_limit) || $time_limit < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'time_limit', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($dereference)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'dereference', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // To prevent flooding the logs, prepend @ to prevent errors from being printed as described by the PHP documentation. @@ -267,7 +282,8 @@ class c_base_ldap { } unset($found); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_search', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -300,27 +316,38 @@ class c_base_ldap { */ public function do_list($directory_name, $filter, $attributes, $attributes_only = FALSE, $entry_limit = 0, $time_limit = 0, $dereference = LDAP_DEREF_NEVER) { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } - if (!is_string($directory_name) || !is_string($filter)) { - return c_base_return_error::s_false(); + if (!is_string($directory_name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'directory_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($filter)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'filter', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($attributes)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attributes', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($entry_limit) || $entry_limit < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'entry_limit', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($time_limit) || $time_limit < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'time_limit', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($dereference)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'dereference', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // To prevent flooding the logs, prepend @ to prevent errors from being printed as described by the PHP documentation. @@ -335,7 +362,8 @@ class c_base_ldap { } unset($found); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_list', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -368,27 +396,38 @@ class c_base_ldap { */ public function do_read($directory_name, $filter, $attributes, $attributes_only = FALSE, $entry_limit = 0, $time_limit = 0, $dereference = LDAP_DEREF_NEVER) { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } - if (!is_string($directory_name) || !is_string($filter)) { - return c_base_return_error::s_false(); + if (!is_string($directory_name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'directory_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($filter)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'filter', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($attributes)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attributes', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($entry_limit) || $entry_limit < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'entry_limit', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($time_limit) || $time_limit < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'time_limit', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($dereference)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'dereference', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // To prevent flooding the logs, prepend @ to prevent errors from being printed as described by the PHP documentation. @@ -403,7 +442,8 @@ class c_base_ldap { } unset($found); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_read', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } /** @@ -425,17 +465,31 @@ class c_base_ldap { */ public function do_compare($directory_name, $attribute, $value) { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); + } + + if (!is_string($directory_name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'directory_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($attribute)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attibute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - if (!is_string($directory_name) || !is_string($attribute) || !is_string($value)) { - return c_base_return_error::s_false(); + if (!is_string($value)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'value', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $result = ldap_compare($this->ldap, $domain, $attribute, $value); if ($result === -1) { unset($result); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_compare', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if ($result === TRUE) { @@ -457,7 +511,8 @@ class c_base_ldap { */ public function get_error_message() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new(ldap_error($this->ldap)); @@ -476,7 +531,8 @@ class c_base_ldap { */ public function get_error_number() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new(ldap_errno($this->ldap)); @@ -511,17 +567,20 @@ class c_base_ldap { */ public function get_option($option) { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } if (!is_int($option)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'option', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $value = NULL; if (ldap_get_option($this->ldap, $option, $value) === FALSE) { unset($value); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_get_option', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if ($option == LDAP_OPT_DEREF || $option == LDAP_OPT_SIZELIMIT || $option == LDAP_OPT_TIMELIMIT || $option == LDAP_OPT_NETWORK_TIMEOUT || $option == LDAP_OPT_PROTOCOL_VERSION || $option == LDAP_OPT_ERROR_NUMBER) { @@ -607,7 +666,8 @@ class c_base_ldap_result extends c_base_return_resource { */ public function set_ldap($ldap) { if (!is_resource($ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->ldap = $ldap; @@ -627,13 +687,15 @@ class c_base_ldap_result extends c_base_return_resource { */ public function get_count() { if (!is_resource($ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } $total = ldap_count_entries($this->ldap, $this->value); if ($total === FALSE) { unset($total); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_count_entries', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($total); @@ -649,13 +711,15 @@ class c_base_ldap_result extends c_base_return_resource { */ public function load_entry_first() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } $first = ldap_first_entry($this->ldap, $this->value); if ($first === FALSE) { unset($first); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_first_entry', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->entry = $first; @@ -678,7 +742,8 @@ class c_base_ldap_result extends c_base_return_resource { */ public function load_entry_next() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } // the entry is false when there are no entries remaining. @@ -688,7 +753,8 @@ class c_base_ldap_result extends c_base_return_resource { // the entry must first be loaded by self::load_entry_first(). if (!is_null($this->entry)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->entry', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $this->entry = ldap_next_entry($this->ldap, $this->value); @@ -714,13 +780,16 @@ class c_base_ldap_result extends c_base_return_resource { */ public function get_entry_all() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } $entries = ldap_get_entries($this->ldap, $this->value); if ($entries === FALSE) { unset($entries); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_get_entries', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($entries); @@ -741,17 +810,21 @@ class c_base_ldap_result extends c_base_return_resource { */ public function get_attribute_first() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } if (!is_resource($this->entry)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->entry', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $attribute = ldap_first_attribute($this->ldap, $this->entry); if ($attribute === FALSE) { unset($attribute); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_first_attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($attribute); @@ -773,17 +846,21 @@ class c_base_ldap_result extends c_base_return_resource { */ public function get_attribute_next() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } if (!is_resource($this->entry)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->entry', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $attribute = ldap_next_attribute($this->ldap, $this->entry); if ($attribute === FALSE) { unset($attribute); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_next_attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($attribute); @@ -805,17 +882,21 @@ class c_base_ldap_result extends c_base_return_resource { */ public function get_attribute_all() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } if (!is_resource($this->entry)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->entry', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $attributes = ldap_get_attributes($this->ldap, $this->entry); if ($attributes === FALSE) { unset($attributes); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_get_attributes', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($attributes); @@ -837,17 +918,21 @@ class c_base_ldap_result extends c_base_return_resource { */ public function get_directory_name() { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } if (!is_resource($this->entry)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->entry', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $directory_name = ldap_get_dn($this->ldap, $this->entry); if ($directory_name === FALSE) { unset($directory_name); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_get_dn', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($directory_name); @@ -869,15 +954,23 @@ class c_base_ldap_result extends c_base_return_resource { */ public function get_values($attribute, $binary = FALSE) { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } if (!is_resource($this->entry)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->entry', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if (!is_string($attribute)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_bool($binary)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'binary', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($binary) { @@ -889,7 +982,9 @@ class c_base_ldap_result extends c_base_return_resource { if (!is_array($values)) { unset($values); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => ($binary ? 'ldap_get_values_len' : 'ldap_get_values'), ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($values); @@ -905,17 +1000,21 @@ class c_base_ldap_result extends c_base_return_resource { */ public function do_sort($attribute) { if (!is_resource($this->ldap)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':resource_name' => 'this->ldap', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NO_CONNECTION); + return c_base_return_error::s_false($error); } if (!is_string($attribute)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $status = ldap_sort($this->ldap, $this->value, $attribute); if ($status === FALSE) { unset($status); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_sort', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($status); @@ -927,7 +1026,7 @@ class c_base_ldap_result extends c_base_return_resource { * * @return c_base_return_status * TRUE is returned on success, FALSE is returned if nothing to free. - * FALSE with the error flag set is returned on error. + * FALSE with the error bit set is returned on error. * * @see: ldap_free_result() */ @@ -940,6 +1039,7 @@ class c_base_ldap_result extends c_base_return_resource { return new c_base_return_true(); } - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'ldap_free_result', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } } diff --git a/common/base/classes/base_log.php b/common/base/classes/base_log.php index a1140a7..6be9bb4 100644 --- a/common/base/classes/base_log.php +++ b/common/base/classes/base_log.php @@ -99,7 +99,8 @@ class c_base_log { */ public function set_type($type) { if (!is_int($type) || $type < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->type = $type; @@ -148,17 +149,21 @@ class c_base_log { */ public function get_data_jsonized($options = 0, $depth = 512) { if (!is_int($options)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'options', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($depth) || $depth < 1) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'depth', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $encoded = json_encode($this->data, $options, $depth) if ($encoded === FALSE) { unset($encoded); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'json_encode', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($encoded); @@ -179,11 +184,13 @@ class c_base_log { protected function pr_set_data($key, $value) { if (is_int($key)) { if ($key < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'key', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } elseif (!is_string($key)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'value', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->data[$key] = $value; @@ -204,15 +211,18 @@ class c_base_log { protected function pr_get_data($key) { if (is_int($key)) { if ($key < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'key', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } } elseif (!is_string($key)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'key', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!array_key_exists($key, $this->data)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':index_name' => $key, ':array_name' => 'this->data', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_ARRAY_INDEX); + return c_base_return_error::s_false($error); } return c_base_return_value::s_new($this->data[$key]); diff --git a/common/base/classes/base_markup.php b/common/base/classes/base_markup.php index 974db9a..0601c28 100644 --- a/common/base/classes/base_markup.php +++ b/common/base/classes/base_markup.php @@ -550,7 +550,8 @@ class c_base_markup_tag { * @param $value * The value of the attribute. * The actual value type is specific to each attribute type. - * May be set to NULL to unassign/remove any given attribute. + * Set to NULL to unassign/remove any given attribute. + * Set to c_base_markup_attributes::ATTRIBUTE_NONE to remove all attribute values. * * @return c_base_return_status * TRUE on success, FALSE otherwise. @@ -558,7 +559,8 @@ class c_base_markup_tag { */ public function set_attribute($attribute, $value) { if (!is_int($attribute)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($value)) { @@ -568,6 +570,9 @@ class c_base_markup_tag { switch ($attribute) { case c_base_markup_attributes::ATTRIBUTE_NONE: + // when attribute none is specified, the entire attributes array is to be reset. + unset($this->attributes); + $this->attributes = array(); return new c_base_return_true(); case c_base_markup_attributes::ATTRIBUTE_ABBR: @@ -965,7 +970,8 @@ class c_base_markup_tag { */ public function get_attribute($attribute) { if (!is_int($attribute)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'attribute', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!isset($this->attributes) && !is_array($this->attributes)) { @@ -975,8 +981,9 @@ class c_base_markup_tag { if (array_key_exists($attribute, $this->attributes)) { switch ($attribute) { case c_base_markup_attributes::ATTRIBUTE_NONE: - // should not be possible, so consider this an error (attributes set to NONE are actually unset from the array). - return c_base_return_error::s_false(); + // should not be possible, so consider this an error (when attribute is set to NONE, the entire attributes array is unset). + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); case c_base_markup_attributes::ATTRIBUTE_ABBR: case c_base_markup_attributes::ATTRIBUTE_ACCESS_KEY: @@ -1337,11 +1344,13 @@ class c_base_markup_tag { */ public function set_tag($tag, $index = NULL) { if (!($tag instanceof c_base_markup_tag)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'tag', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($index) && (!is_int($index) && $index < 0)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'index', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($this->tags)) { @@ -1373,7 +1382,8 @@ class c_base_markup_tag { */ public function unset_tag($index) { if (!is_null($index) && (!is_int($index) && $index < 0)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'index', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($this->tags)) { @@ -1414,7 +1424,8 @@ class c_base_markup_tag { */ public function get_tag($index) { if (!is_int($index) && $index < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'index', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!array_key_exists($index, $this->tags)) { @@ -1453,7 +1464,8 @@ class c_base_markup_tag { */ public function set_text($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->text = $text; @@ -1489,7 +1501,8 @@ class c_base_markup_tag { */ public function set_type($type) { if (!is_int($type)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } switch ($type) { diff --git a/common/base/classes/base_mime.php b/common/base/classes/base_mime.php index 3a54ad4..e9971ac 100644 --- a/common/base/classes/base_mime.php +++ b/common/base/classes/base_mime.php @@ -164,7 +164,8 @@ class c_base_mime { */ static function s_get_names_by_id($id, $category = NULL) { if (!is_int($id) && !is_numeric($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($category)) { @@ -200,7 +201,8 @@ class c_base_mime { } else { if (!is_int($category)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'category', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($category == self::CATEGORY_PROVIDED) { @@ -270,11 +272,13 @@ class c_base_mime { */ static function s_identify($mime, $lowercase = FALSE) { if (!is_string($mime)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'mime', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($lowercase)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'lowercase', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($lowercase) { diff --git a/common/base/classes/base_return.php b/common/base/classes/base_return.php index 5c4e6b2..b2997ea 100644 --- a/common/base/classes/base_return.php +++ b/common/base/classes/base_return.php @@ -246,20 +246,20 @@ trait t_base_return_message { * @require class c_base_error */ class c_base_return { - private $error; + private $errors; /** * Class constructor. */ public function __construct() { - $this->error = NULL; + $this->errors = array(); } /** * Class destructor. */ public function __destruct() { - unset($this->error); + unset($this->errors); } /** @@ -279,32 +279,69 @@ class c_base_return { * * @param null|c_base_error $error * The error code class defining what the error is. - * Setting this to NULL will clear the error flag. + * Setting this to NULL will clear all errors. + * @param null|int $delta + * (optional) When an integer, the error is assigned an explicit position in the errors array. + * When NULL, the error is appended to the errors array. * * @return bool * TRUE on success, FALSE otherwise. */ - public function set_error($error) { + public function set_error($error, $delta = NULL) { if (!is_null($error) && !($error instanceof c_base_error)) { return FALSE; } - $this->error = $error; + if (is_null($error)) { + $this->errors = array(); + return TRUE; + } + + if (!is_array($this->errors)) { + $this->errors = array(); + } + + if (is_null($delta)) { + $this->errors[] = $error; + } + elseif (is_int($delta) && $delta >= 0) { + $this->errors[$delta] = $error; + } + else { + return FALSE; + } + return TRUE; } /** * Return the error code. * - * @return null|c_base_error - * @todo: finish this once c_base_error is implemented. + * @param null|int $delta + * (optional) When an integer, the error assigned at the specified position in the errors array is returned. + * When NULL, the entire array of errors is retuned. + * + * @return null|array|c_base_error + * When $delta is an integer, an error object is returned. + * An array of errors are returned when $delta is NULL. + * NULL is returned when there is no error or there is no error at the specified delta. */ - public function get_error() { - if (!($this->error instanceof c_base_error)) { - $this->error = NULL; + public function get_error($delta = NULL) { + if (!is_array($this->errors)) { + $this->errors = array(); + } + + if (is_null($delta)) { + return $this->errors; } - return $this->error; + if (array_key_exists($delta, $this->errors)) { + if ($this->errors[$delta] instanceof c_base_error) { + return $this->errors[$delta]; + } + } + + return NULL; } /** @@ -312,14 +349,22 @@ class c_base_return { * * This is similar to get_error(), but should instead be used to to check to see if there is an error and not check what the error is set to. * + * @param null|int $delta + * (optional) When an integer, the error assigned at the specified position in the errors array is checked. + * When NULL, the entire errors array is checked for any error. + * * @return bool - * TRUE if an error is assigned and FALSE if no error is assigned. + * TRUE if any error is assigned and FALSE if no errors are assigned. * * @see: get_error() */ - public function has_error() { + public function has_error($delta = NULL) { + if (is_int($delta) && array_key_exists($delta, $this->errors)) { + return ($this->errors[$delta]) instanceof c_base_error; + } + // when there is no error flag assigned, its value should be NULL so a simple existence check should be all that is needed. - return $this->error instanceof c_base_error; + return !empty($this->errors); } /** @@ -1313,8 +1358,10 @@ class c_base_return_error { /** * Creates a return boolean TRUE with the error value populated. * - * @param c_base_error|null $error + * @param c_base_error|array|null $error * (optional) a custom error. + * Can be an array of c_base_error for returning multiple errors. + * When NULL, no errors are defined. * * @return c_base_return_true * A c_base_return_true object with the error value populated. @@ -1327,6 +1374,13 @@ class c_base_return_error { $object_return->set_error($object_error); unset($object_error); } + 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); } @@ -1337,8 +1391,10 @@ class c_base_return_error { /** * Creates a return boolean TRUE with the error value populated. * - * @param c_base_error|null $error + * @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_true object with the error value populated. @@ -1351,6 +1407,13 @@ class c_base_return_error { $object_return->set_error($object_error); unset($object_error); } + 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); } @@ -1367,6 +1430,8 @@ class c_base_return_error { * A custom class name. * @param c_base_error|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|c_base_return_value * A c_base_return_value object is returned with the error value populated @@ -1384,6 +1449,13 @@ class c_base_return_error { $object_return->set_error($object_error); unset($object_error); } + 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); } diff --git a/common/base/classes/base_rfc_string.php b/common/base/classes/base_rfc_string.php index 61adedf..c65fdb7 100644 --- a/common/base/classes/base_rfc_string.php +++ b/common/base/classes/base_rfc_string.php @@ -80,7 +80,7 @@ abstract class c_base_rfc_string extends c_base_rfc_char { unset($ordinals); $characters = c_base_utf8::s_ordinals_to_string_array($result['ordinals']); - if ($characters instanceof c_base_return_error) { + if ($characters instanceof c_base_return_false) { unset($characters); $result['invalid'] = TRUE; return $result; @@ -117,7 +117,7 @@ abstract class c_base_rfc_string extends c_base_rfc_char { ); $ordinals = c_base_utf8::s_string_to_ordinals($text); - if ($ordinals instanceof c_base_return_error) { + if ($ordinals instanceof c_base_return_false) { unset($ordinals); $result['invalid'] = TRUE; return $result; @@ -190,6 +190,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { $comment_last = FALSE; $quote_closed = FALSE; for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if ($code == c_base_ascii::SLASH_BACKWARD) { @@ -341,6 +347,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if ($code == c_base_ascii::QUOTE_DOUBLE) { @@ -495,6 +507,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_digit($code)) { @@ -550,6 +568,13 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_tchar($code)) { @@ -605,6 +630,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_tchar68($code)) { @@ -664,6 +695,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { $not_quoted = FALSE; for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if ($code == c_base_ascii::QUOTE_DOUBLE) { @@ -755,6 +792,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_digit($code)) { @@ -812,6 +855,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_digit($code)) { @@ -870,6 +919,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_vchar($code) && !$this->pr_rfc_char_is_wsp($code)) { @@ -924,6 +979,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_text($code)) { @@ -978,6 +1039,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_atext($code)) { @@ -1032,6 +1099,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_dtext($code)) { @@ -1086,6 +1159,12 @@ abstract class c_base_rfc_string extends c_base_rfc_char { } for (; $result['current'] < $stop; $result['current']++) { + if (!array_key_exists($result['current'], $ordinals) || !array_key_exists($result['current'], $characters)) { + // @fixme: should error be reported? do some debugging with this. + $result['invalid'] = TRUE; + break; + } + $code = $ordinals[$result['current']]; if (!$this->pr_rfc_char_is_qtext($code)) { diff --git a/common/base/classes/base_session.php b/common/base/classes/base_session.php index d3d71fa..6d5c9e9 100644 --- a/common/base/classes/base_session.php +++ b/common/base/classes/base_session.php @@ -105,7 +105,8 @@ class c_base_session { */ public function set_system_name($system_name) { if (!is_string($system_name) || empty($system_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'system_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->system_name = basename($system_name); @@ -135,11 +136,13 @@ class c_base_session { */ public function set_name($name) { if (!is_string($name) || empty($name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (mb_strlen($name) == 0 || preg_match('/^(\w|-)+$/i', $name) != 1) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':format_name' => 'name', ':expected_format' => '. Alphanumeric and dash characters only', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_FORMAT); + return c_base_return_error::s_false($error); } $this->name = $name; @@ -168,7 +171,8 @@ class c_base_session { */ public function set_id_user($id_user) { if ((is_int($id_user) && $id_user < 0) || !is_int($id_user) && (!is_string($id_user) || !(is_numeric($id_user) && (int) $id_user >= 0))) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id_user', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->id_user = (int) $id_user; @@ -196,11 +200,13 @@ class c_base_session { */ public function set_host($host) { if (!is_string($host) || empty($host)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'host', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (mb_strlen($host) == 0 || ip2long($host) === FALSE) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'host', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->host = $host; @@ -234,7 +240,8 @@ class c_base_session { */ public function set_password($password) { if (!is_null($password) && (!is_string($password) || empty($password))) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'password', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_null($password)) { @@ -244,7 +251,8 @@ class c_base_session { // deny 0-length passwords. if (mb_strlen($password) == 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'password', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->password = $password; @@ -274,7 +282,8 @@ class c_base_session { */ public function set_settings($settings) { if (!is_array($settings)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->settings = $settings; @@ -322,12 +331,14 @@ class c_base_session { */ public function set_session_id($session_id) { if (!is_string($session_id) || empty($session_id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'session_id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // deny 0-length session_id. if (mb_strlen($session_id) == 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'session_id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->session_id = $session_id; @@ -357,7 +368,8 @@ class c_base_session { */ public function set_timeout_expire($timeout_expire) { if (!is_int($timeout_expire)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'timeout_expire', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->timeout_expire = $timeout_expire; @@ -387,7 +399,8 @@ class c_base_session { */ public function set_timeout_max($timeout_max) { if (!is_int($timeout_max)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'timeout_max', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->timeout_max = $timeout_max; @@ -422,15 +435,18 @@ class c_base_session { */ public function set_socket_timeout($seconds, $microseconds = 0, $receive = TRUE) { if (!is_int($seconds) || $seconds < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'seconds', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($microseconds) || $microseconds < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'microseconds', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($receive)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'receive', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_array($this->socket_timeout)) { @@ -503,7 +519,8 @@ class c_base_session { */ public function get_error_socket() { if (!is_resource($this->socket)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->socket', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new(@socket_last_error($this->socket)); @@ -520,7 +537,8 @@ class c_base_session { */ public function clear_error_socket() { if (!is_resource($this->socket)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->socket', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } @socket_clear_error($this->socket); @@ -541,22 +559,31 @@ class c_base_session { * @see: c_base_session::do_disconnect() */ function do_connect() { - if (is_resource($this->socket) || is_null($this->system_name)) { - return c_base_return_error::s_false(); + if (is_resource($this->socket)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->socket', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); + } + + if (is_null($this->system_name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->system_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $this->socket = socket_create(AF_UNIX, SOCK_STREAM, 0); if ($this->socket === FALSE) { $this->do_disconnect(); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'socket_create', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $connected = @socket_connect($this->socket, $this->socket_path, 0); if ($connected === FALSE) { unset($connected); - $this->do_disconnect(); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'socket_connect', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($connected); @@ -581,7 +608,8 @@ class c_base_session { */ public function do_disconnect() { if (!is_resource($this->socket)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->socket', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } @socket_close($this->socket); @@ -617,12 +645,19 @@ class c_base_session { * @see: c_base_session::p_transfer() */ public function do_pull() { - if (is_null($this->host) || is_null($this->session_id)) { - return c_base_return_error::s_false(); + if (is_null($this->host)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->host', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); + } + + if (is_null($this->session_id)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->session_id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if (!is_resource($this->socket) || @socket_last_error($this->socket) != 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->socket', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $response = $this->p_transfer(array('ip' => $this->host, 'session_id' => $this->session_id)); @@ -634,7 +669,8 @@ class c_base_session { if (empty($response['result']) || !is_array($response['result'])) { unset($response); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_transfer', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->name = NULL; @@ -696,20 +732,39 @@ class c_base_session { * @see: c_base_session::p_transfer() */ public function do_push($interval_expire = NULL, $interval_max = NULL) { - if (is_null($this->name) || is_null($this->id_user) || is_null($this->host) || is_null($this->password)) { - return c_base_return_error::s_false(); + if (is_null($this->name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); + } + + if (is_null($this->id_user)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->id_user', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); + } + + if (is_null($this->host)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->host', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); + } + + if (is_null($this->password)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->password', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if (!is_resource($this->socket) || @socket_last_error($this->socket) != 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->socket', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if (!is_null($interval_expire) && (!is_int($interval_expire) || $interval_expire < 1)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'interval_expires', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($interval_max) && (!is_int($interval_max) || $interval_max < 1)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'interval_max', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // settings is allowed to be undefined, so send it as an empty array. @@ -719,14 +774,15 @@ class c_base_session { $response = $this->p_transfer(array('name' => $this->name, 'id_user' => $this->id_user, 'ip' => $this->host, 'password' => $this->password, 'expire' => $interval_expire, 'max' => $interval_max, 'settings' => $this->settings)); if (c_base_return::s_has_error($response)) { - return c_base_return_error::s_false(); + return c_base_return_error::s_false($response->get_error(0)); } $response = c_base_return_array::s_value_exact($response); if (empty($response['result']) || !is_array($response['result'])) { unset($response); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_transfer', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $this->session_id = NULL; @@ -763,24 +819,32 @@ class c_base_session { * @see: self::p_transfer() */ public function do_terminate() { - if (is_null($this->host) || is_null($this->session_id)) { - return c_base_return_error::s_false(); + if (is_null($this->host)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->host', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); + } + + if (is_null($this->session_id)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->session_id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if (!is_resource($this->socket) || @socket_last_error($this->socket) != 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->socket', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $response = $this->p_transfer(array('ip' => $this->host, 'session_id' => $this->session_id, 'close' => TRUE)); if (c_base_return::s_has_error($response)) { - return $response->get_error(); + return c_base_return_error::s_false($response->get_error(0)); } $response = c_base_return_array::s_value_exact($response); if (empty($response['result']) || !is_array($response['result'])) { unset($response); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_transfer', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } if (!is_null($this->password)) { @@ -812,7 +876,8 @@ class c_base_session { */ public function do_flush() { if (!is_resource($this->socket) || @socket_last_error($this->socket) != 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->socket', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $response = $this->p_transfer(array('flush' => TRUE)); @@ -824,7 +889,8 @@ class c_base_session { if (empty($response['result']) || !is_array($response['result'])) { unset($response); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_transfer', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($response); @@ -849,21 +915,23 @@ class c_base_session { $json = json_encode($request); - $written = socket_write($this->socket, $json); + $written = @socket_write($this->socket, $json); unset($json); if ($written === FALSE || $written == 0) { unset($written); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'socket_write', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($written); - $json = socket_read($this->socket, self::PACKET_MAX_LENGTH); + $json = @socket_read($this->socket, self::PACKET_MAX_LENGTH); if (!is_string($json) || mb_strlen($json) == 0) { unset($json); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'socket_read', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $response = json_decode($json, TRUE); @@ -874,7 +942,8 @@ class c_base_session { } if ($response === FALSE) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'json_decode', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($response); diff --git a/common/base/classes/base_utf8.php b/common/base/classes/base_utf8.php index fff5ca0..16e630e 100644 --- a/common/base/classes/base_utf8.php +++ b/common/base/classes/base_utf8.php @@ -77,7 +77,8 @@ class c_base_utf8 { */ public static function s_is_UTF_8($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (mb_check_encoding($text, self::UTF_8)) { @@ -100,13 +101,16 @@ class c_base_utf8 { */ public static function s_character_to_ordinal($character) { if (!is_string($character)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'character', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $ordinal = self::p_s_character_to_ordinal($character); if ($ordinal === FALSE) { unset($ordinal); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_character_to_ordinal', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($ordinal); @@ -124,7 +128,8 @@ class c_base_utf8 { */ public static function s_ordinal_to_character($ordinal) { if (!is_int($ordinal)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ordinal', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new(self::p_s_ordinal_to_character($ordinal)); @@ -146,13 +151,16 @@ class c_base_utf8 { */ public static function s_length_string($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $length = self::p_s_length_string($text); if ($length === FALSE) { unset($length); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_length_string', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($length); @@ -173,17 +181,21 @@ class c_base_utf8 { */ public static function s_clean($text, $remove_bom = FALSE) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($remove_bom)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'remove_bom', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $sanitized = self::p_s_clean($text); if ($sanitized === FALSE) { unset($sanitized); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_clean', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($sanitized); @@ -203,17 +215,21 @@ class c_base_utf8 { */ public static function s_split($text, $split_length = 1) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($split_length)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'split_length', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $split = self::p_s_split($text, $split_length); if ($split === FALSE) { unset($split); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_split', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($split); @@ -231,13 +247,16 @@ class c_base_utf8 { */ public static function s_character_size_list($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $size_list = self::p_s_character_size_list($text); if ($size_list === FALSE) { unset($size_list); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_character_size_list', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new($size_list); @@ -257,13 +276,16 @@ class c_base_utf8 { */ public static function s_character_max_width($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $size_list = self::p_s_character_size_list($text); if ($size_list === FALSE) { unset($size_list); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_character_size_list', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new(max($size_list)); @@ -283,13 +305,16 @@ class c_base_utf8 { */ public static function s_encode_html_character($character) { if (!is_string($character)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'character', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $encoded = self::p_s_encode_html_character($character); if ($encoded === FALSE) { unset($encoded); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_encode_html_character', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new($encoded); @@ -307,13 +332,16 @@ class c_base_utf8 { */ public static function s_encode_html($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $split = self::p_s_split($text); if ($split === FALSE) { unset($split); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_split', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $new_array = array(); @@ -349,15 +377,18 @@ class c_base_utf8 { */ public static function s_substring($text, $start = 0, $length = NULL) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($start)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'start', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($length) && !is_int($length)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'length', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new(self::p_s_substring($text, $start, $length)); @@ -376,7 +407,8 @@ class c_base_utf8 { */ public static function s_is_bom($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (self::p_s_is_bom($text)) { @@ -397,11 +429,13 @@ class c_base_utf8 { */ public static function s_file_has_bom($file_path) { if (!is_string($file_path)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'file_path', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!file_exists($file_path)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':file_name' => $file_path, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_FILE); + return c_base_return_error::s_false($error); } if (self::p_s_is_bom(file_get_contents($file_path, 0, NULL, -1, 3))) { @@ -422,7 +456,8 @@ class c_base_utf8 { */ public static function s_string_has_bom($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (self::p_s_is_bom(substr($text, 0, 3))) { @@ -446,7 +481,8 @@ class c_base_utf8 { */ public static function s_prepend_bom($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!s_is_bom(substr($text, 0, 3))) { @@ -468,13 +504,16 @@ class c_base_utf8 { */ public static function s_reverse($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $split = self::p_s_split($text); if ($split === FALSE) { unset($split); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_split', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new(implode(array_reverse($split))); @@ -502,15 +541,18 @@ class c_base_utf8 { */ public static function s_position_string($haystack, $needle, $offset = 0) { if (!is_string($haystack)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'haystack', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($needle) && !is_string($needle)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'needle', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($offset) || $offset < 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'offset', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $search_for = $needle; @@ -536,7 +578,8 @@ class c_base_utf8 { */ public static function s_string_to_ordinals($text) { if (!is_string($text) && !is_array($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return c_base_return_array::s_new(self::p_s_string_to_ordinals($text)); @@ -549,19 +592,22 @@ class c_base_utf8 { * An array of Unicode code points. * * @return c_base_return_string|c_base_return_status - * A string represnting the ordinals array. + * A string representing the ordinals array. + * A string representing the ordinals array with error bit set is returned on error for non-critical string-processing errors. * FALSE with error bit set is returned on error. */ public static function s_ordinals_to_string($ordinals) { if (!is_array($ordinals)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ordinals', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } + $errors = array(); $string = ''; foreach ($ordinals as $ordinal) { $character = self::p_s_ordinal_to_character($ordinal); if ($character === FALSE) { - // @todo: generate a warning or error of some sort. + $errors[] = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_s_ordinal_to_character', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); continue; } @@ -570,7 +616,20 @@ class c_base_utf8 { unset($ordinal); unset($character); - return c_base_return_string::s_new($string); + if (empty($errors)) { + unset($errors); + + return c_base_return_string::s_new($string); + } + + $return_string = c_base_return_string::s_new($string); + foreach ($errors as $error) { + $return_string->set_error($error); + } + unset($errors); + unset($error); + + return $return_string; } /** @@ -585,14 +644,16 @@ class c_base_utf8 { */ public static function s_ordinals_to_string_array($ordinals) { if (!is_array($ordinals)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ordinals', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } + $errors = array(); $array = array(); foreach ($ordinals as $ordinal) { $character = self::p_s_ordinal_to_character($ordinal); if ($character === FALSE) { - // @todo: generate a warning or error of some sort. + $errors[] = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'this->p_s_ordinal_to_character', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); continue; } @@ -601,7 +662,20 @@ class c_base_utf8 { unset($ordinal); unset($character); - return c_base_return_array::s_new($array); + if (empty($errors)) { + unset($errors); + + return c_base_return_array::s_new($array); + } + + $return_array = c_base_return_array::s_new($array); + foreach ($errors as $error) { + $return_array->set_error($error); + } + unset($errors); + unset($error); + + return $return_array; } /** @@ -616,7 +690,8 @@ class c_base_utf8 { */ public static function s_ordinal_array_to_string($ordinals) { if (!is_array($ordinals)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ordinals', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $array = array(); @@ -641,13 +716,16 @@ class c_base_utf8 { */ public static function s_ordinal_to_codepoint($ordinal) { if (!is_int($ordinal)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ordinal', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $codepoint = self::p_s_ordinal_to_codepoint($ordinal); if ($codepoint === FALSE) { unset($codepoint); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_orginal_to_codepoint', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_int::s_new($codepoint); @@ -671,19 +749,23 @@ class c_base_utf8 { */ public static function s_count_substrings($haystack, $needle, $offset = 0, $length = NULL) { if (!is_string($haystack)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'haystack', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_string($needle)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'needle', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($offset)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'offset', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($length) && !is_int($length)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'length', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($offset || $length) { @@ -709,7 +791,8 @@ class c_base_utf8 { */ public static function s_is_ascii($text) { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (preg_match('/[\x80-\xff]/', $text)) { @@ -733,18 +816,22 @@ class c_base_utf8 { */ public static function s_strip_tags($text, $allowable_tags = '') { if (!is_string($text)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_string($allowable_tags)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'allowable_tags', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } // clean broken UTF_8. $sanitized = self::p_s_clean($text); if ($sanitized === FALSE) { unset($sanitized); - return c_base_return_error::s_false(); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'self::p_s_clean', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } return c_base_return_string::s_new(strip_tags($sanitized, $allowable_tags)); diff --git a/common/theme/classes/theme_dom.php b/common/theme/classes/theme_dom.php index 14b2a4f..129713b 100644 --- a/common/theme/classes/theme_dom.php +++ b/common/theme/classes/theme_dom.php @@ -61,11 +61,13 @@ class c_theme_dom extends DOMDocument { */ public function change_element($element, $type) { if (!($element instanceof DOMNode)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'element', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_string($type) || empty($type)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } return c_them_return_dom_node::s_new($this->pr_change_element($element, $type)); @@ -88,15 +90,18 @@ class c_theme_dom extends DOMDocument { */ public function change_elements($type_old, $type_new) { if (!is_string($type_old) || strlen($type_old) == 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type_old', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_string($type_new) || strlen($type_empty) == 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type_empty', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!($this->content instanceof DOMNode)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->content', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } return $this->pr_change_elements($type_old, $type_new, $this->content); @@ -124,11 +129,13 @@ class c_theme_dom extends DOMDocument { */ public function remove_element($element, $preserve_children = TRUE) { if (!($element instanceof DOMNode)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'element', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($preserve_children)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'preserve_children', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if ($this->pr_remove_element($element, $preserve_children)) { @@ -160,15 +167,18 @@ class c_theme_dom extends DOMDocument { */ public function remove_elements($type, $preserve_children = TRUE) { if (!is_string($type) || strlen($type) == 0) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_bool($preserve_children)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'preserve_children', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!($this->content instanceof DOMNode)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->content', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } if ($this->pr_remove_elements($type, $this->content, $preserve_children)) { diff --git a/common/theme/classes/theme_html.php b/common/theme/classes/theme_html.php index 932ac43..49140f4 100644 --- a/common/theme/classes/theme_html.php +++ b/common/theme/classes/theme_html.php @@ -68,22 +68,26 @@ class c_theme_html { */ public static function s_create_tag($type, $id = NULL, $classes = NULL) { if (!is_null($id) && !is_string($id)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_int($type)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($classes) && !is_array($classes)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'classes', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $tag = new c_base_markup_tag(); $result = $tag->set_type($type); if ($result instanceof c_base_return_false) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'type', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (is_string($id)) { @@ -122,7 +126,8 @@ class c_theme_html { */ public function set_html($html) { if (!($html instanceof c_base_html)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'html', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->html = $html; @@ -170,7 +175,8 @@ class c_theme_html { */ public function render_markup() { if (!($this->html instanceof c_base_html)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':variable_name' => 'this->html', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_false($error); } $this->markup = 'p_render_markup_attributes_global() . $this->p_render_markup_attributes_event_handler() . '>'; @@ -193,7 +199,8 @@ class c_theme_html { */ public function set_http($http) { if (!($http instanceof c_base_http)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'http', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->http = $http; @@ -228,7 +235,8 @@ class c_theme_html { */ public function set_max_recursion_depth($max_recursion_depth) { if (!is_int($max_recursion_depth)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'max_recursion_depth', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $this->max_recursion_depth = $max_recursion_depth; diff --git a/documentation/requirements.txt b/documentation/requirements.txt index 914f475..b0773df 100644 --- a/documentation/requirements.txt +++ b/documentation/requirements.txt @@ -19,6 +19,7 @@ php-lzo: - see: http://www.oberhumer.com/opensource/lzo/ - This must be added to the PHP source code during compile time. -php-xz: +php-xz: (currently not required because code is defunct.) +- see: https://github.com/payden/php-xz - see: https://github.com/chobie/php-xz - This must be added to the PHP source code during compile time. diff --git a/program/reservation/index.php b/program/reservation/index.php index 8a3f3b0..d258890 100644 --- a/program/reservation/index.php +++ b/program/reservation/index.php @@ -56,7 +56,7 @@ $settings['session_max'] = 1800; // 30 minutes // ldap information - $settings['ldap_server'] = 'ldaps://ldap.example.com:1636/'; + $settings['ldap_server'] = 'ldaps://127.0.0.1:1636/'; $settings['ldap_base_dn'] = 'ou=users,ou=People'; $settings['ldap_fields'] = array('mail', 'gecos', 'givenname', 'cn', 'sn', 'employeenumber'); @@ -81,10 +81,8 @@ * * @param c_base_http $http * Http object. - * @param c_base_cookie $cookie - * Cookie object. */ - function reservation_send_response($http, $cookie) { + function reservation_send_response($http) { $old_output_buffering = ini_get('output_buffering'); ini_set('output_buffering', 'off'); @@ -94,7 +92,6 @@ // when the headers are sent, checksums are created, so at this point all error output should be stored and not sent. $http->send_response_headers(); - $cookie->do_push(); flush(); // once the header are sent, send the content. @@ -116,10 +113,10 @@ * System settings * @param c_base_session &$session * Session information. - * @param c_base_cookie &$cookie - * Session cookie. + * @param c_base_cookie &$cookie_login + * Session login cookie. */ - function reservation_process_request(&$http, &$database, &$settings, &$session, &$cookie) { + function reservation_process_request(&$http, &$database, &$settings, &$session, &$cookie_login) { $html = new c_base_html(); @@ -242,7 +239,7 @@ elseif ($session === FALSE) { // check to see if user has filled out the login form. if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_id']) && $_POST['form_id'] == 'login_form') { - $problems = reservation_attempt_login($database, $settings, $session, $cookie); + $problems = reservation_attempt_login($database, $settings, $session, $cookie_login); if ($problems instanceof c_base_return_false) { // @todo: render default page. @@ -300,14 +297,14 @@ // 3: process session information - $cookie = new c_base_cookie(); - $session = reservation_process_sessions($settings, $cookie)->get_value_exact(); + $cookie_login = new c_base_cookie(); + $session = reservation_process_sessions($settings, $cookie_login)->get_value_exact(); gc_collect_cycles(); // 4: perform actions, process work. $database = new c_base_database(); - $html = reservation_process_request($http, $database, $settings, $session, $cookie)->get_value(); + $html = reservation_process_request($http, $database, $settings, $session, $cookie_login)->get_value(); if (!($html instanceof c_base_html)) { $html = new c_base_html(); } @@ -327,19 +324,19 @@ // 6: build response information. $http->set_response_content($markup); + $http->set_response_set_cookie($cookie_login); unset($markup); + unset($cookie_login); gc_collect_cycles(); // 7: send HTTP response. - reservation_send_response($http, $cookie); + reservation_send_response($http); gc_collect_cycles(); unset($settings); unset($http); unset($session); - unset($cookie); - unset($database); gc_collect_cycles(); } diff --git a/program/reservation/reservation_database.php b/program/reservation/reservation_database.php index 6a062a9..185fc5b 100644 --- a/program/reservation/reservation_database.php +++ b/program/reservation/reservation_database.php @@ -22,13 +22,19 @@ */ function reservation_database_string(&$database, $settings) { if (!($database instanceof c_base_database)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_array($settings)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $connection_string = new c_base_connection_string(); $connection_string->set_host($settings['database_host']); $connection_string->set_port($settings['database_port']); - $connection_string->set_dbname($settings['database_name']); + $connection_string->set_database_name($settings['database_name']); $connection_string->set_user($settings['database_user']); if (!is_null($settings['database_password'])) { @@ -56,7 +62,8 @@ */ function reservation_database_connect(&$database) { if (!($database instanceof c_base_database)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $status = $database->do_connect(); @@ -92,15 +99,18 @@ */ function reservation_database_get_user_data(&$database, $user_name, $ldap_data = NULL) { if (!($database instanceof c_base_database)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_string($user_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_null($ldap_data) && !is_array($ldap_data)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ldap_data', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $user_data = array( @@ -219,11 +229,13 @@ */ function reservation_database_load_ldap_data($settings, $user_name) { if (!is_array($settings)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_string($user_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $return_data = array( diff --git a/program/reservation/reservation_paths.php b/program/reservation/reservation_paths.php index 31eef59..db09e62 100644 --- a/program/reservation/reservation_paths.php +++ b/program/reservation/reservation_paths.php @@ -163,15 +163,15 @@ function reservation_build_login_page(&$html, $problems = NULL) { * The system settings array. * @param c_base_session &$session * The current session. - * @param c_base_cookie &$cookie - * Session cookie. + * @param c_base_cookie &$cookie_login + * Session login cookie. * * @return c_base_return_array|c_base_return_status * FALSE on success. * An array of problems on failure. * FALSE with error bit set is returned on error. */ -function reservation_attempt_login(&$database, &$settings, &$session, &$cookie) { +function reservation_attempt_login(&$database, &$settings, &$session, &$cookie_login) { $problems = array(); if (empty($_POST['login_form-username'])) { $problems[] = array( @@ -287,15 +287,15 @@ function reservation_attempt_login(&$database, &$settings, &$session, &$cookie) $session->do_disconnect(); $session_expire = $session->get_timeout_expire()->get_value_exact(); - $cookie->set_expires($session_expire); - $cookie->set_max_age(NULL); + $cookie_login->set_expires($session_expire); + $cookie_login->set_max_age(NULL); if ($result instanceof c_base_return_true) { $data = array( 'session_id' => $session->get_session_id()->get_value_exact(), 'expire' => gmdate("D, d-M-Y H:i:s T", $session_expire), // unecessary, but provided for debug purposes. ); - $cookie->set_data($data); + $cookie_login->set_data($data); } unset($result); unset($session_expire); diff --git a/program/reservation/reservation_session.php b/program/reservation/reservation_session.php index bdee85d..afc9bb6 100644 --- a/program/reservation/reservation_session.php +++ b/program/reservation/reservation_session.php @@ -17,27 +17,26 @@ * * @param array &$settings * System settings. - * @param c_base_cookie &$cookie - * Cookie setting. + * @param c_base_cookie &$cookie_login + * A login cookie object. * * @param c_base_return_status|c_base_session * Session information is returned on success. * FALSE is returned when no session is defined. * FALSE with error bit set is returned on error. */ - function reservation_process_sessions(&$settings, &$cookie) { - // cookie is used to determine whether or not the user is logged in. - $cookie->set_name($settings['cookie_name']); - $cookie->set_path($settings['cookie_path']); - $cookie->set_domain($settings['cookie_domain']); - $cookie->set_secure(TRUE); - - $pulled = $cookie->do_pull(); + function reservation_process_sessions(&$settings, &$cookie_login) { + $cookie_login->set_name($settings['cookie_name']); + $cookie_login->set_path($settings['cookie_path']); + $cookie_login->set_domain($settings['cookie_domain']); + $cookie_login->set_secure(TRUE); + + $pulled = $cookie_login->do_pull(); if ($pulled instanceof c_base_return_true) { - $cookie_data = $cookie->get_data()->get_value_exact(); + $cookie_data = $cookie_login->get_data()->get_value_exact(); - if (!($cookie->validate() instanceof c_base_return_true) || empty($cookie_data['session_id'])) { - // cookie failed validation or the cookie contains no session id. + if (!($cookie_login->validate() instanceof c_base_return_true) || empty($cookie_data['session_id'])) { + // cookie_login failed validation or the cookie contains no session id. return new c_base_return_false(); } @@ -78,8 +77,8 @@ } if ($session_expire > $cookie_data['expire']) { $cookie_data['expire'] = gmdate("D, d-M-Y H:i:s T", $session_expire); - $cookie->set_data($value); - $cookie->set_expires($session_expire); + $cookie_login->set_data($value); + $cookie_login->set_expires($session_expire); } return c_base_session_return::s_new($session); @@ -102,11 +101,13 @@ */ function reservation_ensure_user_account($settings, $user_name) { if (!is_array($settings)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } if (!is_string($user_name)) { - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); @@ -114,7 +115,8 @@ socket_close($socket); unset($socket); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'socket_create', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $connected = @socket_connect($socket, $settings['database_create_account_host'], $settings['database_create_account_port']); @@ -123,7 +125,8 @@ unset($socket); unset($connected); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'socket_connect', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } $packet_size_target = 63; @@ -153,7 +156,8 @@ unset($socket); unset($packet_size_client); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'socket_write', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } unset($written); @@ -165,7 +169,8 @@ if (!is_string($response) || strlen($response) == 0) { unset($response); - return c_base_return_error::s_false(); + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => 'socket_read', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE); + return c_base_return_error::s_false($error); } // an integer is expected to be returned by the socket.