/**
* Assign the value.
*
+ * If the value is an object, then this should create a copy of the object (a clone).
+ *
* @param $value
* This can be anything that is to be considered a return value.
*
* TRUE on success, FALSE otherwise.
*/
public function set_value($value) {
- $this->value = $value;
+ if (is_object($value)) {
+ $this->value = clone($value);
+ }
+ else {
+ $this->value = $value;
+ }
+
return TRUE;
}
}
/**
+ * A trait for a return value that may be assigned an object via reference.
+ */
+trait t_base_return_reference_set {
+ /**
+ * Assign the value, using reference instead of a copy.
+ *
+ * If the value is an object, then this should contain a reference to the object.
+ *
+ * @param $value
+ * This can be anything that is to be considered a return value.
+ *
+ * @return bool
+ * TRUE on success, FALSE otherwise.
+ * FALSE is returned when $value is not an object.
+ */
+ public function set_value_reference($value) {
+ if (is_object($value)) {
+ $this->value = $value;
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+}
+
+/**
+ * A trait for a return value that may return an object via reference.
+ */
+trait t_base_return_reference_get {
+
+ /**
+ * Return the value, by reference.
+ *
+ * @return null|object $value
+ * A reference to the value within this class.
+ * NULL is returned if no reference can be returned.
+ */
+ public function get_value_reference() {
+ if (is_object($this->value)) {
+ return $this->value;
+ }
+
+ return NULL;
+ }
+}
+
+/**
+ * A trait for a return value that may return an object via reference of the expected type.
+ */
+trait t_base_return_reference_get_exact {
+
+ /**
+ * Return the value, by reference, of the expected type.
+ *
+ * @return object $value
+ * A reference to the value within this class.
+ * A new object is created and returned if a reference would otherwise be unreturnable.
+ */
+ public abstract function get_value_reference_exact();
+}
+
+/**
* A generic class for managing return values.
*
* This is the base template class used for specific return classes.
* All specific object types should extend this class so that instanceof tests against c_base_return_object are always accurate.
*/
class c_base_return_object extends c_base_return_value {
+
/**
* @see: t_base_return_value::p_s_new()
*/
* All specific resource types should extend this class so that instanceof tests against c_base_return_resource are always accurate.
*/
class c_base_return_resource extends c_base_return_value {
+
/**
* @see: t_base_return_value::p_s_new()
*/
* A return class whose value is represented as a stream resource.
*/
class c_base_return_resource_stream extends c_base_return_resource {
+
/**
* @see: t_base_return_value::p_s_new()
*/
* A return class whose value is represented as a socket resource.
*/
class c_base_return_resource_socket extends c_base_return_resource {
+
/**
* @see: t_base_return_value::p_s_new()
*/
return NULL;
}
- return $this->value;
+ return clone($this->value);
}
/**
return new c_theme_dom();
}
- return $this->value;
+ return clone($this->value);
}
}
return FALSE;
}
- $this->value = $value;
+ $this->value = clone($value);
return TRUE;
}
return NULL;
}
- return $this->value;
+ return clone($this->value);
}
/**
return new DOMNode();
}
+ return clone($this->value);
+ }
+
+ /**
+ * Return the value.
+ *
+ * This returns a reference instead of a copy.
+ *
+ * @return string|null $value
+ * The value array stored within this class.
+ */
+ public function get_value_reference() {
+ if (!is_null($this->value) && !($this->value instanceof DOMNode)) {
+ return NULL;
+ }
+
return $this->value;
}
+
+ /**
+ * Return the value of the expected type.
+ *
+ * This returns a reference instead of a copy.
+ *
+ * @return DOMNode $value
+ * The value DOMNode stored within this class.
+ */
+ public function get_value_reference_exact() {
+ if (!($this->value instanceof DOMNode)) {
+ return new DOMNode();
+ }
+
+ return clone($this->value);
+ }
}
/**
return FALSE;
}
- $this->value = $value;
+ $this->value = clone($value);
return TRUE;
}
return NULL;
}
- return $this->value;
+ return clone($this->value);
}
/**
return new DOMComment();
}
- return $this->value;
+ return clone($this->value);
}
}
return FALSE;
}
- $this->value = $value;
+ $this->value = clone($value);
return TRUE;
}
return NULL;
}
- return $this->value;
+ return clone($this->value);
}
/**
return FALSE;
}
- $this->value = $value;
+ $this->value = clone($value);
return TRUE;
}
return NULL;
}
- return $this->value;
+ return clone($this->value);
}
/**
return new DOMText();
}
- return $this->value;
+ return clone($this->value);
}
}
return FALSE;
}
- $this->value = $value;
+ $this->value = clone($value);
return TRUE;
}
$this->value = NULL;
}
- return $this->value;
+ return clone($this->value);
}
/**
$this->value = new c_theme_tag();
}
- return $this->value;
+ return clone($this->value);
}
}
*/
class c_theme_return_markup extends c_base_return_value {
use t_base_return_value_exact;
-
/**
* @see: t_base_return_value::p_s_new()
*/
return FALSE;
}
- $this->value = $value;
+ $this->value = clone($value);
return TRUE;
}
$this->value = NULL;
}
- return $this->value;
+ return clone($this->value);
}
/**
$this->value = new c_theme_tag();
}
- return $this->value;
+ return clone($this->value);
}
}