Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 5 additions & 124 deletions SwatDB/SwatDBDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,6 @@
return $this->getDeprecatedProperty($key);
}

$property_list = $this->getProtectedPropertyList();
if (array_key_exists($key, $property_list)) {
if (array_key_exists('get', $property_list[$key])) {
$get = $property_list[$key]['get'];

return $this->{$get}();
}

return $this->{$key};
}

$value = $this->getUsingLoaderMethod($key);

if ($value === false) {
Expand Down Expand Up @@ -188,19 +177,6 @@
return;
}

$property_list = $this->getProtectedPropertyList();
if (array_key_exists($key, $property_list)) {
if (array_key_exists('set', $property_list[$key])) {
$set = $property_list[$key]['set'];
$this->{$set}($value);

return;
}
$this->{$key} = $value;

return;
}

if (method_exists($this, $this->getLoaderMethod($key))) {
if ($value === null) {
$this->unsetSubDataObject($key);
Expand Down Expand Up @@ -241,8 +217,7 @@
$is_set
= method_exists($this, $this->getLoaderMethod($key))
|| ($this->hasInternalValue($key)
&& $this->internal_property_accessible[$key])
|| array_key_exists($key, $this->getProtectedPropertyList());
&& $this->internal_property_accessible[$key]);
}

return $is_set;
Expand Down Expand Up @@ -388,10 +363,7 @@
$id_field = new SwatDBField($this->id_field, 'integer');

// public properties
$properties = array_merge(
$this->getPublicProperties(),
$this->getSerializableProtectedProperties(),
);
$properties = $this->getPublicProperties();

foreach ($properties as $name => $value) {
if ($name !== $id_field->name) {
Expand Down Expand Up @@ -447,22 +419,15 @@
/**
* Returns an array of the public and protected properties of this object.
*
* This array is useful for places where get_object_vars() is useful but we
* also want to return the protected properties alongside the public onces.
* For example when using getter and setter methods instead of public
* properties on a dataobject.
* This array is useful for places where get_object_vars() is useful.
*
* @return array an array of public and protected properties
* @return array an array of properties
*
* @see SwatDBDataObject::getPublicProperties()
* @see SwatDBDataObject::getSerializableProtectedProperties()
*/
public function getAttributes()
{
return array_merge(
$this->getPublicProperties(),
$this->getProtectedProperties(),
);
return $this->getPublicProperties();
}

protected function setInternalValue($name, $value)
Expand Down Expand Up @@ -515,7 +480,7 @@

$property_array = array_merge(
$this->getPublicProperties(),
$this->getSerializableProtectedProperties(),

Check failure on line 483 in SwatDB/SwatDBDataObject.php

View workflow job for this annotation

GitHub Actions / runner

Call to an undefined method SwatDBDataObject::getSerializableProtectedProperties().
);

if (is_object($row)) {
Expand Down Expand Up @@ -660,23 +625,6 @@
return null;
}

/**
* Gets a list of all protected properties of this data-object.
*
* The keys of this array should map to protected properties on this
* object. The value of each entry is a second array in the format
* [ 'get' => 'getMethodName', 'set' => 'setMethodName' ]
* where the keys of each array correspond to methods on this object that
* will be called by the magic getter and setter when the protected
* property is accessed.
*
* @return array an array of protected property keys and method values
*/
protected function getProtectedPropertyList()
{
return [];
}

/**
* Gets the public properties of this data-object.
*
Expand Down Expand Up @@ -714,49 +662,6 @@
return $properties;
}

/**
* Gets the serializable protected properties of this data-object.
*
* Protected properties should correspond directly to database fields.
*
* @return array a reference to an associative array of protected properties
* of this data-object. The array is of the form
* 'property name' => 'property value'.
*/
private function getSerializableProtectedProperties()
{
$properties = [];
foreach ($this->getProtectedPropertyList() as $property => $accessors) {
// We want to maintain what is internally stored in this object so
// we don't want to use the getter. What the getter returns
// publicly may be different than what we have internally.
$properties[$property] = $this->{$property};
}

return $properties;
}

/**
* Gets the protected properties of this data-object using the getter
* accessor.
*
* Protected properties should correspond directly to database fields.
*
* @return array a reference to an associative array of protected properties
* of this data-object. The array is of the form
* 'property name' => 'property value'.
*/
private function getProtectedProperties()
{
$properties = [];
foreach ($this->getProtectedPropertyList() as $property => $accessors) {
// Use the getter for the property.
$properties[$property] = $this->{$accessors['get']}();
}

return $properties;
}

/**
* Gets all the modifyable properties of this data-object.
*
Expand All @@ -772,7 +677,6 @@
{
$property_array = array_merge(
$this->getPublicProperties(),
$this->getSerializableProtectedProperties(),
$this->internal_properties,
);

Expand Down Expand Up @@ -1436,13 +1340,6 @@
}
}

foreach ($this->getProtectedPropertyList() as $property => $accessor) {
// We want to maintain what is internally stored in this object so
// we don't want to use the getter. What the getter returns
// publicly may be different than what we have internally.
$data[$property] = $this->{$property};
}

// restore unset sub-dataobjects on this object
foreach ($unset_objects as $name => $object) {
$this->setSubDataObject($name, $object);
Expand Down Expand Up @@ -1530,13 +1427,6 @@
}
}

foreach ($this->getProtectedPropertyList() as $property => $accessor) {
// We want to maintain what is internally stored in this object so
// we don't want to use the getter. What the getter returns
// publicly may be different than what we have internally.
$data[$property] = $this->{$property};
}

return $data;
}

Expand All @@ -1555,15 +1445,6 @@
}
}

foreach ($this->getProtectedPropertyList() as $property => $accessor) {
if (isset($data[$property])) {
// We want to maintain what is internally stored in this object
// so we don't want to use the getter. What the setter sets may
// be different than what we have internally.
$this->{$property} = $data[$property];
}
}

// private properties sans sub-data-objects property
$private_properties = $this->getSerializablePrivateProperties();
$private_properties = array_diff($private_properties, [
Expand Down
Loading