Skip to content

Commit 2802612

Browse files
committed
Merge branch 'feature/content-branching' into feature/live-preview
2 parents b9a4050 + 9750bb7 commit 2802612

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

src/Contentstack.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class Contentstack
4646
public static function Stack($api_*** = '',
4747
$access_token = '',
4848
$environment = '',
49-
$config = array('region'=> '', 'live_preview' => array('enable' => false, 'host' => 'api.contentstack.io'))
49+
$config = array('region'=> '', 'branch'=> '', 'live_preview' => array('enable' => false, 'host' => 'api.contentstack.io'))
5050
) {
5151
return new Stack($api_***, $access_token, $environment, $config);
5252
}

src/Stack/BaseQuery.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,23 @@ public function includeFallback()
307307

308308
return $this->queryObject;
309309
}
310+
311+
/**
312+
* To include branch of publish content.
313+
*
314+
* @return Query
315+
*/
316+
public function includeBranch()
317+
{
318+
$this->queryObject->_query = call_user_func(
319+
'contentstackAddBoolean',
320+
'include_branch',
321+
$this->queryObject->_query
322+
);
323+
324+
return $this->queryObject;
325+
}
326+
310327
/**
311328
* To include schema along with entries
312329
*

src/Stack/Stack.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(
5555
$api_*** = '',
5656
$delivery_token = '',
5757
$environment = '',
58-
$config = array('region'=> '', 'live_preview' => array())
58+
$config = array('region'=> '', 'branch'=> '', 'live_preview' => array())
5959
) {
6060

6161
if ($config && $config !== "undefined" && array_***_exists('region', $config) && $config['region'] !== "undefined" && $config['region'] =="eu" ) {
@@ -65,7 +65,8 @@ public function __construct(
6565
'stack', array('api_***' => $api_***,
6666
'access_token' => $delivery_token,
6767
'environment' => $environment,
68-
'region' => $config['region'] ?? '')
68+
'region' => $config['region'] ?? '',
69+
'branch' => $config['branch'] ?? '')
6970
);
7071
$this->environment = $this->header['environment'];
7172
unset($this->header['environment']);
@@ -225,7 +226,7 @@ public function getPort()
225226
/**
226227
* This function sets API Key.
227228
*
228-
* @param string $api_*** - Name of Environment
229+
* @param string $api_*** - API Key
229230
*
230231
* @return Stack
231232
* */
@@ -238,7 +239,7 @@ public function setAPIKEY($api_*** = '')
238239
/**
239240
* This function sets Delivery Token.
240241
*
241-
* @param string $delivery_token - Name of Environment
242+
* @param string $delivery_token - Delivery Token
242243
*
243244
* @return Stack
244245
* */
@@ -291,6 +292,31 @@ public function getEnvironment()
291292
return $this->environment;
292293
}
293294

295+
296+
/**
297+
* This function sets Branch.
298+
*
299+
* @param string $branch - Name of branch
300+
*
301+
* @return Stack
302+
* */
303+
public function setBranch($branch = '')
304+
{
305+
Utility::validateInput('branch', $branch);
306+
$this->header['branch'] = $branch;
307+
return $this;
308+
}
309+
310+
/**
311+
* This function returns Branch.
312+
*
313+
* @return string
314+
* */
315+
public function Branch()
316+
{
317+
return $this->header['branch'];
318+
}
319+
294320
/**
295321
* This call returns comprehensive information of all
296322
* the content types available in a particular stack in your account.

src/Support/Utility.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ public static function contentstackRequest($queryObject = '', $type = '')
395395
}else {
396396
$request_headers[] = 'access_token: '.$Headers["access_token"];
397397
}
398+
if ($Headers["branch"] !== '' && $Headers["branch"] !== "undefined") {
399+
$request_headers[] = 'branch: '.$Headers["branch"];
400+
}
398401
curl_setopt($http, CURLOPT_HTTPHEADER, $request_headers);
399402

400403
curl_setopt($http, CURLOPT_HEADER, false);

0 commit comments

Comments
 (0)