/** * Converts the object to a string which can be stored as a file * @return string * @throws Exception */ public function stringify() { $out = array(); if (empty($this->author)) { throw new Exception('Author must not be empty.'); } if (empty($this->execute) && empty($this->sql)) { throw new Exception('There is neither an execute command nor a SQL part. One MUST be set.'); } foreach (array_keys(get_class_vars('Change')) as $var) { switch ($var) { case 'slow': if ($this->slow) { $out[] = $this->getDocComment($var); } break; case 'execute': foreach ($this->execute as $exec) { $out[] = $this->getDocComment($var, $exec); } unset($exec); break; case 'rights': if ($this->rights == 'normal') { break; } case 'db': if (empty($this->{$var}) || $this->{$var} == 'standard') { break; } $out[] = $this->getDocComment($var, $this->{$var}); break; case 'version': case 'since': case 'author': case 'message': if (empty($this->{$var})) { break; } $out[] = $this->getDocComment($var, $this->{$var}); break; } } if (!empty($this->sql)) { $out[] = str_replace(array(DbChangesSettings::CRLF, DbChangesSettings::CR), DbChangesSettings::LF, $this->sql); } $out[] = ''; $out = implode(DbChangesSettings::LF, $out); $lineEnding = $this->settings->getLineEnding(); if ($lineEnding != DbChangesSettings::LF) { $out = str_replace(DbChangesSettings::LF, $lineEnding, $out); } return $out; }