diff --git a/src/Davispeixoto/LaravelSalesforce/LaravelSalesforceServiceProvider.php b/src/Davispeixoto/LaravelSalesforce/LaravelSalesforceServiceProvider.php index 2f0f6ea..678bba5 100644 --- a/src/Davispeixoto/LaravelSalesforce/LaravelSalesforceServiceProvider.php +++ b/src/Davispeixoto/LaravelSalesforce/LaravelSalesforceServiceProvider.php @@ -1,9 +1,13 @@ -app['salesforce'] = $this->app->share(function ($app) { - return new Salesforce($app['config']); + $this->app['salesforce'] = $this->app->singleton('salesforce', function ($app) { + $sf = new Salesforce(new Client()); + $sf->connect($app['config']); + + return $sf; }); } diff --git a/src/Davispeixoto/LaravelSalesforce/Salesforce.php b/src/Davispeixoto/LaravelSalesforce/Salesforce.php index d55a891..700caec 100644 --- a/src/Davispeixoto/LaravelSalesforce/Salesforce.php +++ b/src/Davispeixoto/LaravelSalesforce/Salesforce.php @@ -2,7 +2,6 @@ use Davispeixoto\ForceDotComToolkitForPhp\SforceEnterpriseClient as Client; use Exception; -use Illuminate\Config\Repository; /** * Class Salesforce @@ -15,50 +14,59 @@ */ class Salesforce { - /** * @var Client $sfh The Salesforce Handler */ - private $sfh; + public $sfh; /** - * The constructor. + * Salesforce constructor. * + * @param Client $sfh + * @throws SalesforceException + */ + public function __construct(Client $sfh) + { + $this->sfh = $sfh; + } + + /** + * @param $method + * @param $args + * @return mixed + */ + public function __call($method, $args) + { + return call_user_func_array(array($this->sfh, $method), $args); + } + + /** * Authenticates into Salesforce according to * the provided credentials and WSDL file * - * @param Repository $configExternal + * @param $configExternal * @throws SalesforceException */ - public function __construct(Repository $configExternal) + public function connect($configExternal) { - try { - $this->sfh = new Client(); + $wsdl = $configExternal->get('salesforce.wsdl'); - $wsdl = $configExternal->get('laravel-salesforce::wsdl'); + if (empty($wsdl)) { + $wsdl = __DIR__ . '/Wsdl/enterprise.wsdl.xml'; + } - if (empty($wsdl)) { - $wsdl = __DIR__ . '/Wsdl/enterprise.wsdl.xml'; - } + $user = $configExternal->get('salesforce.username'); + $pass = $configExternal->get('salesforce.password'); + $token = $configExternal->get('salesforce.token'); + try { $this->sfh->createConnection($wsdl); - - $username = $configExternal->get('laravel-salesforce::username'); - $password = $configExternal->get('laravel-salesforce::password'); - $token = $configExternal->get('laravel-salesforce::token'); - - $this->sfh->login($username, $password . $token); - + $this->sfh->login($user, $pass . $token); } catch (Exception $e) { throw new SalesforceException('Exception at Constructor' . $e->getMessage() . "\n\n" . $e->getTraceAsString()); } } - public function __call($method, $args) - { - return call_user_func_array(array($this->sfh, $method), $args); - } - /* * Debugging functions */