Dotclear

source: inc/core/class.dc.error.php @ 3074:594a1d72c352

Revision 3074:594a1d72c352, 2.2 KB checked in by Gvx <gvx@…>, 10 years ago (diff)

Cleaned unnecessary code

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14/**
15* @ingroup DC_CORE
16* @brief Error class
17*
18* dcError is a very simple error class, with a stack. Call dcError::add to
19* add an error in stack. In administration area, errors are automatically
20* displayed.
21*/
22class dcError
23{
24     /** @var array Errors stack */
25     protected $errors = array();
26     /** @var boolean True if stack is not empty */
27     protected $flag = false;
28     /** @var string HTML errors list pattern */
29     protected $html_list = "<ul>\n%s</ul>\n";
30     /** @var string HTML error item pattern */
31     protected $html_item = "<li>%s</li>\n";
32
33     /**
34     * Object string representation. Returns errors stack.
35     *
36     * @return string
37     */
38     public function __toString()
39     {
40          $res = '';
41
42          foreach ($this->errors as $msg)
43          {
44               $res .= $msg."\n";
45          }
46
47          return $res;
48     }
49
50     /**
51     * Adds an error to stack.
52     *
53     * @param string     $msg           Error message
54     */
55     public function add($msg)
56     {
57          $this->flag = true;
58          $this->errors[] = $msg;
59     }
60
61     /**
62     * Returns the value of <var>flag</var> property. True if errors stack is not empty
63     *
64     * @return boolean
65     */
66     public function flag()
67     {
68          return $this->flag;
69     }
70
71     /**
72     * Resets errors stack.
73     */
74     public function reset()
75     {
76          $this->flag = false;
77          $this->errors = array();
78     }
79
80     /**
81     * Returns <var>errors</var> property.
82     *
83     * @return array
84     */
85     public function getErrors()
86     {
87          return $this->errors;
88     }
89
90     /**
91     * Sets <var>list</var> and <var>item</var> properties.
92     *
93     * @param string     $list          HTML errors list pattern
94     * @param string     $item          HTML error item pattern
95     */
96     public function setHTMLFormat($list,$item)
97     {
98          $this->html_list = $list;
99          $this->html_item = $item;
100     }
101
102     /**
103     * Returns errors stack as HTML.
104     *
105     * @return string
106     */
107     public function toHTML()
108     {
109          $res = '';
110
111          if ($this->flag)
112          {
113               foreach ($this->errors as $msg)
114               {
115                    $res .= sprintf($this->html_item,$msg);
116               }
117
118               $res = sprintf($this->html_list,$res);
119          }
120
121          return $res;
122     }
123}
Note: See TracBrowser for help on using the repository browser.

Sites map