remapCamelcase(); //$this->originalData = get_object_vars($this); } public function getId() { return $this->id; } protected function isPropertyDirty($property) { return $this->originalData->$property !== $this->$property; } public function isDirty() { return true; } public function getDirtyProperties() { $properties = get_object_vars($this); unset($properties['id']); return $this->fromCamelCase($properties); } /** * Convert the object properties to camelCase. * This works in constructor because the properties are here from * fetch_object before the constructor get called. */ protected function remapCamelcase() { foreach(get_object_vars($this) as $key => $val) { if(strpos($key, '_') !== false) { $camelCaseKey = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))); $this->$camelCaseKey = $val; unset($this->$key); } } } protected function fromCamelCase($properties) { $data = array(); foreach($properties as $propertie => $value) { $newPropertyKey = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $propertie)); $data[$newPropertyKey] = $value; } return $data; } }