DfpUser::__construct PHP Method

__construct() public method

The DfpUser class can be configured in one of two ways:

  1. Using an authentication INI file
  2. Using supplied credentials

If an authentication INI file is provided and successfully loaded, those values will be used unless a corresponding parameter overwrites it. If the authentication INI file is not provided (e.g. it is null) the class will attempt to load the default authentication file at the path of "../auth.ini" relative to this file's directory. Any corresponding parameter, which is not null will however, overwrite any parameter loaded from the default INI.

Likewise, if a custom settings INI file is not provided, the default settings INI file will be loaded from the path of "../settings.ini" relative to this file's directory.

public __construct ( string $authenticationIniPath = null, string $applicationName = null, string $networkCode = null, string $settingsIniPath = null, array $oauth2Info = null )
$authenticationIniPath string the absolute path to the authentication INI or relative to the current directory (cwd). If null, the default authentication INI file will attempt to be loaded
$applicationName string the application name (required header). Will be prepended with the library name and version. Will also overwrite the applicationName entry in any INI file
$networkCode string the network code the user belongs to (optional header). Can be left null if the user only belongs to one network. Will overwrite the networkCode entry in any INI file
$settingsIniPath string the path to the settings INI file. If null, the default settings INI file will be loaded
$oauth2Info array the OAuth 2.0 information to use for requests
    public function __construct($authenticationIniPath = null, $applicationName = null, $networkCode = null, $settingsIniPath = null, $oauth2Info = null)
    {
        parent::__construct();
        $buildIniDfp = parse_ini_file(dirname(__FILE__) . '/build.ini', false);
        $buildIniCommon = parse_ini_file(dirname(__FILE__) . '/../../Common/Lib/build.ini', false);
        $this->libName = $buildIniDfp['LIB_NAME'];
        $this->libVersion = $buildIniCommon['LIB_VERSION'];
        $apiProps = ApiPropertiesUtils::ParseApiPropertiesFile(dirname(__FILE__) . '/api.properties');
        $versions = explode(',', $apiProps['api.versions']);
        $defaultVersion = $versions[count($versions) - 1];
        $defaultServer = $apiProps['api.server'];
        if ($authenticationIniPath === null) {
            $authenticationIniPath = dirname(__FILE__) . '/../auth.ini';
        }
        $authenticationIni = parse_ini_file(realpath($authenticationIniPath), true);
        $applicationName = $this->GetAuthVarValue($applicationName, self::USER_AGENT_HEADER_NAME, $authenticationIni);
        $networkCode = $this->GetAuthVarValue($networkCode, 'networkCode', $authenticationIni);
        $oauth2Info = $this->GetAuthVarValue($oauth2Info, 'OAUTH2', $authenticationIni);
        if (isset($oauth2Info['oAuth2AdditionalScopes'])) {
            $scopes = explode(',', $oauth2Info['oAuth2AdditionalScopes']);
        } else {
            $scopes = array();
        }
        $scopes[] = self::OAUTH2_SCOPE;
        $this->SetOAuth2Info($oauth2Info);
        $this->SetApplicationName($applicationName);
        $this->updateClientLibraryUserAgent($applicationName);
        $this->SetNetworkCode($networkCode);
        $this->SetScopes($scopes);
        if ($settingsIniPath === null) {
            $settingsIniPath = dirname(__FILE__) . '/../settings.ini';
        }
        $this->loadSettings($settingsIniPath, $defaultVersion, $defaultServer, getcwd(), dirname(__FILE__));
    }