From f6ab1622cb0f2acf84fc4f1713444b1646d989c6 Mon Sep 17 00:00:00 2001 From: hlu2 Date: Fri, 7 Apr 2017 11:09:30 -0700 Subject: [PATCH] Remove unnecessary config for declaring Constants --- src/Core/Configuration/LocalConfigReader.php | 222 +++++++++++------- src/Core/CoreConstants.php | 3 + .../Http/Serialization/IEntitySerializer.php | 6 +- .../Serialization/JsonObjectSerializer.php | 3 +- .../Serialization/XmlObjectSerializer.php | 11 +- src/Core/ServiceContext.php | 103 ++++---- src/DataService/DataService.php | 49 ++-- src/Diagnostics/LoggerBase.php | 4 +- src/_Samples/CustomerCreate.php | 21 +- src/config.php | 14 +- 10 files changed, 255 insertions(+), 181 deletions(-) diff --git a/src/Core/Configuration/LocalConfigReader.php b/src/Core/Configuration/LocalConfigReader.php index 97b27ae8..7a1669bd 100644 --- a/src/Core/Configuration/LocalConfigReader.php +++ b/src/Core/Configuration/LocalConfigReader.php @@ -16,7 +16,7 @@ /** - * Specifies the Default Configuration Reader implmentation used by the SDK. + * Specifies the Default Configuration Reader implmentation used by the SDK. The ConfigReader can either read a file or from passed arrays * * @hao - separate each function to its own method * @@ -76,7 +76,7 @@ class LocalConfigReader * A Customer FilePath. If different than the default sdk.config file * @return IppConfiguration The custom config object. */ - public static function ReadConfiguration($filePath = null, $OAuthOption = CoreConstants::OAUTH1) + public static function ReadConfigurationFromFile($filePath, $OAuthOption = CoreConstants::OAUTH1) { $ippConfig = new IppConfiguration(); @@ -86,7 +86,8 @@ public static function ReadConfiguration($filePath = null, $OAuthOption = CoreCo $xmlObj = simplexml_load_file($filePath); }else { - $xmlObj = simplexml_load_file(PATH_SDK_ROOT . 'sdk.config'); + // $xmlObj = simplexml_load_file(PATH_SDK_ROOT . 'sdk.config'); + throw new \Exception("Can't Read Configuration from file: ". $filePath); } LocalConfigReader::initializeOAuthSettings($xmlObj, $ippConfig, $OAuthOption); @@ -102,6 +103,38 @@ public static function ReadConfiguration($filePath = null, $OAuthOption = CoreCo } + } + + public static function ReadConfigurationFromParameters($OAuthConfig, $baseUrl, $defaultLoggingLocation = CoreConstatnts::DEFAULT_LOGGINGLOCATION, $minorVersion = 3){ + $ippConfig = new IppConfiguration(); + try { + //Set OAuth + if(isset($OAuthConfig)){ + $ippConfig->Security = $OAuthConfig; + }else{ + throw new \Exception("Empty OAuth Config from Constuct IPP Configuration on LocalConfigReader"); + } + //Set Logger and Searlization format. The default one is XML + LocalConfigReader::intializeMessage($ippConfig); + LocalConfigReader::setRequestAndResponseSerializationFormat($ippConfig, CompressionFormat::None, CompressionFormat::None, SerializationFormat::Xml, SerializationFormat::Xml); + //Set base Urls + $ippConfig->BaseUrl = new BaseUrl(); + $ippConfig->BaseUrl->Qbo = $baseUrl; + //Set content writer and logger + LocalConfigReader::setupLogger($ippConfig, $defaultLoggingLocation, "TRUE"); + LocalConfigReader::setupContentWriter($ippConfig, CoreConstants::FILE_STRATEGY, CoreConstants::PHP_CLASS_PREFIX, null, false); + //Set API Entity Rules + $rules=CoreConstants::getQuickBooksOnlineAPIEntityRules(); + LocalConfigReader::initOperationControlList($ippConfig, $rules); + //Set minor version + $ippConfig->minorVersion = $minorVersion; + + return $ippConfig; + + } catch (\Exception $e) { + throw new \Exception("Can't Config Environments from passed parameters"); + } + } /** @@ -220,10 +253,7 @@ public static function initializeOAuthSettings($xmlObj, $ippConfig, $OAuthOption * @Hao */ public static function initializeRequestAndResponseSerializationAndCompressionFormat($xmlObj, $ippConfig){ - // Initialize Request Configuration Object - $ippConfig->Message = new Message(); - $ippConfig->Message->Request = new Request(); - $ippConfig->Message->Response = new Response(); + LocalConfigReader::intializeMessage($ippConfig); $requestSerializationFormat = NULL; $requestCompressionFormat = NULL; @@ -246,76 +276,87 @@ public static function initializeRequestAndResponseSerializationAndCompressionFo $responseSerializationFormat = (string)$responseAttr->serializationFormat; $responseCompressionFormat = (string)$responseAttr->compressionFormat; } + LocalConfigReader::setRequestAndResponseSerializationFormat($ippConfig, $requestCompressionFormat, $responseCompressionFormat, $requestSerializationFormat, $responseSerializationFormat); + } + + public static function intializeMessage($ippConfig){ + // Initialize Request Configuration Object + $ippConfig->Message = new Message(); + $ippConfig->Message->Request = new Request(); + $ippConfig->Message->Response = new Response(); + } + + public static function setRequestAndResponseSerializationFormat($ippConfig, $requestCompressionFormat, $responseCompressionFormat, $requestSerializationFormat, $responseSerializationFormat){ switch ($requestCompressionFormat) { - case CompressionFormat::None: - $ippConfig->Message->Request->CompressionFormat = CompressionFormat::None; - break; - case CompressionFormat::GZip: - $ippConfig->Message->Request->CompressionFormat = CompressionFormat::GZip; - break; - case CompressionFormat::Deflate: - $ippConfig->Message->Request->CompressionFormat = CompressionFormat::Deflate; - break; - default: + case CompressionFormat::None: + $ippConfig->Message->Request->CompressionFormat = CompressionFormat::None; + break; + case CompressionFormat::GZip: + $ippConfig->Message->Request->CompressionFormat = CompressionFormat::GZip; + break; + case CompressionFormat::Deflate: + $ippConfig->Message->Request->CompressionFormat = CompressionFormat::Deflate; + break; + default: //Default compression set to None $ippConfig->Message->Request->CompressionFormat = CompressionFormat::None; - break; + break; } switch ($responseCompressionFormat) { - case CompressionFormat::None: - $ippConfig->Message->Response->CompressionFormat = CompressionFormat::None; - break; - case CompressionFormat::GZip: - $ippConfig->Message->Response->CompressionFormat = CompressionFormat::GZip; - break; - case CompressionFormat::Deflate: - $ippConfig->Message->Response->CompressionFormat = CompressionFormat::Deflate; - break; + case CompressionFormat::None: + $ippConfig->Message->Response->CompressionFormat = CompressionFormat::None; + break; + case CompressionFormat::GZip: + $ippConfig->Message->Response->CompressionFormat = CompressionFormat::GZip; + break; + case CompressionFormat::Deflate: + $ippConfig->Message->Response->CompressionFormat = CompressionFormat::Deflate; + break; default: - //Default compression set to None - $ippConfig->Message->Response->CompressionFormat = CompressionFormat::None; - break; - } - - switch ($requestSerializationFormat) - { - //case Intuit\Ipp\Utility\SerializationFormat::DEFAULT: - case SerializationFormat::Xml: - $ippConfig->Message->Request->SerializationFormat = SerializationFormat::Xml; - break; - case SerializationFormat::Json: - $ippConfig->Message->Request->SerializationFormat = SerializationFormat::Json; - break; - case SerializationFormat::Custom: - $ippConfig->Message->Request->SerializationFormat = SerializationFormat::Custom; - break; + //Default compression set to None + $ippConfig->Message->Response->CompressionFormat = CompressionFormat::None; + break; + } + + switch ($requestSerializationFormat) + { + //case Intuit\Ipp\Utility\SerializationFormat::DEFAULT: + case SerializationFormat::Xml: + $ippConfig->Message->Request->SerializationFormat = SerializationFormat::Xml; + break; + case SerializationFormat::Json: + $ippConfig->Message->Request->SerializationFormat = SerializationFormat::Json; + break; + case SerializationFormat::Custom: + $ippConfig->Message->Request->SerializationFormat = SerializationFormat::Custom; + break; default: - //Default compression set to XML - $ippConfig->Message->Request->SerializationFormat = SerializationFormat::Xml; - break; - } - - switch ($responseSerializationFormat) - { - case SerializationFormat::Xml: - $ippConfig->Message->Response->SerializationFormat = SerializationFormat::Xml; - break; - //case Intuit\Ipp\Utility\SerializationFormat::DEFAULT: - case SerializationFormat::Json: - $ippConfig->Message->Response->SerializationFormat = SerializationFormat::Json; - break; - case SerializationFormat::Custom: - $ippConfig->Message->Response->SerializationFormat = SerializationFormat::Custom; - break; + //Default compression set to XML + $ippConfig->Message->Request->SerializationFormat = SerializationFormat::Xml; + break; + } + + switch ($responseSerializationFormat) + { + case SerializationFormat::Xml: + $ippConfig->Message->Response->SerializationFormat = SerializationFormat::Xml; + break; + //case Intuit\Ipp\Utility\SerializationFormat::DEFAULT: + case SerializationFormat::Json: + $ippConfig->Message->Response->SerializationFormat = SerializationFormat::Json; + break; + case SerializationFormat::Custom: + $ippConfig->Message->Response->SerializationFormat = SerializationFormat::Custom; + break; default: //Default compression set to XML - $ippConfig->Message->Response->SerializationFormat = SerializationFormat::Xml; - break; - } + $ippConfig->Message->Response->SerializationFormat = SerializationFormat::Xml; + break; + } } /** @@ -336,38 +377,49 @@ public static function intializaeServiceBaseURLAndLogger($xmlObj, $ippConfig){ } // Initialize Logger - $ippConfig->Logger = new Logger(); - if ( isset($xmlObj) && - isset($xmlObj->intuit->ipp->logger->requestLog)) - { - $requestLogAttr = $xmlObj->intuit->ipp->logger->requestLog->attributes(); - $ippConfig->Logger->RequestLog->ServiceRequestLoggingLocation = (string)$requestLogAttr->requestResponseLoggingDirectory; - $ippConfig->Logger->RequestLog->EnableRequestResponseLogging = (string)$requestLogAttr->enableRequestResponseLogging; - }else { - throw new \Exception("Log settings is not available from Config file."); - } + if ( isset($xmlObj) && + isset($xmlObj->intuit->ipp->logger->requestLog)) + { + $requestLogAttr = $xmlObj->intuit->ipp->logger->requestLog->attributes(); + $ServiceRequestLoggingLocation = (string)$requestLogAttr->requestResponseLoggingDirectory; + $EnableRequestResponseLogging = (string)$requestLogAttr->enableRequestResponseLogging; + LocalConfigReader::setupLogger($ippConfig, $ServiceRequestLoggingLocation, $EnableRequestResponseLogging); + }else { + throw new \Exception("Log settings is not available from Config file."); + } // A developer is forced to write in the same style. // This should be refactored - $ippConfig->ContentWriter = new ContentWriterSettings(); if ( isset($xmlObj) && isset($xmlObj->intuit->ipp->contentWriter)) { $contentWriterAttr = $xmlObj->intuit->ipp->contentWriter->attributes(); - $ippConfig->ContentWriter->strategy = ContentWriterSettings::checkStrategy((string)$contentWriterAttr->strategy); - $ippConfig->ContentWriter->prefix = (string)$contentWriterAttr->prefix; - $ippConfig->ContentWriter->exportDir = $contentWriterAttr->exportDirectory - ? (string)$contentWriterAttr->exportDirectory - : null; - $ippConfig->ContentWriter->returnOject = $contentWriterAttr->returnObject - ? filter_var((string)$contentWriterAttr->returnObject, FILTER_VALIDATE_BOOLEAN) - : false; - $ippConfig->ContentWriter->verifyConfiguration(); + $strategy = ContentWriterSettings::checkStrategy((string)$contentWriterAttr->strategy); + $prefix = (string)$contentWriterAttr->prefix; + $exportDir = $contentWriterAttr->exportDirectory; + $returnOject = $contentWriterAttr->returnObject; + LocalConfigReader::setupContentWriter($ippConfig, $strategy, $prefix, $exportDir, $returnOject); }else{ throw new \Exception("Content Writer Settings is not available from Config file."); } } + public static function setupLogger($ippConfig, $ServiceRequestLoggingLocation, $EnableRequestResponseLogging) + { + $ippConfig->Logger = new Logger(); + $ippConfig->Logger->RequestLog->ServiceRequestLoggingLocation = $ServiceRequestLoggingLocation; + $ippConfig->Logger->RequestLog->EnableRequestResponseLogging = $EnableRequestResponseLogging; + } + + public static function setupContentWriter($ippConfig, $strategy, $prefix, $exportDir, $returnOject ){ + $ippConfig->ContentWriter = new ContentWriterSettings(); + $ippConfig->ContentWriter->strategy = $strategy; + $ippConfig->ContentWriter->prefix = $prefix; + $ippConfig->ContentWriter->exportDir = $exportDir ? (string)$exportDir : null; + $ippConfig->ContentWriter->returnOject = $returnOject ? filter_var($returnOject, FILTER_VALIDATE_BOOLEAN): false; + $ippConfig->ContentWriter->verifyConfiguration(); + } + /** * Creates PHP class entity from intuit name @@ -376,7 +428,7 @@ public static function intializaeServiceBaseURLAndLogger($xmlObj, $ippConfig){ */ private static function decorateEntity($name) { - return PHP_CLASS_PREFIX . $name; + return CoreConstants::PHP_CLASS_PREFIX . $name; } } diff --git a/src/Core/CoreConstants.php b/src/Core/CoreConstants.php index 40b53be4..7b501887 100644 --- a/src/Core/CoreConstants.php +++ b/src/Core/CoreConstants.php @@ -7,6 +7,9 @@ class CoreConstants { + const DEFAULT_LOGGINGLOCATION = "/tmp/IdsLogs"; + + const PHP_CLASS_PREFIX = 'IPP'; /* * All content writer strategy we support. Append this lists with new strategies */ diff --git a/src/Core/Http/Serialization/IEntitySerializer.php b/src/Core/Http/Serialization/IEntitySerializer.php index 6361f41e..c582fda3 100644 --- a/src/Core/Http/Serialization/IEntitySerializer.php +++ b/src/Core/Http/Serialization/IEntitySerializer.php @@ -1,6 +1,7 @@ overrideAsSingleNamespace='http://schema.intuit.com/finance/v3'; try { @@ -92,7 +93,7 @@ private static function PhpObjFromXml($className, $xmlStr) }else{ throw new \Exception("Can't find corresponding CLASS for className" . $className . "during unmarshall XML into POPO Object"); } - $bind = new Bind(PHP_CLASS_PREFIX); + $bind = new Bind(CoreConstants::PHP_CLASS_PREFIX); $bind->overrideAsSingleNamespace='http://schema.intuit.com/finance/v3'; $bind->bindXml($xmlStr, $phpObj); return $phpObj; @@ -150,7 +151,7 @@ private static function ParseArbitraryResultObjects($responseXml, $bLimitToOne) private static function decorateIntuitEntityToPhpClassName($intuitEntityName) { $intuitEntityName = trim($intuitEntityName); - return PHP_CLASS_PREFIX . $intuitEntityName; + return CoreConstants::PHP_CLASS_PREFIX . $intuitEntityName; } /** @@ -165,8 +166,8 @@ public static function cleanPhpClassNameToIntuitEntityName($phpClassName) //if the className has delimiters, get the last part $separetes = explode('\\', $phpClassName); $phpClassName = end($separetes); - if (0==strpos($phpClassName, PHP_CLASS_PREFIX)) - return substr($phpClassName, strlen(PHP_CLASS_PREFIX)); + if (0==strpos($phpClassName, CoreConstants::PHP_CLASS_PREFIX)) + return substr($phpClassName, strlen(CoreConstants::PHP_CLASS_PREFIX)); return NULL; } diff --git a/src/Core/ServiceContext.php b/src/Core/ServiceContext.php index 482b3765..08bbedcd 100644 --- a/src/Core/ServiceContext.php +++ b/src/Core/ServiceContext.php @@ -6,9 +6,14 @@ use QuickBooksOnline\API\Security\OAuthRequestValidator; use QuickBooksOnline\API\Diagnostics\TraceLevel; use QuickBooksOnline\API\Exception\SdkException; +use QuickBooksOnline\API\Core\Http\Compression\CompressionFormat; +use QuickBooksOnline\API\Core\Http\Serialization\SerializationFormat; +use QuickBooksOnline\API\Core\CoreConstants; + /** - * THe Service Context Class contains necessary settings for + * THe Service Context Class contains necessary settings for RestCalls + * @Hao Update the fields to be private April.2th, 2017 */ class ServiceContext { @@ -82,9 +87,15 @@ class ServiceContext * @throws InvalidTokenException If the token is invalid. * @return ServiceContext Returns ServiceContext object. */ - public function __construct($realmId, $serviceType = CoreConstants::IntuitServicesTypeQBO, $requestValidator = NULL) + private function __construct($realmId, $serviceType = CoreConstants::IntuitServicesTypeQBO, $requestValidator = NULL, $ippConfiguration = NULL) { - $this->IppConfiguration = LocalConfigReader::ReadConfiguration(); + if(isset($ippConfiguration)) + { + //$this->IppConfiguration = LocalConfigReader::ReadConfiguration(); + $this->IppConfiguration = $ippConfiguration; + }else{ + throw new \Exception("You shouldn't pass a null ippConfiguration in Current release"); + } // Validate Parameters if (empty($realmId)) @@ -108,14 +119,14 @@ public function __construct($realmId, $serviceType = CoreConstants::IntuitServic } $this->isCreateMethod = false; - $this->baseserviceURL = $this->GetBaseURL(); + $this->baseserviceURL = $this->getBaseURL(); return $this; } - public static function ConfigureFromLocalFile() + public static function ConfigureFromLocalFile($filePath) { - $localIppConfiguration = LocalConfigReader::ReadConfiguration(); + $localIppConfiguration = LocalConfigReader::ReadConfigurationFromFile($filePath); $QBORealmID = $localIppConfiguration->RealmID; if (empty($QBORealmID)) { @@ -124,13 +135,13 @@ public static function ConfigureFromLocalFile() $serviceType = CoreConstants::IntuitServicesTypeQBO; $OAuthConfig = $localIppConfiguration->Security; - $serviceContextInstance = new ServiceContext($QBORealmID, $serviceType, $OAuthConfig); + $serviceContextInstance = new ServiceContext($QBORealmID, $serviceType, $OAuthConfig, $localIppConfiguration); return $serviceContextInstance; } public static function ConfigureFromPassedArray(array $settings){ - if(empty($settings)){ + if( !isset($settings) || empty($settings)){ throw new \Exception("Empty OAuth Array passed. Can't construct ServiceContext based on Empty Array"); } @@ -160,61 +171,40 @@ public static function ConfigureFromPassedArray(array $settings){ throw new Exception("'QBORealmID' must be provided"); } + if (!isset($settings['baseUrl'])) { + throw new Exception("'baseUrl' must be provided"); + } + + + $OAuthConfig = new OAuthRequestValidator( $settings['accessTokenKey'], $settings['accessTokenSecret'], $settings['consumerKey'], $settings['consumerSecret']); $QBORealmID = $settings['QBORealmID']; + $baseURL = $settings['baseUrl']; $serviceType = CoreConstants::IntuitServicesTypeQBO; - $serviceContextInstance = new ServiceContext($QBORealmID, $serviceType, $OAuthConfig); + $IppConfiguration = LocalConfigReader::ReadConfigurationFromParameters($OAuthConfig, $baseURL, CoreConstants::DEFAULT_LOGGINGLOCATION, "3"); + $serviceContextInstance = new ServiceContext($QBORealmID, $serviceType, $OAuthConfig, $IppConfiguration); return $serviceContextInstance; } + /** * Gets the base Uri for a QBO user. * * @return string Returns the base Uri endpoint for a user. */ - public function GetBaseURL() + public function getBaseURL() { $this->IppConfiguration->Logger->RequestLog->Log(TraceLevel::Info, "Called GetBaseURL method."); - $baseurl = NULL; - - - if ($this->serviceType == CoreConstants::IntuitServicesTypeQBO) - { - if ($this->IppConfiguration && - $this->IppConfiguration->BaseUrl && - $this->IppConfiguration->BaseUrl->Qbo) - { - $baseurl = $this->IppConfiguration->BaseUrl->Qbo . implode(CoreConstants::SLASH_CHAR, array(CoreConstants::VERSION)) . CoreConstants::SLASH_CHAR; - } - - if (empty($baseurl)) - { - $baseurl = CoreConstants::QBO_BASEURL; - } - - //this.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Info, string.Format(CultureInfo.InvariantCulture, "BaseUrl set for QBD Service Type: {0}.", baseurl)); - } - else if ($this->serviceType == CoreConstants::IntuitServicesTypeIPP) - { - if ($this->IppConfiguration && - $this->IppConfiguration->BaseUrl && - $this->IppConfiguration->BaseUrl->Ipp) - { - $baseurl = $this->IppConfiguration->BaseUrl->Ipp; - } - - if (empty($baseurl)) - { - $baseurl = CoreConstants::IPP_BASEURL; - } - - //this.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Info, string.Format(CultureInfo.InvariantCulture, "BaseUrl set for Intuit Platform Service Type: {0}.", baseurl)); - } - + try + { + $baseurl = $this->IppConfiguration->BaseUrl->Qbo . implode(CoreConstants::SLASH_CHAR, array(CoreConstants::VERSION)) . CoreConstants::SLASH_CHAR; + } catch (\Exception $e){ + throw new \Excpetion("Base URL is not setup"); + } return $baseurl; } @@ -230,4 +220,25 @@ public function UsePlatformServices() public function disableSSlCheck() { $this->IppConfiguration->SSLCheckStatus = false; } + + /** + * Currently the Object serailziation and deserilization only supports XML format. + */ + public function useXml(){ + $this->$ippConfig->Message->Request->CompressionFormat = CompressionFormat::None; + $this->$ippConfig->Message->Response->CompressionFormat = CompressionFormat::None; + $this->$ippConfig->Message->Request->SerializationFormat = SerializationFormat::Xml; + $this->$ippConfig->Message->Response->SerializationFormat = SerializationFormat::Xml; + } + + /** + * Currently the Object serailziation and deserilization only supports XML format. + * To be Supported @Hao + */ + public function useJson(){ + $this->$ippConfig->Message->Request->CompressionFormat = CompressionFormat::None; + $this->$ippConfig->Message->Response->CompressionFormat = CompressionFormat::None; + $this->$ippConfig->Message->Request->SerializationFormat = SerializationFormat::Json; + $this->$ippConfig->Message->Response->SerializationFormat = SerializationFormat::Json; + } } diff --git a/src/DataService/DataService.php b/src/DataService/DataService.php index cd5c3ae8..f261a65e 100644 --- a/src/DataService/DataService.php +++ b/src/DataService/DataService.php @@ -3,6 +3,7 @@ use QuickBooksOnline\API\Core\CoreHelper; use QuickBooksOnline\API\Core\ServiceContext; +use QuickbooksOnline\API\Core\CoreConstants; use QuickBooksOnline\API\Core\Configuration\OperationControlList; use QuickBooksOnline\API\Core\HttpClients\SyncRestHandler; use QuickBooksOnline\API\Core\HttpClients\RequestParameters; @@ -10,7 +11,6 @@ use QuickBooksOnline\API\Core\Http\Serialization\SerializationFormat; use QuickBooksOnline\API\Exception\IdsException; use QuickBooksOnline\API\Exception\IdsExceptionManager; -use QuickBooksOnline\API\Core\CoreConstants; use QuickBooksOnline\API\Core\Configuration\LocalConfigReader; use QuickBooksOnline\API\Diagnostics\TraceLevel; use QuickBooksOnline\API\Diagnostics\ContentWriter; @@ -123,27 +123,38 @@ private function setupRestHandler($serviceContext){ $this->restHandler = new SyncRestHandler($serviceContext); } + /** + * PHP SDK currently only support XML for Object Serialization and Deserialization + */ + public function useXml(){ + + } /** * New Static function for static Reading from Config or Passing Array */ /** + * The config needs to include */ - public static function Configure(array $settings = NULL){ - if(empty($settings)){ - $ServiceContextFromFile = ServiceContext::ConfigureFromLocalFile(); - if (!isset($ServiceContextFromFile)) { - throw new Exception('Construct ServiceContext from File failed.'); + public static function Configure($settings){ + if(isset($settings)){ + if(is_array($settings)){ + $ServiceContextFromPassedArray = ServiceContext::ConfigureFromPassedArray($settings); + if (!isset($ServiceContextFromPassedArray)) { + throw new Exception('Construct ServiceContext from OAuthSettigs failed.'); + } + $DataServiceInstance = new DataService($ServiceContextFromPassedArray); + return $DataServiceInstance; + }else if(is_string($settings)){ + $ServiceContextFromFile = ServiceContext::ConfigureFromLocalFile($settings); + if (!isset($ServiceContextFromFile)) { + throw new Exception('Construct ServiceContext from File failed.'); + } + $DataServiceInstance = new DataService($ServiceContextFromFile); + return $DataServiceInstance; } - $DataServiceInstance = new DataService($ServiceContextFromFile); - return $DataServiceInstance; }else{ - $ServiceContextFromPassedArray = ServiceContext::ConfigureFromPassedArray($settings); - if (!isset($ServiceContextFromPassedArray)) { - throw new Exception('Construct ServiceContext from OAuthSettigs failed.'); - } - $DataServiceInstance = new DataService($ServiceContextFromPassedArray); - return $DataServiceInstance; + throw new SdkException("Passed Null to Configure method. It expects either a file path for the config file or an array containing OAuth settings and BaseURL."); } } @@ -218,7 +229,7 @@ private function getXmlFromObj($phpObj) { return FALSE; } - $php2xml = new com\mikebevz\xsd2php\Php2Xml(PHP_CLASS_PREFIX); + $php2xml = new com\mikebevz\xsd2php\Php2Xml(CoreConsants::PHP_CLASS_PREFIX); $php2xml->overrideAsSingleNamespace = 'http://schema.intuit.com/finance/v3'; try { @@ -238,7 +249,9 @@ private function getXmlFromObj($phpObj) { * @return POPO class name */ private static function decorateIntuitEntityToPhpClassName($intuitEntityName) { - return PHP_CLASS_PREFIX . $intuitEntityName; + $className = CoreConstants::PHP_CLASS_PREFIX . $intuitEntityName; + $className = trim($className); + return $className; } @@ -256,8 +269,8 @@ private static function getEntityResourceName($entity) */ private static function cleanPhpClassNameToIntuitEntityName($phpClassName) { $phpClassName = self::removeNameSpaceFromPhpClassName($phpClassName); - if (0 == strpos($phpClassName, PHP_CLASS_PREFIX)) - return substr($phpClassName, strlen(PHP_CLASS_PREFIX)); + if (0 == strpos($phpClassName, CoreConstants::PHP_CLASS_PREFIX)) + return substr($phpClassName, strlen(CoreConstants::PHP_CLASS_PREFIX)); return NULL; } diff --git a/src/Diagnostics/LoggerBase.php b/src/Diagnostics/LoggerBase.php index 3c3f1646..75e5879f 100644 --- a/src/Diagnostics/LoggerBase.php +++ b/src/Diagnostics/LoggerBase.php @@ -1,6 +1,6 @@ 'oauth1', - 'consumerKey' => "qyprdUSoVpIHrtBp0eDMTHGz8UXuSz", - 'consumerSecret' => "TKKBfdlU1I1GEqB9P3AZlybdC8YxW5qFSbuShkG7", - 'accessTokenKey' => "lvprdePgDHR4kSxxC7KFb8sy84TjQMVJrbITqyeaRAwBrLuq", - 'accessTokenSecret' => "VRm1nrr17JL1RhPAFGgEjepxWeSUbGGsOwsjrKLP", - 'QBORealmID' => "123145812836282" -)); -*/ -/*$dataService = DataService::Configure(array( +$dataService = DataService::Configure(array( 'auth_mode' => 'oauth1', 'consumerKey' => "lve2eZN6ZNBrjN0Wp26JVYJbsOOFbF", 'consumerSecret' => "fUhPIeu6jrq1UmNGXSMsIsl0JaHuHzSkFf3tsmrW", 'accessTokenKey' => "qye2etcpyquO3B1t8ydZJI8OTelqJCMiLZlY5LdX7qZunwoo", 'accessTokenSecret' => "2lEUtSEIvXf64CEkMLaGDK5rCwaxE9UvfW1dYrrH", - 'QBORealmID' => "193514489870599" + 'QBORealmID' => "193514489870599", + 'baseUrl' => "https://qbonline-e2e.api.intuit.com/" )); -*/ + if (!$dataService) exit("Problem while initializing DataService.\n"); diff --git a/src/config.php b/src/config.php index 127d94c3..87500cc9 100644 --- a/src/config.php +++ b/src/config.php @@ -9,15 +9,15 @@ */ // Determine parent path for SDK, which is the directory "sdk" -$sdkDir = __DIR__ . DIRECTORY_SEPARATOR; +//$sdkDir = __DIR__ . DIRECTORY_SEPARATOR; -if (!defined('PATH_SDK_ROOT')) - define('PATH_SDK_ROOT', $sdkDir); +//if (!defined('PATH_SDK_ROOT')) + //define('PATH_SDK_ROOT', $sdkDir); // Specify POPO class path; typically a direct child of the SDK path -if (!defined('POPO_CLASS_PATH')) - define('POPO_CLASS_PATH', $sdkDir . 'Data' . DIRECTORY_SEPARATOR); +//if (!defined('POPO_CLASS_PATH')) +// define('POPO_CLASS_PATH', $sdkDir . 'Data' . DIRECTORY_SEPARATOR); // PSR-4 Autoloader,QuickBooksOnline\Data; spl_autoload_register(function ($class) { @@ -75,5 +75,5 @@ // Specify the prefix pre-pended to POPO class names. If you modify this value, you // also need to rebuild the POPO classes, with the same prefix -if (!defined('PHP_CLASS_PREFIX')) - define('PHP_CLASS_PREFIX','IPP'); +//if (!defined('PHP_CLASS_PREFIX')) +// define('PHP_CLASS_PREFIX','IPP');