-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathClientBuilder.php
More file actions
66 lines (57 loc) · 1.54 KB
/
ClientBuilder.php
File metadata and controls
66 lines (57 loc) · 1.54 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
<?php
namespace Phpforce\SoapClient;
use Phpforce\SoapClient\Soap\SoapClientFactory;
use Phpforce\SoapClient\Plugin\LogPlugin;
use Psr\Log\LoggerInterface;
/**
* Salesforce SOAP client builder
*
* @author David de Boer <david@ddeboer.nl>
*/
class ClientBuilder
{
protected $log;
/**
* Construct client builder with required parameters
*
* @param string $wsdl Path to your Salesforce WSDL
* @param string $username Your Salesforce username
* @param string $password Your Salesforce password
* @param string $token Your Salesforce security token
*/
public function __construct($wsdl, $username, $password, $token)
{
$this->wsdl = $wsdl;
$this->username = $username;
$this->password = $password;
$this->token = $token;
}
/**
* Enable logging
*
* @param LoggerInterface $log Logger
*
* @return ClientBuilder
*/
public function withLog(LoggerInterface $log)
{
$this->log = $log;
return $this;
}
/**
* Build the Salesforce SOAP client
*
* @return Client
*/
public function build()
{
$soapClientFactory = new SoapClientFactory();
$soapClient = $soapClientFactory->factory($this->wsdl);
$client = new Client($soapClient, $this->username, $this->password, $this->token);
if ($this->log) {
$logPlugin = new LogPlugin($this->log);
$client->getEventDispatcher()->addSubscriber($logPlugin);
}
return $client;
}
}