Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

option to read from config. Fix php 7 issues #165

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ET_CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function __construct($clientId, $clientSecret)
public function get()
{
$now = time();
$data = ET_CacheService::$cachedSoapUrls[$this->_identifier];
$data = isset(ET_CacheService::$cachedSoapUrls[$this->_identifier]) ? ET_CacheService::$cachedSoapUrls[$this->_identifier] : null;

if (!$data || !$data->expires || $data->expires < $now) {
// remove expired data from the array
unset(ET_CacheService::$cachedSoapUrls[$this->_identifier]);
Expand Down
51 changes: 32 additions & 19 deletions src/ET_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace FuelSdk;

use \RobRichards\WsePhp\WSSESoap;
use \Firebase\JWT;
use \Firebase\JWT\JWT;

use \Datetime;
use \SoapClient;
Expand Down Expand Up @@ -95,19 +95,24 @@ class ET_Client extends SoapClient
* <i><b>proxyusername</b></i> - proxy server user name</br>
* <i><b>proxypassword</b></i> - proxy server password</br>
* <i><b>sslverifypeer</b></i> - Require verification of peer name</br>
* @param boolean $readConfig Default true, read the config.php file if it exists.
* @param string|null $configPath Read the config.php file from specific path.
*/
function __construct($getWSDL = false, $debug = false, $params = null)
function __construct($getWSDL = false, $debug = false, $params = null, $readConfig = true, $configPath = null)
{
$tenantTokens = array();
$config = false;

$this->xmlLoc = 'ExactTargetWSDL.xml';

if (file_exists(realpath("config.php")))
$config = include 'config.php';
if ($readConfig) {
$configPath = $configPath ? $configPath : realpath("config.php");
if (file_exists($configPath)) {
$config = include $configPath;
}
}

if ($config)
{
if ($config) {
$this->wsdlLoc = $config['defaultwsdl'];
$this->clientId = $config['clientid'];
$this->clientSecret = $config['clientsecret'];
Expand Down Expand Up @@ -155,7 +160,8 @@ function __construct($getWSDL = false, $debug = false, $params = null)
if (array_key_exists('proxyusername', $config)){$this->proxyUserName = $config['proxyusername'];}
if (array_key_exists('proxypassword', $config)){$this->proxyPassword = $config['proxypassword'];}
if (array_key_exists('sslverifypeer', $config)){$this->sslVerifyPeer = $config['sslverifypeer'];}
}
}

if ($params)
{
if (array_key_exists('defaultwsdl', $params)){$this->wsdlLoc = $params['defaultwsdl'];}
Expand Down Expand Up @@ -308,6 +314,7 @@ function __construct($getWSDL = false, $debug = false, $params = null)

parent::__setLocation($this->endpoint);
}

/**
* Gets the refresh token using the authentication URL.
*
Expand Down Expand Up @@ -524,21 +531,27 @@ function __doRequest($request, $location, $saction, $version, $one_way = 0)
$doc = new DOMDocument();
$doc->loadXML($request);

if($this->useOAuth2Authentication === true){
if($this->useOAuth2Authentication === true) {
$this->addOAuth($doc, $this->getAuthToken($this->tenantKey));
$content = $doc->saveXML();
}
else{
} else {
$objWSSE = new WSSESoap($doc);
$objWSSE->addUserToken("*", "*", FALSE);
$this->addOAuth($doc, $this->getInternalAuthToken($this->tenantKey));

$content = $objWSSE->saveXML();
}

if ($this->debugSOAP){
if ($this->debugSOAP) {
error_log ('FuelSDK SOAP Request: ');
error_log (str_replace($this->getInternalAuthToken($this->tenantKey),"REMOVED",$content));
error_log (str_replace($this->getInternalAuthToken($this->tenantKey), "REMOVED", $content));
}

if ('Retrieve' === $saction && false !== strpos($content, '<ns1:ObjectType>EmailSendDefinition</ns1:ObjectType>')) {
$content = str_replace('<ns1:Properties>DeliveryProfile.CusomterKey</ns1:Properties>', '', $content);
$content = str_replace('<ns1:Properties>DeliveryProfile.HeaderContentArea.ID</ns1:Properties>', '', $content);
$content = str_replace('<ns1:Properties>DeliveryProfile.FooterContentArea.ID</ns1:Properties>', '', $content);
$content = str_replace('<ns1:Properties>SendWindowCloses</ns1:Properties>', '', $content);
}

$headers = array("Content-Type: text/xml","SOAPAction: ".$saction, "User-Agent: ".ET_Util::getSDKVersion());
Expand Down Expand Up @@ -611,7 +624,7 @@ public function addOAuth( $doc, $token)
public function getAuthToken($tenantKey = null)
{
$tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;
if ($this->tenantTokens[$tenantKey] == null) {
if (!isset($this->tenantTokens[$tenantKey]) || $this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
return isset($this->tenantTokens[$tenantKey]['authToken'])
Expand All @@ -627,7 +640,7 @@ public function getAuthToken($tenantKey = null)
*/
function setAuthToken($tenantKey, $authToken, $authTokenExpiration)
{
if ($this->tenantTokens[$tenantKey] == null) {
if (!isset($this->tenantTokens[$tenantKey]) || $this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['authToken'] = $authToken;
Expand All @@ -642,7 +655,7 @@ function setAuthToken($tenantKey, $authToken, $authTokenExpiration)
function getAuthTokenExpiration($tenantKey)
{
$tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;
if ($this->tenantTokens[$tenantKey] == null) {
if (!isset($this->tenantTokens[$tenantKey]) || $this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
return isset($this->tenantTokens[$tenantKey]['authTokenExpiration'])
Expand All @@ -658,7 +671,7 @@ function getAuthTokenExpiration($tenantKey)
function getInternalAuthToken($tenantKey)
{
$tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;
if ($this->tenantTokens[$tenantKey] == null) {
if (!isset($this->tenantTokens[$tenantKey]) || $this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
return isset($this->tenantTokens[$tenantKey]['internalAuthToken'])
Expand All @@ -672,7 +685,7 @@ function getInternalAuthToken($tenantKey)
* @param string $internalAuthToken
*/
function setInternalAuthToken($tenantKey, $internalAuthToken) {
if ($this->tenantTokens[$tenantKey] == null) {
if (!isset($this->tenantTokens[$tenantKey]) || $this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['internalAuthToken'] = $internalAuthToken;
Expand All @@ -685,7 +698,7 @@ function setInternalAuthToken($tenantKey, $internalAuthToken) {
*/
function setRefreshToken($tenantKey, $refreshToken)
{
if ($this->tenantTokens[$tenantKey] == null) {
if (!isset($this->tenantTokens[$tenantKey]) || $this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['refreshToken'] = $refreshToken;
Expand All @@ -700,7 +713,7 @@ function setRefreshToken($tenantKey, $refreshToken)
public function getRefreshToken($tenantKey)
{
$tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;
if ($this->tenantTokens[$tenantKey] == null) {
if (!isset($this->tenantTokens[$tenantKey]) || $this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
return isset($this->tenantTokens[$tenantKey]['refreshToken'])
Expand Down