Completed
Pull Request — master (#15)
by
unknown
03:16
created

Salesforce::connect()   A

Complexity

Conditions 3
Paths 6

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 3
eloc 12
nc 6
nop 1
1
<?php namespace Davispeixoto\LaravelSalesforce;
2
3
use Davispeixoto\ForceDotComToolkitForPhp\SforceEnterpriseClient as Client;
4
use Exception;
5
6
/**
7
 * Class Salesforce
8
 *
9
 * Provides an easy binding to Salesforce
10
 * on Laravel 4 applications through SOAP
11
 * Data Integration.
12
 *
13
 * @package Davispeixoto\LaravelSalesforce
14
 */
15
class Salesforce
16
{
17
    /**
18
     * @var Client $sfh The Salesforce Handler
19
     */
20
    public $sfh;
21
22
    /**
23
     * Salesforce constructor.
24
     *
25
     * @param Client $sfh
26
     * @throws SalesforceException
27
     */
28
    public function __construct(Client $sfh)
29
    {
30
        $this->sfh = $sfh;
31
    }
32
33
    /**
34
     * @param $method
35
     * @param $args
36
     * @return mixed
37
     */
38
    public function __call($method, $args)
39
    {
40
        return call_user_func_array(array($this->sfh, $method), $args);
41
    }
42
43
    /**
44
     * Authenticates into Salesforce according to
45
     * the provided credentials and WSDL file
46
     *
47
     * @param $configExternal
48
     * @throws SalesforceException
49
     */
50
    public function connect($configExternal)
51
    {
52
        $wsdl = $configExternal->get('salesforce.wsdl');
53
54
        if (empty($wsdl)) {
55
            $wsdl = __DIR__ . '/Wsdl/enterprise.wsdl.xml';
56
        }
57
58
        $user = $configExternal->get('salesforce.username');
59
        $pass = $configExternal->get('salesforce.password');
60
        $token = $configExternal->get('salesforce.token');
61
62
        try {
63
            $this->sfh->createConnection($wsdl);
64
            $this->sfh->login($user, $pass . $token);
65
        } catch (Exception $e) {
66
            throw new SalesforceException('Exception at Constructor' . $e->getMessage() . "\n\n" . $e->getTraceAsString());
67
        }
68
    }
69
70
    /*
71
     * Debugging functions
72
     */
73
74
    /**
75
     * @return mixed
76
     */
77
    public function dump()
78
    {
79
        return print_r($this, true);
80
    }
81
}
82