Passed
Push — master ( 9861bf...8a602a )
by Nicholas
01:34
created

ApiTrait::getWSSHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nickcheek\Atdconnect\Traits;
4
5
use SoapClient;
6
7
trait ApiTrait {
8
9
	private $config; 
10
	private $wsshead;
11
    
12
13
    public  function apiCall($call,$query,$service)
14
    {
15
    	$config = include(realpath(dirname(__FILE__) . '/../config/config.php'));
16
    	$this->wsshead = $this->getWSSHeader($config->user, $config->pass, $config->client);
17
        $client     = new \SoapClient($service);
18
        $client->__setSoapHeaders($this->wsshead);
19
        $response 	= $client->$call($query);
20
        return $response;
21
    }   
22
    
23
    public  function getWSSHeader($user, $pass, $client)
24
    {
25
        $xml = '
26
		<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
27
		    <wsse:UsernameToken atd:clientId="' . $client . '" xmlns:atd="http://api.atdconnect.com/atd">
28
		        <wsse:Username>' . $user . '</wsse:Username>
29
		        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' . $pass . '</wsse:Password>
30
		    </wsse:UsernameToken>
31
		</wsse:Security>
32
		';
33
        
34
        return new \SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', new \SoapVar($xml, XSD_ANYXML), true);
35
    }
36
    
37
}
38