From da999b4b077432337c8d3ab141909cdd5683b9e7 Mon Sep 17 00:00:00 2001 From: zushi Date: Thu, 31 Aug 2023 15:05:10 +0900 Subject: [PATCH] =?UTF-8?q?add=20:=20production=E3=83=A2=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=81=B8=E3=81=AE=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Api/AbstractApi.php | 4 +++- src/MfkApi.php | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Api/AbstractApi.php b/src/Api/AbstractApi.php index 1a65d0e..c28955b 100644 --- a/src/Api/AbstractApi.php +++ b/src/Api/AbstractApi.php @@ -30,9 +30,11 @@ abstract class AbstractApi "sandbox" => "https://sandbox-api.mfkessai.co.jp/v2/" ]; - public function __construct($client) + public function __construct($client, $env) { $this->client = $client; + if ($env === "prodcution" || $env === "sandbox") $this->env = $env; + else if ($env !== null) throw new \Exception("Uncorrect env value. please select from production or sandbox."); } /** diff --git a/src/MfkApi.php b/src/MfkApi.php index b3f5948..9636d1a 100644 --- a/src/MfkApi.php +++ b/src/MfkApi.php @@ -33,12 +33,20 @@ class MfkApi */ protected static $client; + /** + * API ENV production|sandbox + * + * @var production|sandbox + */ + protected $env; + /** * @param string $apikey * @return $this */ - public function __construct(string $apikey) + public function __construct(string $apikey, $env = null) { + $this->env = $env; if (null === self::$client) { self::$client = new Client( [ @@ -68,7 +76,7 @@ public function __call($method, $args) throw new Exception("Class $fullClassName does not exist."); if (!isset(self::$instances[$fullClassName])) - self::$instances[$fullClassName] = new $fullClassName(self::$client); + self::$instances[$fullClassName] = new $fullClassName(self::$client, $this->env); return self::$instances[$fullClassName]; }