Обертка для file_get_contents

This commit is contained in:
CORP\phedor 2018-02-14 11:03:43 +03:00
parent bfd53ecc09
commit 0d92ebad86
5 changed files with 17 additions and 6 deletions

View file

@ -167,7 +167,7 @@ class Controller_Component
function getInfo() { function getInfo() {
$filename = Path::join($this->viewPath[0], 'install.json'); $filename = Path::join($this->viewPath[0], 'install.json');
if (file_exists($filename)) { if (file_exists($filename)) {
$settings = json_decode(file_get_contents($filename), true); $settings = json_decode(File::getContents($filename), true);
return $settings; return $settings;
} }
return array(); return array();

View file

@ -141,7 +141,7 @@ class Database_Manager
$this->db->query($q); $this->db->query($q);
} }
function getConstraintDef($c) { function getConstraintDef(/*.array.*/$c) {
if ($c['type'] == 'unique') { if ($c['type'] == 'unique') {
return "UNIQUE(" . implode(", ", $c['fields']) . ")"; return "UNIQUE(" . implode(", ", $c['fields']) . ")";
} }

11
src/File.php Normal file
View file

@ -0,0 +1,11 @@
<?php
class File {
static function getContents($filename) {
$buffer = file_get_contents($filename);
if ($buffer !== false) {
return $buffer;
}
throw new Exception("Unable to read file: " . $filename);
}
}

View file

@ -32,7 +32,7 @@ class Settings extends Collection
// Не include_once т.к читать настройки можно несколько раз // Не include_once т.к читать настройки можно несколько раз
$settings = array(); $settings = array();
if ($this->format == 'json') { if ($this->format == 'json') {
$settings = json_decode(file_get_contents($this->file), true); $settings = json_decode(File::getContents($this->file), true);
} else { } else {
include ($this->file); include ($this->file);
} }

View file

@ -38,11 +38,11 @@ class Tools_SQLStatementExtractor {
*/ */
public static function extractFile($filename) { public static function extractFile($filename) {
$buffer = file_get_contents($filename); $buffer = file_get_contents($filename);
if ($buffer === false) { if ($buffer !== false) {
throw new Exception("Unable to read file: " . $filename);
}
return self::extractStatements(self::getLines($buffer)); return self::extractStatements(self::getLines($buffer));
} }
throw new Exception("Unable to read file: " . $filename);
}
/** /**
* Extract statements from string. * Extract statements from string.