Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
ErrorCode.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * @classname ErrorCode
8  * @brief static method use to retrieve error code
9  * @see ErrorCodeATTR family attribute error codes
10  * @see ErrorCodeWFL workflow error codes
11  * @see ErrorCodeACCS application access error codes
12  * @see ErrorCodePRFL document's profil error codes
13  * @see ErrorCodePRFD family profil error codes
14  * @see ErrorCodeDOC document error codes
15  * @see ErrorCodeORDR order error codes
16  * @see ErrorCodeKEYS keys error codes
17  *
18  */
19 class ErrorCode
20 {
21  /**
22  * @static
23  * @param string $code error code
24  * @param ... $args
25  * @return string the composed message
26  */
27  public static function getError($code, $args = null)
28  {
29  $msg = '';
30  if ($code) {
31  if (preg_match('/^([A-Z]+)([0-9]+)$/', $code, $reg)) {
32  $class = sprintf("ErrorCode%s", $reg[1]);
33  try {
34  $rc = new ReflectionClass($class);
35  $fmt = $rc->getConstant($code);
36  if ($fmt) {
37 
38  $nargs = func_num_args();
39  $sp = array();
40  for ($ip = 1; $ip < $nargs; $ip++) {
41  $sp[] = func_get_arg($ip);
42  }
43  $label = @vsprintf($fmt, $sp);
44  if ($label) {
45  $msg = sprintf("{%s} %s", $code, $label);
46  } else {
47  $gl = error_get_last();
48  $msg = sprintf("{%s} %s", $code, $gl['message']);
49  }
50  } else {
51  $msg = sprintf("unknow error code %s", $code);
52  }
53  }
54  catch(Exception $e) {
55  $msg = sprintf("cannot find class error for %s : %s (%s)", $code, $e->getMessage() , implode(', ', func_get_args()));
56  }
57  } else {
58  $msg = sprintf("wrong error code %s", $code);
59  }
60  }
61  // if ($msg) error_log("ERROR:" . $msg);
62  return $msg;
63  }
64 }
if(substr($wsh, 0, 1)!= '/') $args
static getError($code, $args=null)
Definition: ErrorCode.php:27
static method use to retrieve error code
Definition: ErrorCode.php:19
$class
Definition: updateclass.php:38
← centre documentaire © anakeen