2 /***************************************************************************
3 * Copyright (C) 2003-2011 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 $file = Platal
::globals()->spoolroot
. '/spool/tmp/site_errors';
78 if (file_exists($file)) {
79 $this->file
= fopen($file, 'r');
85 public function next()
90 $entry = fgetcsv($this->file
);
91 if ($entry === false
) {
96 $value = PlErrorReport
::fromCSV($entry);
100 public function total()
105 public function first()
110 public function last()
116 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: