Skip to content

Commit 19a4f48

Browse files
authored
Merge pull request #48 from anthonysterling/fix/issue-46
Nest payload for forwarding_url page rule action in value block
2 parents 9c56941 + 3585dde commit 19a4f48

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/Configurations/PageRulesActions.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ public function setForwardingURL(int $statusCode, string $forwardingUrl)
132132
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
133133
}
134134

135-
$this->addConfigurationOption('forwarding_url', [
136-
'status_code' => $statusCode,
137-
'url' => $forwardingUrl,
135+
$this->addConfigurationOption("forwarding_url", [
136+
'value' => [
137+
'status_code' => $statusCode,
138+
'url' => $forwardingUrl,
139+
],
138140
]);
139141
}
140142

@@ -299,9 +301,19 @@ public function getArray(): array
299301

300302
private function addConfigurationOption(string $setting, array $configuration)
301303
{
304+
/**
305+
* Transforms an, optionally nested, array in to a collection of
306+
* stdClass objects.
307+
*
308+
* @var array $array
309+
*/
310+
$getArrayAsObject = function (array $array) {
311+
return json_decode(json_encode($array));
312+
};
313+
302314
$configuration['id'] = $setting;
303315

304-
$this->configs[] = (object) $configuration;
316+
array_push($this->configs, $getArrayAsObject($configuration));
305317
}
306318

307319
private function getBoolAsOnOrOff(bool $value): string
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
use Cloudflare\API\Configurations\PageRulesActions;
3+
4+
class PageRulesActionTest extends TestCase
5+
{
6+
public function testForwardingURLConfigurationIsApplied()
7+
{
8+
$identifier = 'forwarding_url';
9+
$statusCode = 301;
10+
$forwardingURL = 'https://www.example.org/';
11+
12+
$actions = new PageRulesActions();
13+
$actions->setForwardingURL($statusCode, $forwardingURL);
14+
$configuration = $actions->getArray();
15+
16+
$this->assertCount(1, $configuration);
17+
$this->assertEquals($identifier, $configuration[0]->id);
18+
$this->assertEquals($statusCode, $configuration[0]->value->status_code);
19+
$this->assertEquals($forwardingURL, $configuration[0]->value->url);
20+
}
21+
}

0 commit comments

Comments
 (0)