This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlText.php
71 lines (54 loc) · 1.5 KB
/
XmlText.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Tienvx\PactPhpXml;
use Tienvx\PactPhpXml\Model\Matcher\Generator;
use Tienvx\PactPhpXml\Model\Matcher\Matcher;
class XmlText
{
private string|int|float $content;
private ?Matcher $matcher = null;
private ?Generator $generator = null;
public function __construct(callable ...$options)
{
array_walk($options, fn (callable $option) => $option($this));
}
public function setContent(string|int|float $content): self
{
$this->content = $content;
return $this;
}
public function setMatcher(?Matcher $matcher): self
{
$this->matcher = $matcher;
return $this;
}
public function setGenerator(?Generator $generator): self
{
$this->generator = $generator;
return $this;
}
/**
* @return array<string, mixed>
*/
public function getArray(): array
{
$result = $this->getBaseArray();
if ($this->matcher) {
$result['matcher'] = $this->matcher->getArray();
}
if ($this->generator) {
$generator = $this->generator->getArray();
$result['pact:generator:type'] = $generator['pact:generator:type'];
$result['matcher'] += array_diff_key($generator, array_flip(['pact:generator:type']));
}
return $result;
}
/**
* @return array<string, mixed>
*/
private function getBaseArray(): array
{
return [
'content' => $this->content,
];
}
}