Skip to content

Commit b0d703d

Browse files
Supporting the region bases data fetch
1 parent ad81c65 commit b0d703d

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/*
3+
* Constants for the SDK
4+
* */
5+
namespace Contentstack\Contentstackregion;
6+
7+
// Domain relevant constants
8+
define('Europe', 'eu');
9+
define('US', 'us');

src/lib/models/stack.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_once __DIR__."/assets.php";
1010
//require_once __DIR__."/asset.php";
1111
require_once __DIR__."/../../config/index.php";
12+
require_once __DIR__."/contentstackregion.php";
1213

1314
/*
1415
* Stack Class to initialize the provided parameter Stack
@@ -28,8 +29,13 @@ class Stack {
2829
/*
2930
* Constructor of the Stack
3031
* */
31-
public function __construct($api_key = '', $access_token = '', $environment = '') {
32-
$this->header = Utility\validateInput('stack', array('api_key' => $api_key, 'access_token' => $access_token, 'environment' => $environment));
32+
public function __construct($api_key = '', $access_token = '', $environment = '', $region = '') {
33+
34+
35+
if($region && $region =="Europe") {
36+
$this->host = Europe.'-'.HOST ;
37+
}
38+
$this->header = Utility\validateInput('stack', array('api_key' => $api_key, 'access_token' => $access_token, 'environment' => $environment, 'region' => $region));
3339
$this->environment = $this->header['environment'];
3440
unset($this->header['environment']);
3541
return $this;

src/lib/utility.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ function validateInput($type = '', $input = array()) {
2222
try {
2323
switch ($type) {
2424
case 'stack' :
25+
if($input['region']) {
26+
if(!(isKeySet($input,'api_key') && isKeySet($input, 'access_token') && isKeySet($input, 'environment') && isKeySet($input, 'region')))
27+
$msg = 'Please provide valid api_key, access_token, environment and region';
28+
break;
29+
} else {
2530
if(!(isKeySet($input,'api_key') && isKeySet($input, 'access_token') && isKeySet($input, 'environment')))
2631
$msg = 'Please provide valid api_key, access_token and environment';
2732
break;
33+
}
34+
2835
case 'port' :
2936
if(isEmpty($input) || !is_numeric($input))
3037
$msg = 'Please provide valid string for '.$type;

0 commit comments

Comments
 (0)