entity = $entity; $this->id = $id; } /** * Return an array of messages describing the change that this operation will bring * * @return array * @throws \Exception */ public function getChangeLog(): array { $messages = [ '[PUT ' . $this->entity . '/' . $this->id . ']' ]; foreach ($this->parameters as $field => $newValue) { if (!array_key_exists($field, $this->currentData)) { throw new \Exception('Field does not exists in the current object data : ' . $field); } if (is_array($newValue)) { foreach ($newValue as $subField => $newSubValue) { if (!array_key_exists($subField, $this->currentData[$field])) { throw new \Exception('Field does not exists in the current object data : ' . $field . '.' . $subField); } if ($newSubValue !== $this->currentData[$field][$subField]) { $messages[] = $field . '.' . $subField . ' : `'. $this->currentData[$field][$subField] . '` => `' . $newSubValue . '`'; } } } else { if ($newValue !== $this->currentData[$field]) { $messages[] = $field . ' : `' . $this->currentData[$field] . '` => `' . $newValue . '`'; } } } return $messages; } }