Use Icinga\Util\File instead of fopen
This commit is contained in:
parent
9066a0c2fa
commit
c563479888
|
@ -17,6 +17,7 @@ use Icinga\Application\Icinga;
|
|||
use Icinga\Logger\Logger;
|
||||
use Icinga\Util\Translator;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Util\File;
|
||||
|
||||
/**
|
||||
* Module handling
|
||||
|
@ -319,10 +320,12 @@ class Module
|
|||
|
||||
if (file_exists($this->metadataFile)) {
|
||||
|
||||
$fh = fopen($this->metadataFile, 'r');
|
||||
$file = File::open($this->metadataFile, 'r');
|
||||
$lines = $file->readlines();
|
||||
$file->close();
|
||||
$key = null;
|
||||
|
||||
while (false !== ($line = fgets($fh))) {
|
||||
foreach ($lines as $line) {
|
||||
$line = rtrim($line);
|
||||
|
||||
if ($key === 'description') {
|
||||
|
|
|
@ -6,9 +6,9 @@ namespace Icinga\Logger\Writer;
|
|||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Util\File;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Logger\LogWriter;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
/**
|
||||
|
@ -93,12 +93,6 @@ class FileWriter extends LogWriter
|
|||
*/
|
||||
protected function write($text)
|
||||
{
|
||||
$fd = fopen($this->path, 'a');
|
||||
|
||||
if ($fd === false || fwrite($fd, $text . PHP_EOL) === false) {
|
||||
throw new Exception('Failed to write to log file "' . $this->path . '"');
|
||||
}
|
||||
|
||||
fclose($fd);
|
||||
File::open($this->path, 'a')->write($text . PHP_EOL)->close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ class IniStore extends PreferencesStore
|
|||
);
|
||||
}
|
||||
|
||||
File::create($this->preferencesFile);
|
||||
File::open($this->preferencesFile, 'a')->chmod(0664)->close();
|
||||
}
|
||||
|
||||
if (!is_writable($this->preferencesFile)) {
|
||||
|
|
|
@ -78,6 +78,21 @@ class File
|
|||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read file line by line
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function readlines()
|
||||
{
|
||||
$lines = array();
|
||||
while (($line = fgets($this->handle)) !== false) {
|
||||
$lines[] = $line;
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write contents to file
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue