520acf0fc8e8eb8c17d3f951c3f986a702287678
2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 **************************************************************************/
28 private function __construct($date, $error, $state = array())
31 $this->error
= "" . $error;
32 $this->state
= $state;
35 private function toCSV()
37 return array($this->date
, $this->error
, serialize($this->state
));
40 public function fromCSV(array $entry)
42 return new PlErrorReport($entry[0], $entry[1], unserialize($entry[2]));
45 public static function report($error)
47 $error = new PlErrorReport(date('Y-m-d G:i:s'), $error,
48 array('Session' => $_SESSION,
53 'Server' => $_SERVER));
55 $file = fopen(Platal
::globals()->spoolroot
. '/spool/tmp/site_errors', 'a');
56 fputcsv($file, $error->toCSV());
60 public static function iterate()
62 return new PlErrorReportIterator();
65 public static function clear()
67 @unlink
(Platal
::globals()->spoolroot
. '/spool/tmp/site_errors');
71 class PlErrorReportIterator
implements PlIterator
75 public function __construct()
77 $this->file
= fopen(Platal
::globals()->spoolroot
. '/spool/tmp/site_errors', 'r');
80 public function next()
85 $entry = fgetcsv($this->file
);
86 if ($entry === false
) {
91 $value = PlErrorReport
::fromCSV($entry);
95 public function total()
100 public function first()
105 public function last()
111 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: