Gajus\MOA\Mother::synchronise PHP Method

synchronise() private method

This will overwrite the existing state of the object.
private synchronise ( ) : void
return void
    private function synchronise()
    {
        $this->logger->debug('Synchronising object.', ['method' => __METHOD__, 'object' => static::TABLE_NAME]);
        if (!isset($this->data[static::PRIMARY_KEY_NAME])) {
            throw new Exception\LogicException('Primary key is not set.');
        }
        if ($this->updated_properties) {
            throw new Exception\LogicException('Object state has not been saved prior synchronisation.');
        }
        $sth = $this->db->prepare("SELECT * FROM `" . static::TABLE_NAME . "` WHERE `" . static::PRIMARY_KEY_NAME . "` = ?");
        $sth->execute([$this->data[static::PRIMARY_KEY_NAME]]);
        $this->data = $sth->fetch(\PDO::FETCH_ASSOC);
        if (!$this->data) {
            throw new Exception\RecordNotFoundException('Primary key value does not refer to an existing record.');
        }
        foreach (static::$columns as $name => $column) {
            if (!array_key_exists($name, $this->data)) {
                throw new Exception\LogicException('Model does not reflect table.');
            }
            // @todo Add as a test condition.
            if (in_array($column['data_type'], ['datetime', 'timestamp']) && !is_null($this->data[$name])) {
                $this->data[$name] = strtotime($this->data[$name]);
            }
        }
        $this->synchronisation_count++;
    }