Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.error.php

    r3615 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414/** 
    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 */ 
     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 */ 
    2222class dcError 
    2323{ 
    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      /** @var string HTML error single pattern */ 
    33      protected $html_single = "<p>%s</p>\n"; 
     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    /** @var string HTML error single pattern */ 
     33    protected $html_single = "<p>%s</p>\n"; 
    3434 
    35      /** 
    36      * Object string representation. Returns errors stack. 
    37      * 
    38      * @return string 
    39      */ 
    40      public function __toString() 
    41      { 
    42           $res = ''; 
     35    /** 
     36     * Object string representation. Returns errors stack. 
     37     * 
     38     * @return string 
     39     */ 
     40    public function __toString() 
     41    { 
     42        $res = ''; 
    4343 
    44           foreach ($this->errors as $msg) 
    45           { 
    46                $res .= $msg."\n"; 
    47           } 
     44        foreach ($this->errors as $msg) { 
     45            $res .= $msg . "\n"; 
     46        } 
    4847 
    49           return $res; 
    50      } 
     48        return $res; 
     49    } 
    5150 
    52      /** 
    53      * Adds an error to stack. 
    54      * 
    55      * @param string     $msg           Error message 
    56      */ 
    57      public function add($msg) 
    58      { 
    59           $this->flag = true; 
    60           $this->errors[] = $msg; 
    61      } 
     51    /** 
     52     * Adds an error to stack. 
     53     * 
     54     * @param string    $msg            Error message 
     55     */ 
     56    public function add($msg) 
     57    { 
     58        $this->flag    = true; 
     59        $this->errors[] = $msg; 
     60    } 
    6261 
    63      /** 
    64      * Returns the value of <var>flag</var> property. True if errors stack is not empty 
    65      * 
    66      * @return boolean 
    67      */ 
    68      public function flag() 
    69      { 
    70           return $this->flag; 
    71      } 
     62    /** 
     63     * Returns the value of <var>flag</var> property. True if errors stack is not empty 
     64     * 
     65     * @return boolean 
     66     */ 
     67    public function flag() 
     68    { 
     69        return $this->flag; 
     70    } 
    7271 
    73      /** 
    74      * Resets errors stack. 
    75      */ 
    76      public function reset() 
    77      { 
    78           $this->flag = false; 
    79           $this->errors = array(); 
    80      } 
     72    /** 
     73     * Resets errors stack. 
     74     */ 
     75    public function reset() 
     76    { 
     77        $this->flag  = false; 
     78        $this->errors = array(); 
     79    } 
    8180 
    82      /** 
    83      * Returns <var>errors</var> property. 
    84      * 
    85      * @return array 
    86      */ 
    87      public function getErrors() 
    88      { 
    89           return $this->errors; 
    90      } 
     81    /** 
     82     * Returns <var>errors</var> property. 
     83     * 
     84     * @return array 
     85     */ 
     86    public function getErrors() 
     87    { 
     88        return $this->errors; 
     89    } 
    9190 
    92      /** 
    93      * Sets <var>list</var> and <var>item</var> properties. 
    94      * 
    95      * @param string     $list          HTML errors list pattern 
    96      * @param string     $item          HTML error item pattern 
    97      */ 
    98      public function setHTMLFormat($list,$item,$single=null) 
    99      { 
    100           $this->html_list = $list; 
    101           $this->html_item = $item; 
    102           if ($single) { 
    103                $this->html_single = $single; 
    104           } 
    105      } 
     91    /** 
     92     * Sets <var>list</var> and <var>item</var> properties. 
     93     * 
     94     * @param string    $list        HTML errors list pattern 
     95     * @param string    $item        HTML error item pattern 
     96     */ 
     97    public function setHTMLFormat($list, $item, $single = null) 
     98    { 
     99        $this->html_list = $list; 
     100        $this->html_item = $item; 
     101        if ($single) { 
     102            $this->html_single = $single; 
     103        } 
     104    } 
    106105 
    107      /** 
    108      * Returns errors stack as HTML. 
    109      * 
    110      * @return string 
    111      */ 
    112      public function toHTML() 
    113      { 
    114           $res = ''; 
     106    /** 
     107     * Returns errors stack as HTML. 
     108     * 
     109     * @return string 
     110     */ 
     111    public function toHTML() 
     112    { 
     113        $res = ''; 
    115114 
    116           if ($this->flag) 
    117           { 
    118                if (count($this->errors == 1)) { 
    119                     $res = sprintf($this->html_single,$this->errors[0]); 
    120                } else { 
    121                     foreach ($this->errors as $msg) { 
    122                          $res .= sprintf($this->html_item,$msg); 
    123                     } 
    124                     $res = sprintf($this->html_list,$res); 
    125                } 
    126           } 
     115        if ($this->flag) { 
     116            if (count($this->errors == 1)) { 
     117                $res = sprintf($this->html_single, $this->errors[0]); 
     118            } else { 
     119                foreach ($this->errors as $msg) { 
     120                    $res .= sprintf($this->html_item, $msg); 
     121                } 
     122                $res = sprintf($this->html_list, $res); 
     123            } 
     124        } 
    127125 
    128           return $res; 
    129      } 
     126        return $res; 
     127    } 
    130128} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map