From c2c5778ffaae90b65185c6e51b49b0ae78ed12f5 Mon Sep 17 00:00:00 2001 From: Kevin Hellemun Date: Fri, 6 Apr 2018 11:11:43 +0200 Subject: [PATCH] Automatic install return ApiContext and only save when needed. (bunq/sdk_php#126) --- src/Util/InstallationUtil.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Util/InstallationUtil.php b/src/Util/InstallationUtil.php index a03b22fa..bd69c63b 100644 --- a/src/Util/InstallationUtil.php +++ b/src/Util/InstallationUtil.php @@ -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(); @@ -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);