*/ function exists( string $path ) : bool { return file_exists($path); } /** * @param string $path * @return string * @author Christian Fraß */ function read( string $path ) : string { if (! exists($path)) { throw (new \Exception(sprintf('file not found: "%s"', $path))); } else { $content = file_get_contents($path); if ($content === false) { throw (new \Exception('could not read file')); } else { return $content; } } } /** * @param string $path * @param string $content * @author Christian Fraß */ function write( string $path, string $content, bool $create_directory_if_missing = false ) { if ($create_directory_if_missing) { $directory = implode('/', array_slice(explode('/', $path), 0, -1)); if (! file_exists($directory)) { mkdir($directory); } } file_put_contents($path, $content); } /** * @param string $path * @author Christian Fraß */ function remove( string $path ) { if (! exists($path)) { throw (new \Exception(sprintf('file not found: "%s"', $path))); } else { unlink($path); } }