update
This commit is contained in:
49
core/class/FileGenerator.class.php
Normal file
49
core/class/FileGenerator.class.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
class FileGenerator {
|
||||
|
||||
private $lines = array();
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
public function AddLine($string) {
|
||||
$this->lines[] = $string;
|
||||
}
|
||||
|
||||
public function GenerateFileContents() {
|
||||
$output = null;
|
||||
if(count($this->lines)>1) {
|
||||
foreach($this->lines as $line) {
|
||||
$output .= $line.'\n';
|
||||
}
|
||||
} else {
|
||||
$output = $this->lines[0];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function SaveFile($file) {
|
||||
|
||||
if (is_writable($file)) {
|
||||
|
||||
if (!$fh = fopen($file, 'w')) {
|
||||
throw new UserException('Nie moge utworzyc pliku: '.$file);
|
||||
}
|
||||
if (fwrite($fh, $this->GenerateFileContents()) === FALSE) {
|
||||
throw new UserException('Nie moge pisac do pliku pliku: '.$file);
|
||||
}
|
||||
|
||||
|
||||
fclose($fh);
|
||||
|
||||
} else {
|
||||
throw new UserException('Nie moge pisac do pliku: '.$file);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user