diff options
| author | 2013-12-28 17:29:38 +0100 | |
|---|---|---|
| committer | 2013-12-28 17:29:38 +0100 | |
| commit | 01a1dd09a8ee02250905a80d2662bfe811c09f09 (patch) | |
| tree | 9cfdd9c26f3f3b9b3d3ce44d36110c6ed41d0d9f /app/Models/LogDAO.php | |
| parent | 9ac1496d63da32524a33696187342ce061e9ef28 (diff) | |
Minz : refactorisation ModelArray et Log
Utilisation de fonctions natives de PHP comme file_put_contents et
var_export
Évite de garder un descripteur de fichier ouvert tout le temps
Et ModelTxt n'est plus utilisé
Diffstat (limited to 'app/Models/LogDAO.php')
| -rw-r--r-- | app/Models/LogDAO.php | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php index 06855ec66..e57e0b1b9 100644 --- a/app/Models/LogDAO.php +++ b/app/Models/LogDAO.php @@ -1,21 +1,23 @@ <?php -class FreshRSS_LogDAO extends Minz_ModelTxt { - public function __construct () { - parent::__construct (LOG_PATH . '/application.log', 'r+'); - } +class FreshRSS_LogDAO { + private static $filename = '/application.log'; - public function lister () { + public static function lines() { $logs = array (); - while (($line = $this->readLine ()) !== false) { - if (preg_match ('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) { - $myLog = new FreshRSS_Log (); - $myLog->_date ($matches[1]); - $myLog->_level ($matches[2]); - $myLog->_info ($matches[3]); - $logs[] = $myLog; + $handle = @fopen(LOG_PATH . self::$filename, 'r'); + if ($handle) { + while (($line = fgets($handle)) !== false) { + if (preg_match ('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) { + $myLog = new FreshRSS_Log (); + $myLog->_date ($matches[1]); + $myLog->_level ($matches[2]); + $myLog->_info ($matches[3]); + $logs[] = $myLog; + } } + fclose($handle); } - return $logs; + return array_reverse($logs); } } |
