From: Kevin Day Date: Sat, 18 Aug 2018 18:14:49 +0000 (-0500) Subject: Update: redesign c_base_return, t_base_return_value, and related to be more abstract X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=e1b4ed2528c67c8171d38777a052ec4600faeb3f;p=koopa Update: redesign c_base_return, t_base_return_value, and related to be more abstract Attempt to make the design more consistent by setting up c_base_return as an abstract. Anything that is directly calling c_base_return statics should be updated accordingly. More of the value methods have been moved to t_base_return_value. Move the related static methods to t_base_return_value as well. --- diff --git a/common/base/classes/base_file.php b/common/base/classes/base_file.php index d79a807..56339d1 100644 --- a/common/base/classes/base_file.php +++ b/common/base/classes/base_file.php @@ -14,7 +14,7 @@ require_once('common/base/classes/base_mime.php'); /** * A generic container for files. */ -class c_base_file extends c_base_return_value { +class c_base_file extends c_base_return { protected $id; protected $id_creator; protected $id_creator_session; @@ -93,27 +93,6 @@ class c_base_file extends c_base_return_value { } /** - * @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 file id. * * @param int $id diff --git a/common/base/classes/base_return.php b/common/base/classes/base_return.php index 17fcbcb..dc249b7 100644 --- a/common/base/classes/base_return.php +++ b/common/base/classes/base_return.php @@ -32,7 +32,7 @@ require_once('common/base/traits/base_return.php'); * * @require class c_base_error */ -class c_base_return { +abstract class c_base_return { private $errors; /** @@ -108,7 +108,7 @@ class c_base_return { return; } - $errors = $source->get_error()->get_value_exact(); + $errors = $source->get_error()->get_value(); if (is_array($errors)) { foreach ($errors as $error) { $destination->set_error($error); @@ -309,30 +309,11 @@ class c_base_return { } /** - * Return the value. - * - * @return null $value - * The value within this class. - */ - public function get_value() { - return NULL; - } - - /** - * Return the value of the expected type. - * - * @return NULL $value - * The value c_base_markup_tag stored within this class. - */ - public function get_value_exact() { - return NULL; - } - - /** * Determine if this class has a value assigned to it. * * @return bool - * TRUE if a value is assigned, FALSE otherwise. + * TRUE if the value is assigned to this class. + * FALSE is returned otherwise. */ public function has_value() { return FALSE; @@ -345,28 +326,42 @@ class c_base_return { * This is used as a return status for a function that does not return any expected valid values. * This class does not have any values of its own. */ -class c_base_return_status extends c_base_return { -} +abstract class c_base_return_status extends c_base_return { -/** - * A boolean return class representing a return value of TRUE. - * - * This class will not have any values. - */ -class c_base_return_true extends c_base_return_status { + /** + * Return the value. + * + * @return + * Always returns value represented by this class. + */ + public abstract function get_value(); /** - * Assign the value. + * Return the value. * - * @param $value - * This is ignored. + * @return + * Always returns value represented by this class + */ + public abstract function get_value_exact(); + + /** + * Determine if this class has a value assigned to it. * * @return bool * Always returns TRUE. */ - public function set_value($value) { + public function has_value() { return TRUE; } +} + +/** + * A boolean return class representing a return value of TRUE. + * + * This class does not actually use any values. + */ +class c_base_return_true extends c_base_return_status { + use t_base_return_value_exact; /** * Return the value. @@ -395,19 +390,7 @@ class c_base_return_true extends c_base_return_status { * This class will not have any values. */ class c_base_return_false extends c_base_return_status { - - /** - * Assign the value. - * - * @param $value - * This is ignored. - * - * @return bool - * Always returns TRUE. - */ - public function set_value($value) { - return TRUE; - } + use t_base_return_value_exact; /** * Return the value. @@ -436,24 +419,12 @@ class c_base_return_false extends c_base_return_status { * This class will not have any values. */ class c_base_return_null extends c_base_return_status { + use t_base_return_value_exact; /** * Assign the value. * - * @param $value - * This is ignored. - * - * @return bool - * Always returns TRUE. - */ - public function set_value($value) { - return TRUE; - } - - /** - * Return the value. - * - * @return $value + * @return null * Always returns NULL. */ public function get_value() { @@ -463,12 +434,22 @@ class c_base_return_null extends c_base_return_status { /** * Return the value of the expected type. * - * @return $value + * @return null $value * Always returns NULL. */ public function get_value_exact() { return NULL; } + + /** + * Determine if this class has a value assigned to it. + * + * @return bool + * Always returns TRUE. + */ + public function has_value() { + return TRUE; + } } /** @@ -504,59 +485,6 @@ class c_base_return_value extends c_base_return { public static function s_value($return) { return self::p_s_value($return, __CLASS__); } - - /** - * Assign the value. - * - * @param bool $value - * Any value so long as it is a bool. - * NULL is not allowed. - * - * @return bool - * TRUE on success, FALSE otherwise. - */ - public function set_value($value) { - $this->value = $value; - return TRUE; - } - - /** - * Return the value. - * - * @return $value - * The value bool stored within this class. - */ - public function get_value() { - if (!isset($this->value)) { - return NULL; - } - - return $this->value; - } - - /** - * Return the value of the expected type. - * - * @return $value - * The value bool stored within this class. - */ - public function get_value_exact() { - if (!isset($this->value)) { - return NULL; - } - - return $this->value; - } - - /** - * Determine if this class has a value assigned to it. - * - * @return bool - * TRUE if a value is assigned, FALSE otherwise. - */ - public function has_value() { - return !is_null($this->value); - } } /** diff --git a/common/base/traits/base_return.php b/common/base/traits/base_return.php index 332ff22..0ee0361 100644 --- a/common/base/traits/base_return.php +++ b/common/base/traits/base_return.php @@ -44,6 +44,26 @@ trait t_base_return_value { } /** + * Determine if this class has a value assigned to it. + * + * @return bool + * TRUE if the value is assigned to something other than NULL, FALSE otherwise. + */ + public function has_value() { + return !is_null($this->value); + } + + /** + * Return the value. + * + * @return $value + * The value stored within this class. + */ + public function get_value() { + return $this->value; + } + + /** * Creates a new return __class__ type. * * This is used to simplify the returning of a new class value. @@ -138,6 +158,16 @@ trait t_base_return_value_exact { //use t_base_return_value; /** + * Return the value of the expected type. + * + * @return $value + * The value stored within this class. + */ + public function get_value_exact() { + return $this->value; + } + + /** * Perform a very basic, safe, value retrieval of the expected type. * * This guarantees that a specific type is returned.