Dotclear

source: inc/core/class.dc.error.php @ 2566:9bf417837888

Revision 2566:9bf417837888, 2.3 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add some people in CREDITS, remove trailing spaces and tabs.

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[0]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/**
[334]15* @ingroup DC_CORE
16* @brief Error class
[2566]17*
[334]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.
[0]21*/
22class dcError
23{
[334]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";
[2566]32
[0]33     /**
[334]34     * Object constructor.
[0]35     */
36     public function __construct()
37     {
38          $this->code = 0;
39          $this->msg = '';
40     }
[2566]41
[0]42     /**
[334]43     * Object string representation. Returns errors stack.
[2566]44     *
[334]45     * @return string
[0]46     */
47     public function __toString()
48     {
49          $res = '';
[2566]50
[0]51          foreach ($this->errors as $msg)
52          {
53               $res .= $msg."\n";
54          }
[2566]55
[0]56          return $res;
57     }
[2566]58
[0]59     /**
[334]60     * Adds an error to stack.
[2566]61     *
[334]62     * @param string     $msg           Error message
[0]63     */
64     public function add($msg)
65     {
66          $this->flag = true;
67          $this->errors[] = $msg;
68     }
[2566]69
[0]70     /**
[334]71     * Returns the value of <var>flag</var> property. True if errors stack is not empty
[2566]72     *
[334]73     * @return boolean
[0]74     */
75     public function flag()
76     {
77          return $this->flag;
78     }
[2566]79
[0]80     /**
[334]81     * Resets errors stack.
[0]82     */
83     public function reset()
84     {
85          $this->flag = false;
86          $this->errors = array();
87     }
[2566]88
[0]89     /**
[334]90     * Returns <var>errors</var> property.
[2566]91     *
[334]92     * @return array
[0]93     */
94     public function getErrors()
95     {
96          return $this->errors;
97     }
[2566]98
[0]99     /**
[334]100     * Sets <var>list</var> and <var>item</var> properties.
[2566]101     *
[334]102     * @param string     $list          HTML errors list pattern
103     * @param string     $item          HTML error item pattern
[0]104     */
105     public function setHTMLFormat($list,$item)
106     {
107          $this->html_list = $list;
108          $this->html_item = $item;
109     }
[2566]110
[0]111     /**
[334]112     * Returns errors stack as HTML.
[2566]113     *
[334]114     * @return string
[0]115     */
116     public function toHTML()
117     {
118          $res = '';
[2566]119
[0]120          if ($this->flag)
121          {
122               foreach ($this->errors as $msg)
123               {
124                    $res .= sprintf($this->html_item,$msg);
125               }
[2566]126
[0]127               $res = sprintf($this->html_list,$res);
128          }
[2566]129
[0]130          return $res;
131     }
132}
Note: See TracBrowser for help on using the repository browser.

Sites map