-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorConfig.php
137 lines (110 loc) · 3.47 KB
/
ErrorConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
namespace dc\yukon;
require_once('config.php');
// Common warning codes:
// 0: Cursor type changed.
// 5701: Changed database context.
// 5703: Changed language setting.
// Legacy error handling.
interface iErrorConfig
{
// Accessors
function get_exempt_codes_catch();
function get_exempt_codes_driver();
function get_exempt_codes_throw();
// Mutators
function set_exempt_codes_catch(\SplDoublyLinkedList $value);
function set_exempt_codes_driver(\SplDoublyLinkedList $value);
function set_exempt_codes_throw(\SplDoublyLinkedList $value);
function driver_config($key, $value);
}
class ErrorConfig implements iErrorConfig
{
private
$exempt_codes_catch = NULL, // List of error codes that will be ignored by error trap.
$exempt_codes_driver = NULL, // Toggle internal exception handling.
$exempt_codes_throw = NULL; // Toggle catching of driver errors.
public function __construct(\SplDoublyLinkedList $exempt_codes_catch = NULL, \SplDoublyLinkedList $exempt_codes_throw = NULL, \SplDoublyLinkedList $exempt_codes_driver = NULL)
{
// Apply exempt code lists. We use default constants here
// instead of in the argument block explicitly so
// users must create linked lists and maintain consistency.
$this->exempt_codes_catch = $this->construct_exempt_codes($exempt_codes_catch, DEFAULTS::EXEMPT_CODES_CATCH);
$this->exempt_codes_driver = $this->construct_exempt_codes($exempt_codes_driver, DEFAULTS::EXEMPT_CODES_DRIVER);
$this->exempt_codes_throw = $this->construct_exempt_codes($exempt_codes_throw, DEFAULTS::EXEMPT_CODES_THROW);
}
// Accessors.
public function get_exempt_codes_catch()
{
return $this->exempt_codes_catch;
}
public function get_exempt_codes_driver()
{
return $this->exempt_codes_driver;
}
public function get_exempt_codes_throw()
{
return $this->exempt_codes_throw;
}
// Mutators.
public function set_exempt_codes_catch(\SplDoublyLinkedList $value)
{
$this->exempt_codes_catch = $value;
}
public function set_exempt_codes_driver(\SplDoublyLinkedList $value)
{
$this->exempt_codes_driver = $value;
}
public function set_exempt_codes_throw(\SplDoublyLinkedList $value)
{
$this->exempt_codes_throw = $value;
}
// Constructors
// Passes through list object or returns
// a new object with default values if
// value is NULL.
private function construct_exempt_codes(\SplDoublyLinkedList $value = NULL, $default)
{
$result = NULL; // Final result.
// Verify argument is an object.
$is_object = is_object($value);
if($is_object)
{
$result = $value;
}
else
{
// Create a new list with default values.
$result = $this->explode_to_list($default);
}
// Return final result.
return $result;
}
// Explode delimited list to an SplDoublyLinkedList object.
private function explode_to_list($list = NULL, $delimiter = ',')
{
// Initialize new doubly linked list object.
$result = new \SplDoublyLinkedList();
// Break down list to array.
$value_array = explode(',', $list);
// Add array elements to exempt code list.
foreach($value_array as $value_element)
{
// For our purposes, 0 is a valid list value,
// but a blank string is not. We'll make sure
// the list is clean here by filtering
// out blank strings.
if($value_element !== '')
{
$result->push($value_element);
}
}
return $result;
}
//
public function driver_config($key, $value)
{
return sqlsrv_configure($key, $value);
}
}
?>