-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathUps_Base_Response.php
More file actions
158 lines (118 loc) · 2.04 KB
/
Ups_Base_Response.php
File metadata and controls
158 lines (118 loc) · 2.04 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* UPS Base Response
*
* @package UPS API
* @author Justin Kimbrell
* @copyright Copyright (c) 2012, Objective HTML
* @link http://www.objectivehtml.com/
* @version 0.2.0
* @build 20120823
*/
abstract class Base_UPS_Response {
/**
* UPS Success Constant
*
* @var string
*/
const UPS_SUCCESS = TRUE;
/**
* UPS Failed Constant
*
* @var string
*/
const UPS_FAILED = FALSE;
/**
* Errors
*
* @var array
*/
public $errors = array();
/**
* Warning
*
* @var array
*/
public $warnings = array();
/**
* Timestamp
*
* @var array
*/
public $timestamp;
/**
* Response Code
*
* @var string
*/
public $code;
/**
* Response Status
*
* @var string
*/
public $status;
/**
* Construct
*
* @access public
* @return obj
*/
public function __construct($data = array())
{
$this->timestamp = time();
foreach($data as $key => $value)
{
if(property_exists($this, $key))
{
$this->$key = $value;
}
}
}
public function __set($name, $value)
{
if(property_exists($this, $name))
$this->{$name} = $value;
else if(property_exists($this, ("_".$name)))
$this->{"_".$name} = $value;
else
throw new Exception("Trying to set unexisting property ".$name);
}
/**
* Set the response as success
*
* @access public
* @param mixed Response code
* @return NULL
*/
public function success($code = NULL)
{
$this->set_response(self::UPS_SUCCESS, $code);
}
/**
* Set the response as failed
*
* @access public
* @param mixed Response code
* @return NULL
*/
public function failed($code = NULL)
{
$this->set_response(self::UPS_FAILED, $code);
}
/**
* Set the response
*
* @access public
* @param mixed Response code
* @return NULL
*/
public function set_response($response, $code = NULL)
{
if(!is_null($code))
{
$this->code = $code;
}
$this->status = $response;
}
}