Source of file MySalesforcePartnerApiConnectionOnly.php
Size: 3,240 Bytes - Last Modified: 2021-12-23T10:46:09+00:00
/var/www/docs.ssmods.com/process/src/code/Api/MySalesforcePartnerApiConnectionOnly.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | <?php use SForce\Wsdl\create; class MySalesforcePartnerApiConnectionOnly extends Object { protected static $my_connection = null; protected static $my_soap_client = null; private static $username = ''; private static $password = ''; private static $security_token = ''; private static $wsdl_location = ''; public static function singleton() { self::$my_connection = self::create_from_cache(); if (! self::$my_connection) { // Get details from yml $wsdlLocation = Director::baseFolder() . '/' . self::config()->wsdl_location; $username = self::config()->username; $password = self::config()->password . self::config()->security_token; // Create connection self::$my_connection = new MySalesforcePartnerApi(); self::$my_soap_client = self::$my_connection->createConnection($wsdlLocation); self::$my_connection->login( $username, $password ); // Save connection cache $cache = SS_Cache::factory(self::class); $cache->save(self::$my_connection->getLocation(), 'location'); $cache->save(self::$my_connection->getSessionId(), 'sessionId'); } return self::$my_connection; } public static function debug($showSessionID = false) { $xml = self::$my_soap_client->__getLastRequest(); $domxml = new \DOMDocument('1.0'); $domxml->preserveWhiteSpace = false; $domxml->formatOutput = true; /** @var SimpleXMLElement $xml */ $domxml->loadXML($xml); if ($showSessionID === false) { $list = $domxml->getElementsByTagName('sessionId'); foreach ($list as $domElement) { $domElement->nodeValue = '--- hidden for security reasons ---'; } } return $domxml->saveXML(); } protected static function create_from_cache() { $sessionData = self::retrieve_cache_data(); if (empty($sessionData)) { return null; } $location = $sessionData['location']; $sessionId = $sessionData['sessionId']; if (! $location || ! $sessionId) { return null; } $sessionHeader = new SForce\Wsdl\SessionHeader($sessionId); if (empty($sessionHeader)) { return null; } // Use SforceEnterpriseClient or SforcePartnerClient as appropriate $wsdlLocation = Director::baseFolder() . '/' . self::config()->wsdl_location; // Get from cache self::$my_connection = new MySalesforcePartnerApi(); self::$my_connection->createConnection($wsdlLocation); self::$my_connection->setEndpoint($location); self::$my_connection->setSessionHeader($sessionHeader); return self::$my_connection; } protected static function retrieve_cache_data() { $cache = SS_Cache::factory(self::class); $location = $cache->load('location'); $sessionId = $cache->load('sessionId'); return [ 'location' => $location, 'sessionId' => $sessionId, ]; } } |