1 | <?php |
||
2 | |||
3 | /** |
||
4 | * JPGraph v4.0.3 |
||
5 | */ |
||
6 | |||
7 | namespace Amenadiel\JpGraph\Util; |
||
8 | |||
9 | /* |
||
10 | * File: JPGRAPH_ERRHANDLER.PHP |
||
11 | * // Description: Error handler class together with handling of localized |
||
12 | * // error messages. All localized error messages are stored |
||
13 | * // in a separate file under the "lang/" subdirectory. |
||
14 | * // Created: 2006-09-24 |
||
15 | * // Ver: $Id: jpgraph_errhandler.inc.php 1920 2009-12-08 10:02:26Z ljp $ |
||
16 | * // |
||
17 | * // Copyright 2006 (c) Aditus Consulting. All rights reserved. |
||
18 | */ |
||
19 | if (!defined('DEFAULT_ERR_LOCALE')) { |
||
20 | define('DEFAULT_ERR_LOCALE', 'en'); |
||
21 | } |
||
22 | |||
23 | if (!defined('USE_IMAGE_ERROR_HANDLER')) { |
||
24 | define('USE_IMAGE_ERROR_HANDLER', true); |
||
25 | } |
||
26 | |||
27 | global $__jpg_err_locale; |
||
28 | $__jpg_err_locale = DEFAULT_ERR_LOCALE; |
||
29 | |||
30 | class ErrMsgText |
||
31 | { |
||
32 | private $lt; |
||
33 | |||
34 | public function __construct() |
||
35 | { |
||
36 | global $__jpg_err_locale; |
||
37 | $file = dirname(dirname(__FILE__)) . '/lang/' . $__jpg_err_locale . '.inc.php'; |
||
38 | |||
39 | // If the chosen locale doesn't exist try english |
||
40 | if (!file_exists($file)) { |
||
41 | $__jpg_err_locale = 'en'; |
||
42 | } |
||
43 | |||
44 | $file = dirname(dirname(__FILE__)) . '/lang/' . $__jpg_err_locale . '.inc.php'; |
||
45 | if (!file_exists($file)) { |
||
46 | die('Chosen locale file ("' . $file . '") for error messages does not exist or is not readable for the PHP process. Please make sure that the file exists and that the file permissions are such that the PHP process is allowed to read this file.'); |
||
0 ignored issues
–
show
|
|||
47 | } |
||
48 | require $file; |
||
49 | $this->lt = $_jpg_messages; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
50 | } |
||
51 | |||
52 | public function Get($errnbr, $a1 = null, $a2 = null, $a3 = null, $a4 = null, $a5 = null) |
||
53 | { |
||
54 | global $__jpg_err_locale; |
||
55 | if (!isset($this->lt[$errnbr])) { |
||
56 | return 'Internal error: The specified error message (' . $errnbr . ') does not exist in the chosen locale (' . $__jpg_err_locale . ')'; |
||
57 | } |
||
58 | $ea = $this->lt[$errnbr]; |
||
59 | $j = 0; |
||
60 | if ($a1 !== null) { |
||
61 | $argv[$j++] = $a1; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
62 | if ($a2 !== null) { |
||
63 | $argv[$j++] = $a2; |
||
64 | if ($a3 !== null) { |
||
65 | $argv[$j++] = $a3; |
||
66 | if ($a4 !== null) { |
||
67 | $argv[$j++] = $a4; |
||
68 | if ($a5 !== null) { |
||
69 | $argv[$j++] = $a5; |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | $numargs = $j; |
||
76 | if ($ea[1] != $numargs) { |
||
77 | // Error message argument count do not match. |
||
78 | // Just return the error message without arguments. |
||
79 | return $ea[0]; |
||
80 | } |
||
81 | switch ($numargs) { |
||
82 | case 1: |
||
83 | $msg = sprintf($ea[0], $argv[0]); |
||
84 | |||
85 | break; |
||
86 | case 2: |
||
87 | $msg = sprintf($ea[0], $argv[0], $argv[1]); |
||
88 | |||
89 | break; |
||
90 | case 3: |
||
91 | $msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2]); |
||
92 | |||
93 | break; |
||
94 | case 4: |
||
95 | $msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2], $argv[3]); |
||
96 | |||
97 | break; |
||
98 | case 5: |
||
99 | $msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2], $argv[3], $argv[4]); |
||
100 | |||
101 | break; |
||
102 | case 0: |
||
103 | default: |
||
104 | $msg = sprintf($ea[0]); |
||
105 | |||
106 | break; |
||
107 | } |
||
108 | |||
109 | return $msg; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | // Setup the default handler |
||
114 | global $__jpg_OldHandler; |
||
115 | $__jpg_OldHandler = set_exception_handler(['Amenadiel\JpGraph\Util\JpGraphException', 'defaultHandler']); |
||
116 | |||
117 | if (!USE_IMAGE_ERROR_HANDLER) { |
||
118 | JpGraphError::SetImageFlag(false); |
||
119 | } |
||
120 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.