AdsUser::LoadSettings PHP Method

LoadSettings() public method

Loads the settings for this client library. If the settings INI file located at $settingsIniPath cannot be loaded, then the parameters passed into this method are used.
public LoadSettings ( string $settingsIniPath, string $defaultVersion, string $defaultServer, string $defaultLogsDir, string $logsRelativePathBase )
$settingsIniPath string the path to the settings INI file
$defaultVersion string the default version if the settings INI file cannot be loaded
$defaultServer string the default server if the settings INI file cannot be loaded
$defaultLogsDir string the default logs directory if the settings INI file cannot be loaded
$logsRelativePathBase string the relative path base for the logs directory
    public function LoadSettings($settingsIniPath, $defaultVersion, $defaultServer, $defaultLogsDir, $logsRelativePathBase)
    {
        // Set no time limit for PHP operations.
        set_time_limit(0);
        ini_set('default_socket_timeout', 480);
        $settingsIni = parse_ini_file($settingsIniPath, true);
        // Logging settings.
        $pathRelative = $this->GetSetting($settingsIni, 'LOGGING', 'PATH_RELATIVE', false);
        $libLogDirPath = $this->GetSetting($settingsIni, 'LOGGING', 'LIB_LOG_DIR_PATH', $defaultLogsDir);
        $relativePath = realpath($logsRelativePathBase . '/' . $libLogDirPath);
        // User agent settings.
        $this->isIncludeUtilitiesInUserAgent = $this->GetSetting($settingsIni, 'LOGGING', 'includeUtilitiesInUserAgent', 'true');
        if ($pathRelative && $relativePath) {
            $this->logsDirectory = $relativePath;
        } elseif (!$pathRelative && $libLogDirPath) {
            $this->logsDirectory = $libLogDirPath;
        } else {
            $this->logsDirectory = $defaultLogsDir;
        }
        $this->InitLogs();
        // Server settings.
        $this->defaultVersion = $this->GetSetting($settingsIni, 'SERVER', 'DEFAULT_VERSION', $defaultVersion);
        $this->defaultServer = $this->GetSetting($settingsIni, 'SERVER', 'DEFAULT_SERVER', $defaultServer);
        // SOAP settings.
        $this->soapCompression = (bool) $this->GetSetting($settingsIni, 'SOAP', 'COMPRESSION', true);
        $this->soapCompressionLevel = $this->GetSetting($settingsIni, 'SOAP', 'COMPRESSION_LEVEL', 1);
        if ($this->soapCompressionLevel < 1 || $this->soapCompressionLevel > 9) {
            $this->soapCompressionLevel = 1;
        }
        $this->wsdlCache = (int) $this->GetSetting($settingsIni, 'SOAP', 'WSDL_CACHE', WSDL_CACHE_NONE);
        if ($this->wsdlCache < 0 || $this->wsdlCache > 3) {
            $this->wsdlCache = WSDL_CACHE_NONE;
        }
        $forceHttpVersion = $this->GetSetting($settingsIni, 'SOAP', 'FORCE_HTTP_VERSION');
        $this->forceHttpVersion = $forceHttpVersion === null ? null : (double) $forceHttpVersion;
        $forceAddXsiTypes = $this->GetSetting($settingsIni, 'SOAP', 'FORCE_ADD_XSI_TYPES');
        $this->forceAddXsiTypes = $forceAddXsiTypes === null ? false : (bool) $forceAddXsiTypes;
        // Proxy settings.
        $proxyHost = $this->GetSetting($settingsIni, 'PROXY', 'HOST');
        if (isset($proxyHost)) {
            $this->Define('HTTP_PROXY_HOST', $proxyHost);
        }
        $proxyPort = $this->GetSetting($settingsIni, 'PROXY', 'PORT');
        if (isset($proxyPort)) {
            $this->Define('HTTP_PROXY_PORT', (int) $proxyPort);
        }
        $proxyUser = $this->GetSetting($settingsIni, 'PROXY', 'USER');
        if (isset($proxyUser)) {
            $this->Define('HTTP_PROXY_USER', $proxyUser);
        }
        $proxyPassword = $this->GetSetting($settingsIni, 'PROXY', 'PASSWORD');
        if (isset($proxyPassword)) {
            $this->Define('HTTP_PROXY_PASSWORD', $proxyPassword);
        }
        // OAuth2.
        $this->oauth2Handler = $this->GetDefaultOAuth2Handler($this->GetSetting($settingsIni, 'AUTH', 'OAUTH2_HANDLER_CLASS'));
        // SSL settings.
        $sslVerifyPeer = $this->GetSetting($settingsIni, 'SSL', 'VERIFY_PEER');
        if (isset($sslVerifyPeer)) {
            $this->Define('SSL_VERIFY_PEER', $sslVerifyPeer);
        }
        $sslVerifyHost = $this->GetSetting($settingsIni, 'SSL', 'VERIFY_HOST');
        if (isset($sslVerifyHost)) {
            $this->Define('SSL_VERIFY_HOST', (int) $sslVerifyHost);
        }
        $sslCaPath = $this->GetSetting($settingsIni, 'SSL', 'CA_PATH');
        if (isset($sslCaPath)) {
            $this->Define('SSL_CA_PATH', $sslCaPath);
        }
        $sslCaFile = $this->GetSetting($settingsIni, 'SSL', 'CA_FILE');
        if (isset($sslCaFile)) {
            $this->Define('SSL_CA_FILE', $sslCaFile);
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Overrides {@link AdsUser::LoadSettings()}  
  * added settings - locale
  */
 public function LoadSettings($settingsIniPath, $defaultVersion, $defaultServer, $defaultLogsDir, $logsRelativePathBase)
 {
     $settingsIni = parse_ini_file($settingsIniPath, TRUE);
     if (isset($settingsIni)) {
         if (array_key_exists('LOCAL', $settingsIni)) {
             if (array_key_exists('DEFAULT_LOCALE', $settingsIni['LOCAL'])) {
                 $this->SetLocale($settingsIni['LOCAL']['DEFAULT_LOCALE']);
             }
         }
     }
     parent::LoadSettings($settingsIniPath, $defaultVersion, $defaultServer, $defaultLogsDir, $logsRelativePathBase);
 }