Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make entity values _raw for before passing to DB. #1647

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 10 additions & 10 deletions system/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ class Entity
protected $_original = [];

/**
* Holds info whenever prperties have to be casted
* Holds info whenever properties have to be casted or magic method should be used.
*
* @var boolean
**/
private $_cast = true;
private $_raw = true;

/**
* Allows filling in Entity parameters during construction.
Expand Down Expand Up @@ -150,13 +150,13 @@ public function fill(array $data)
* applied to them.
*
* @param boolean $onlyChanged If true, only return values that have changed since object creation
* @param boolean $cast If true, properties will be casted.
* @param boolean $raw If true, properties will be casted / and getMyProperty will be used.
*
* @return array
*/
public function toArray(bool $onlyChanged = false, bool $cast = true): array
public function toArray(bool $onlyChanged = false, bool $raw = true): array
{
$this->_cast = $cast;
$this->_raw = $raw;
$return = [];

// we need to loop over our properties so that we
Expand Down Expand Up @@ -186,7 +186,7 @@ public function toArray(bool $onlyChanged = false, bool $cast = true): array
$return[$from] = $this->__get($to);
}
}
$this->_cast = true;
$this->_raw = true;
return $return;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public function __get(string $key)

// if a set* method exists for this key,
// use that method to insert this value.
if (method_exists($this, $method))
if ($this->_raw && method_exists($this, $method))
{
$result = $this->$method();
}
Expand All @@ -226,21 +226,21 @@ public function __get(string $key)
{
$result = $this->$key;
}

// Do we need to mutate this into a date?
if (in_array($key, $this->_options['dates']))
{
$result = $this->mutateDate($result);
}
// Or cast it as something?
else if ($this->_cast && isset($this->_options['casts'][$key]) && ! empty($this->_options['casts'][$key]))
else if ($this->_raw && isset($this->_options['casts'][$key]) && ! empty($this->_options['casts'][$key]))
{
$result = $this->castAs($result, $this->_options['casts'][$key]);

}

return $result;
}

//--------------------------------------------------------------------

/**
Expand Down