Skip to content

Commit

Permalink
Automatic install return ApiContext and only save when needed. (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Apr 6, 2018
1 parent 81425fd commit c2c5778
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Util/InstallationUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,18 @@ public static function interactiveInstall()

/**
* @param BunqEnumApiEnvironmentType $environmentType
* @param string $contextFileName
* @param string|null $contextFileName
* @param string|null $apiKey
* @param bool $saveToConfFile
*
* @return ApiContext
*/
public static function automaticInstall(
BunqEnumApiEnvironmentType $environmentType,
string $contextFileName,
string $apiKey = null
) {
string $contextFileName = null,
string $apiKey = null,
bool $saveToConfFile = false
): ApiContext {
try {
$context = static::createApiContextWithoutConstructor();

Expand Down Expand Up @@ -166,11 +170,11 @@ public static function automaticInstall(
);
$methodInitializeSessionContext->invoke($context);

if ($contextFileName === null) {
$context->save();
} else {
if (!$contextFileName === null && $saveToConfFile) {
$context->save($contextFileName);
}

return $context;
} catch (BunqException $exception) {
echo sprintf(self::ERROR_BUNQ_EXCEPTION, $exception->getMessage());
var_dump($exception);
Expand Down

0 comments on commit c2c5778

Please sign in to comment.