Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
exceptions.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Exception class
8  * @package FDL
9  * @author Anakeen
10  *
11  */
12 namespace Dcp {
13  /**
14  * @brief Exception class
15  * use exceptionCode to identifiy correctly exception
16  * @class Exception
17  * @author Anakeen
18  */
19  class Exception extends \Exception
20  {
21  private $dcpCode = '';
22  private $httpHeader = array();
23  /**
24  * Redefined exception : message text is mandatory now
25  * @param string $message error message or code error
26  */
27  public function __construct($message, $argCode = 0)
28  {
29  $code = $message;
30  if ($code && (preg_match('/^([A-Z]+)([0-9]+)$/u', $code, $reg))) {
31  $tArgs = array(
32  $code
33  );
34  $nargs = func_num_args();
35  for ($ip = 1; $ip < $nargs; $ip++) {
36  $tArgs[] = func_get_arg($ip);
37  }
38  $msg = call_user_func_array("ErrorCode::getError", $tArgs);
39  if ($msg) $message = $msg;
40  $this->dcpCode = $code;
41  }
42  if ($argCode && is_numeric($argCode)) $intcode = intval($argCode);
43  else $intcode = 0;
44 
45  parent::__construct($message, $intcode);
46  }
47  /**
48  * return code error from constant of ErrorCode Class
49  * @return string
50  */
51  public function getDcpCode()
52  {
53  if ($this->dcpCode) return $this->dcpCode;
54  if (preg_match("/^{([^}]+)/u", $this->message, $reg)) {
55  return $reg[1];
56  }
57  return '';
58  }
59  /**
60  * return code error from constant of ErrorCode Class
61  * @return string
62  */
63  public function getDcpMessage()
64  {
65 
66  if (preg_match("/^{([^}]+)} *(.*)$/ums", $this->message, $reg)) {
67 
68  return $reg[2];
69  }
70  return $this->message;
71  }
72  /**
73  */
74  public function __toString()
75  {
76  return __CLASS__ . ": {$this->message}";
77  }
78 
79  public function addHttpHeader($header)
80  {
81  $this->httpHeader[] = $header;
82  }
83  public function getHttpHeader()
84  {
85  return implode("\n", $this->httpHeader);
86  }
87  }
88 }
89 
Exception class use exceptionCode to identifiy correctly exception.
Definition: exceptions.php:19
$message
addHttpHeader($header)
Definition: exceptions.php:79
__construct($message, $argCode=0)
Definition: exceptions.php:27
← centre documentaire © anakeen