-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathBaseClient.php
71 lines (61 loc) · 1.8 KB
/
BaseClient.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
<?php namespace DivideBV\Postnl;
use SoapClient;
/**
* Internal functionality common to all clients.
*/
abstract class BaseClient extends SoapClient
{
/**
* @var string The URL of the production WSDL.
*
* Actual clients must define this.
*/
const PRODUCTION_WSDL = '';
/**
* @var string The URL of the sandbox WSDL. Actual clients must define this.
*/
const SANDBOX_WSDL = '';
/**
* @var array A list of complex types for generating a SoapClient classmap.
*
* @see self::getClassmap()
*/
protected $classes = [];
/**
* @param string $apikey
* The authorization API key.
* @param bool $sandbox
* Whether to use the production or sandbox environment. Defaults to
* production.
* @param string $wsdl
* The URL of the WSDL file to use, if not production or sandbox.
*/
public function __construct($apikey, $sandbox = false, $wsdl = null)
{
// If no WSDL is provided, use either the sandbox or production WSDL.
if (!$wsdl) {
$wsdl = $sandbox ? static::SANDBOX_WSDL : static::PRODUCTION_WSDL;
}
parent::__construct($wsdl, [
'classmap' => $this->getClassmap(),
'trace' => true,
'stream_context' => stream_context_create([
'http' => [
'header' => "apikey: $apikey",
],
]),
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
]);
}
/**
* @return array The classmap generated from self::$classes.
*/
protected function getClassmap()
{
$classmap = [];
foreach ($this->classes as $class) {
$classmap[$class] = "DivideBV\\Postnl\\ComplexTypes\\{$class}";
}
return $classmap;
}
}