Skip to content

Commit 07480bf

Browse files
committed
Adds the ability to create a custom configuration with defined values
1 parent b75182a commit 07480bf

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
namespace SoapBox\SignedRequests\Configurations;
4+
5+
class CustomConfiguration implements Configuration
6+
{
7+
/**
8+
* The algorithm header to return.
9+
*
10+
* @var string
11+
*/
12+
protected $algorithmHeader;
13+
14+
/**
15+
* The signature header to return.
16+
*
17+
* @var string
18+
*/
19+
protected $signatureHeader;
20+
21+
/**
22+
* The signing algorithm to return.
23+
*
24+
* @var string
25+
*/
26+
protected $signingAlgorithm;
27+
28+
/**
29+
* The signing key to return.
30+
*
31+
* @var string
32+
*/
33+
protected $signingKey;
34+
35+
/**
36+
* Sets up our custom configuration with various properties.
37+
*
38+
* @param string $algorithmHeader
39+
* The algorithm header to use.
40+
* @param string $signatureHeader
41+
* The signature header to use.
42+
* @param string $signingAlgorithm
43+
* The signing algorithm to use.
44+
* @param string $signingKey
45+
* The signing key to use.
46+
*/
47+
public function __construct(
48+
string $algorithmHeader,
49+
string $signatureHeader,
50+
string $signingAlgorithm,
51+
string $signingKey
52+
) {
53+
$this->algorithmHeader = $algorithmHeader;
54+
$this->signatureHeader = $signatureHeader;
55+
$this->signingAlgorithm = $signingAlgorithm;
56+
$this->signingKey = $signingKey;
57+
}
58+
59+
/**
60+
* Returns the name of the header that will contain the algorithm used to
61+
* sign the request.
62+
*
63+
* @return string
64+
*/
65+
public function getAlgorithmHeader(): string
66+
{
67+
return $this->algorithmHeader;
68+
}
69+
70+
/**
71+
* Returns the name of the header that will contain the generated signature.
72+
*
73+
* @return string
74+
*/
75+
public function getSignatureHeader(): string
76+
{
77+
return $this->signatureHeader;
78+
}
79+
80+
/**
81+
* Returns the algorithm to use to generate the signature.
82+
*
83+
* @return string
84+
*/
85+
public function getSigningAlgorithm(): string
86+
{
87+
return $this->signingAlgorithm;
88+
}
89+
90+
/**
91+
* Returns the key to sign the request with.
92+
*
93+
* @return string
94+
*/
95+
public function getSigningKey(): string
96+
{
97+
return $this->signingKey;
98+
}
99+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Tests\Configurations;
4+
5+
use Tests\TestCase;
6+
use SoapBox\SignedRequests\Configurations\CustomConfiguration;
7+
8+
class CustomConfigurationTest extends TestCase
9+
{
10+
/**
11+
* @test
12+
*/
13+
function it_returns_the_set_values_when_requested()
14+
{
15+
$algorithmHeader = 'a';
16+
$signatureHeader = 's';
17+
$signingAlgorithm = 'sa';
18+
$signingKey = 'sk';
19+
20+
$configuration = new CustomConfiguration(
21+
$algorithmHeader,
22+
$signatureHeader,
23+
$signingAlgorithm,
24+
$signingKey
25+
);
26+
27+
$this->assertSame($algorithmHeader, $configuration->getAlgorithmHeader());
28+
$this->assertSame($signatureHeader, $configuration->getSignatureHeader());
29+
$this->assertSame($signingAlgorithm, $configuration->getSigningAlgorithm());
30+
$this->assertSame($signingKey, $configuration->getSigningKey());
31+
}
32+
}

0 commit comments

Comments
 (0)