Skip to content

Commit

Permalink
add : productionモードへの対応
Browse files Browse the repository at this point in the history
  • Loading branch information
zushiK committed Aug 31, 2023
1 parent 7356492 commit da999b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

/**
Expand Down
12 changes: 10 additions & 2 deletions src/MfkApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down Expand Up @@ -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];
}
Expand Down

0 comments on commit da999b4

Please sign in to comment.