TQ\Svn\Repository\Repository::writeFile PHP Method

writeFile() public method

Writes data to a file and commit the changes immediately
public writeFile ( string $path, string | array $data, string | null $commitMsg = null, integer | null $fileMode = null, integer | null $dirMode = null, boolean $recursive = true, string | null $author = null ) : string
$path string The file path
$data string | array The data to write to the file
$commitMsg string | null The commit message used when committing the changes
$fileMode integer | null The mode for creating the file
$dirMode integer | null The mode for creating the intermediate directories
$recursive boolean Create intermediate directories recursively if required
$author string | null The author
return string The current commit hash
    public function writeFile($path, $data, $commitMsg = null, $fileMode = null, $dirMode = null, $recursive = true, $author = null)
    {
        $file = $this->resolveFullPath($path);
        $fileMode = $fileMode ?: $this->getFileCreationMode();
        $dirMode = $dirMode ?: $this->getDirectoryCreationMode();
        $directory = dirname($file);
        if (!file_exists($directory) && !mkdir($directory, (int) $dirMode, $recursive)) {
            throw new \RuntimeException(sprintf('Cannot create "%s"', $directory));
        } else {
            if (!file_exists($file)) {
                if (!touch($file)) {
                    throw new \RuntimeException(sprintf('Cannot create "%s"', $file));
                }
                if (!chmod($file, (int) $fileMode)) {
                    throw new \RuntimeException(sprintf('Cannot chmod "%s" to %d', $file, (int) $fileMode));
                }
            }
        }
        if (file_put_contents($file, $data) === false) {
            throw new \RuntimeException(sprintf('Cannot write to "%s"', $file));
        }
        $this->add(array($file));
        if ($commitMsg === null) {
            $commitMsg = sprintf('%s created or changed file "%s"', __CLASS__, $path);
        }
        $this->commit($commitMsg, null, $author);
        return $this->getCurrentCommit();
    }