From: Kevin Day Date: Thu, 22 Feb 2018 02:58:17 +0000 (-0600) Subject: Update: refactor the c_base_rfc_string and c_base_rfc_char into traits X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=1a8ff1037d0add2a4307a2250536f6e4354efdaa;p=koopa Update: refactor the c_base_rfc_string and c_base_rfc_char into traits These make more sense when implemented as traits. Classes that extended this and had no expectation of a return value are now extended c_base_return. All others are set to their most appropriate return type, such as c_base_return_string. --- diff --git a/common/base/classes/base_array.php b/common/base/classes/base_array.php index b3be57a..d416dc4 100644 --- a/common/base/classes/base_array.php +++ b/common/base/classes/base_array.php @@ -12,7 +12,8 @@ namespace n_koopa; require_once('common/base/classes/base_error.php'); require_once('common/base/classes/base_return.php'); -require_once('common/base/classes/base_rfc_string.php'); + +require_once('common/base/traits/base_rfc_string.php'); /** * A generic class for providing classes that support a single array value. @@ -22,9 +23,11 @@ require_once('common/base/classes/base_rfc_string.php'); * * This does not use the traits t_base_return_value_exact or t_base_return_value because this is non-confirming to those traits. * - * @require class c_base_rfc_string + * @require class c_base_return_array */ -class c_base_array extends c_base_rfc_string { +class c_base_array extends c_base_return { + use t_base_rfc_string; + protected $items; /** @@ -46,27 +49,6 @@ class c_base_array extends c_base_rfc_string { } /** - * @see: t_base_return_value::p_s_new() - */ - public static function s_new($value) { - return self::p_s_new($value, __CLASS__); - } - - /** - * @see: t_base_return_value::p_s_value() - */ - public static function s_value($return) { - return self::p_s_value($return, __CLASS__); - } - - /** - * @see: t_base_return_value_exact::p_s_value_exact() - */ - public static function s_value_exact($return) { - return self::p_s_value_exact($return, __CLASS__, ''); - } - - /** * Assign the array. * * @param array $array diff --git a/common/base/classes/base_email.php b/common/base/classes/base_email.php index a706967..bcd32b5 100644 --- a/common/base/classes/base_email.php +++ b/common/base/classes/base_email.php @@ -8,7 +8,8 @@ namespace n_koopa; require_once('common/base/classes/base_error.php'); require_once('common/base/classes/base_return.php'); require_once('common/base/classes/base_ascii.php'); -require_once('common/base/classes/base_rfc_string.php'); + +require_once('common/base/traits/base_rfc_string.php'); /** * A generic class for managing the e-mail related functionality. @@ -23,12 +24,11 @@ require_once('common/base/classes/base_rfc_string.php'); * @see: https://tools.ietf.org/html/rfc6854 * @see: https://tools.ietf.org/html/rfc7231#section-5.5.1 * - * @require class c_base_rfc_string * @require class c_base_ascii * @require class c_base_utf8 */ -class c_base_email extends c_base_rfc_string { - use t_base_return_value_exact; +class c_base_email extends c_base_return_string { + use t_base_rfc_string; const LINE_LENGTH_LIMIT_SOFT = 78; const LINE_LENGTH_LIMIT_HARD = 998; @@ -56,54 +56,6 @@ class c_base_email extends c_base_rfc_string { } /** - * Assign the value. - * - * @param DOMNode $value - * Any value so long as it is a DOMNode. - * NULL is not allowed. - * - * @return bool - * TRUE on success. - * FALSE with error bit set is returned on error. - */ - public function set_value($value) { - if (!is_string($value)) { - return FALSE; - } - - $this->value = $value; - return TRUE; - } - - /** - * Return the value. - * - * @return string|null $value - * The value array stored within this class. - */ - public function get_value() { - if (!is_string($this->value)) { - return NULL; - } - - return $this->value; - } - - /** - * Return the value of the expected type. - * - * @return DOMNode $value - * The value DOMNode stored within this class. - */ - public function get_value_exact() { - if (!is_string($this->value)) { - return ''; - } - - return $this->value; - } - - /** * Decode and check that the given e-mail address is valid. * * Validation is done according to rfc5322, rfc6854, and rfc7231. diff --git a/common/base/classes/base_http.php b/common/base/classes/base_http.php index 827ba35..718c297 100644 --- a/common/base/classes/base_http.php +++ b/common/base/classes/base_http.php @@ -8,13 +8,14 @@ namespace n_koopa; require_once('common/base/classes/base_error.php'); require_once('common/base/classes/base_return.php'); require_once('common/base/classes/base_charset.php'); -require_once('common/base/classes/base_rfc_string.php'); require_once('common/base/classes/base_utf8.php'); require_once('common/base/classes/base_languages.php'); require_once('common/base/classes/base_http_status.php'); require_once('common/base/classes/base_cookie.php'); require_once('common/base/classes/base_mime.php'); +require_once('common/base/traits/base_rfc_string.php'); + /** * A generic class for managing the HTTP protocol. * @@ -25,7 +26,9 @@ require_once('common/base/classes/base_mime.php'); * @require class base_rfc_string * @require class base_utf8 */ -class c_base_http extends c_base_rfc_string { +class c_base_http extends c_base_return { + use t_base_rfc_string; + // standard request headers const REQUEST_NONE = 0; const REQUEST_ACCEPT = 1; @@ -297,27 +300,6 @@ class c_base_http extends c_base_rfc_string { } /** - * @see: t_base_return_value::p_s_new() - */ - public static function s_new($value) { - return self::p_s_new($value, __CLASS__); - } - - /** - * @see: t_base_return_value::p_s_value() - */ - public static function s_value($return) { - return self::p_s_value($return, __CLASS__); - } - - /** - * @see: t_base_return_value_exact::p_s_value_exact() - */ - public static function s_value_exact($return) { - return self::p_s_value_exact($return, __CLASS__, ''); - } - - /** * Returns a list of HTTP headers that can be used as an HTML meta tag. * * The HTML language supports HTTP headers as HTML tags. diff --git a/common/base/classes/base_markup.php b/common/base/classes/base_markup.php index 5401954..297242f 100644 --- a/common/base/classes/base_markup.php +++ b/common/base/classes/base_markup.php @@ -9,7 +9,8 @@ require_once('common/base/classes/base_error.php'); require_once('common/base/classes/base_return.php'); require_once('common/base/classes/base_mime.php'); require_once('common/base/classes/base_charset.php'); -require_once('common/base/classes/base_rfc_string.php'); + +require_once('common/base/traits/base_rfc_string.php'); /** * A generic class for html attribute types. @@ -374,7 +375,9 @@ class c_base_markup_filters { * * @todo: add support for non-standard tag attributes, which will just be a string or NULL. */ -class c_base_markup_tag extends c_base_rfc_string { +class c_base_markup_tag extends c_base_return { + use t_base_rfc_string; + const TYPE_NONE = 0; const TYPE_A = 1; const TYPE_ABBR = 2; @@ -574,27 +577,6 @@ class c_base_markup_tag extends c_base_rfc_string { } /** - * @see: t_base_return_value::p_s_new() - */ - public static function s_new($value) { - return self::p_s_new($value, __CLASS__); - } - - /** - * @see: t_base_return_value::p_s_value() - */ - public static function s_value($return) { - return self::p_s_value($return, __CLASS__); - } - - /** - * @see: t_base_return_value_exact::p_s_value_exact() - */ - public static function s_value_exact($return) { - return self::p_s_value_exact($return, __CLASS__, ''); - } - - /** * Assign the specified tag. * * @param int $attribute diff --git a/common/base/classes/base_menu.php b/common/base/classes/base_menu.php index 51006cf..3636efc 100644 --- a/common/base/classes/base_menu.php +++ b/common/base/classes/base_menu.php @@ -7,39 +7,20 @@ namespace n_koopa; require_once('common/base/classes/base_error.php'); require_once('common/base/classes/base_return.php'); -require_once('common/base/classes/base_rfc_string.php'); require_once('common/base/classes/base_http.php'); require_once('common/base/classes/base_database.php'); require_once('common/base/classes/base_session.php'); require_once('common/base/classes/base_array.php'); +require_once('common/base/traits/base_rfc_string.php'); + /** * A generic class for managing a menu. * * This can be converted to HTML