-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathHasContent.php
More file actions
55 lines (45 loc) · 968 Bytes
/
HasContent.php
File metadata and controls
55 lines (45 loc) · 968 Bytes
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
<?php
declare(strict_types=1);
namespace Saloon\XmlWrangler\Traits;
use Saloon\XmlWrangler\Data\Element;
trait HasContent
{
/**
* Content
*
* @var mixed|null
*/
protected mixed $content = null;
/**
* Set content on the tag
*
* @return $this
*/
public function setContent(mixed $content): static
{
$this->content = $content;
return $this;
}
/**
* Get the content
*/
public function getContent(): mixed
{
return $this->content;
}
/**
* Recursively convert element into values
*/
public function values(): array|string
{
$content = $this->getContent();
if (is_array($content)) {
foreach ($content as $key => $value) {
if ($value instanceof Element) {
$content[$key] = $value->values();
}
}
}
return $content;
}
}