FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
shipengine-php/src/ShipEngineConfig.php at main · ShipEngine/shipengine-php · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ShipEngine
/
shipengine-php
Public
Notifications
You must be signed in to change notification settings
Fork
12
Star
17
Code
Issues
2
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
shipengine-php
/
src
/
ShipEngineConfig.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
172 lines (146 loc) · 4.74 KB
Breadcrumbs
shipengine-php
/
src
/
ShipEngineConfig.php
Copy path
File metadata and controls
172 lines (146 loc) · 4.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
declare
(strict_types=
1
);
namespace
ShipEngine
;
use
DateInterval
;
use
ShipEngine
\
Message
\
ValidationException
;
use
ShipEngine
\
Util
\
Assert
;
use
ShipEngine
\
Util
\
Constants
\
Endpoints
;
/**
* Class ShipEngineConfig - This is the configuration object for the ShipEngine object and it's properties are
* used throughout this SDK.
*
* @package ShipEngine
*/
final
class
ShipEngineConfig
implements
\JsonSerializable
{
/**
* The default base uri for the ShipEngineClient.
*/
public
const
DEFAULT_BASE_URI
= Endpoints::
SHIPENGINE_REST_URL
;
/**
* Default page size for responses from ShipEngine API.
*/
public
const
DEFAULT_PAGE_SIZE
=
50
;
/**
* Default number of retries the ShipEngineClient should make before returning an exception.
*/
public
const
DEFAULT_RETRIES
=
1
;
/**
* Default timeout for the ShipEngineClient in seconds as a **DateInterval**.
*/
public
const
DEFAULT_TIMEOUT
=
'
PT10S
'
;
/**
* A ShipEngine API Key, sandbox API Keys start with **TEST_**.
*
* @var string
*/
public
string
$
apiKey
;
/**
* The configured base uri for the ShipEngineClient.
*
* @var string
*/
public
string
$
baseUrl
;
/**
* Configured page size for responses from ShipEngine API.
*
* @var int
*/
public
int
$
pageSize
;
/**
* Configured number of retries the ShipEngineClient should make before returning an exception.
*
* @var int
*/
public
int
$
retries
;
/**
* Configured timeout for the ShipEngineClient in seconds as a **DateInterval**.
*
* @var DateInterval
*/
public
DateInterval
$
timeout
;
/**
* ShipEngineConfig constructor.
*
* @param array $config {apiKey:string, baseUrl:string, pageSize:int,
* retries:int, timeout:DateInterval}
*/
public
function
__construct
(
array
$
config
=
array
())
{
$
assert
=
new
Assert
();
$
assert
->
isApiKeyValid
(
$
config
);
$
this
->
apiKey
=
$
config
[
'
apiKey
'
];
if
(
isset
(
$
config
[
'
retries
'
]) ===
true
&&
$
config
[
'
retries
'
] >=
0
) {
$
this
->
retries
=
$
config
[
'
retries
'
];
}
elseif
(
isset
(
$
config
[
'
retries
'
]) ===
false
) {
$
this
->
retries
=
self
::
DEFAULT_RETRIES
;
}
elseif
(
$
config
[
'
retries
'
] <
0
) {
throw
new
ValidationException
(
'
Retries must be zero or greater.
'
,
null
,
'
shipengine
'
,
'
validation
'
,
'
invalid_field_value
'
);
}
$
timeout
=
$
config
[
'
timeout
'
];
if
(
$
timeout
instanceof
DateInterval) {
$
assert
->
isTimeoutValid
(
$
timeout
);
$
this
->
timeout
=
$
timeout
;
}
elseif
(
isset
(
$
config
[
'
timeout
'
]) ===
false
) {
$
this
->
timeout
=
new
DateInterval
(
self
::
DEFAULT_TIMEOUT
);
}
else
{
throw
new
ValidationException
(
'
Timeout is not a DateInterval.
'
,
null
,
'
shipengine
'
,
'
validation
'
,
'
invalid_field_value
'
);
}
$
this
->
baseUrl
=
$
config
[
'
baseUrl
'
] ??
self
::
DEFAULT_BASE_URI
;
$
this
->
pageSize
=
$
config
[
'
pageSize
'
] ??
self
::
DEFAULT_PAGE_SIZE
;
}
/**
* Merge in method level config into the global config used by the **ShipEngine** object.
*
* @param array|null $newConfig
* @return $this
*/
public
function
merge
(?
array
$
newConfig
=
null
):
ShipEngineConfig
{
if
(!
isset
(
$
newConfig
)) {
return
$
this
;
}
$
config
=
array
();
isset
(
$
newConfig
[
'
apiKey
'
]) ?
(
$
config
[
'
apiKey
'
] =
$
newConfig
[
'
apiKey
'
]) :
(
$
config
[
'
apiKey
'
] =
$
this
->
apiKey
);
isset
(
$
newConfig
[
'
baseUrl
'
]) ?
(
$
config
[
'
baseUrl
'
] =
$
newConfig
[
'
baseUrl
'
]) :
(
$
config
[
'
baseUrl
'
] =
$
this
->
baseUrl
);
isset
(
$
newConfig
[
'
pageSize
'
]) ?
(
$
config
[
'
pageSize
'
] =
$
newConfig
[
'
pageSize
'
]) :
(
$
config
[
'
pageSize
'
] =
$
this
->
pageSize
);
isset
(
$
newConfig
[
'
retries
'
]) ?
(
$
config
[
'
retries
'
] =
$
newConfig
[
'
retries
'
]) :
(
$
config
[
'
retries
'
] =
$
this
->
retries
);
isset
(
$
newConfig
[
'
timeout
'
]) ?
(
$
config
[
'
timeout
'
] =
$
newConfig
[
'
timeout
'
]) :
(
$
config
[
'
timeout
'
] =
$
this
->
timeout
);
return
new
ShipEngineConfig
(
$
config
);
}
/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
*/
public
function
jsonSerialize
()
{
return
[
'
apiKey
'
=>
$
this
->
apiKey
,
'
baseUrl
'
=>
$
this
->
baseUrl
,
'
pageSize
'
=>
$
this
->
pageSize
,
'
retries
'
=>
$
this
->
retries
,
'
timeout
'
=>
$
this
->
timeout
->
s
];
}
}
Back
|
FazBrowse Home
|
New Git URL