1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* The MIT License |
4
|
|
|
* |
5
|
|
|
* Copyright 2017 Julien Fastré <[email protected]>. |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in |
15
|
|
|
* all copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23
|
|
|
* THE SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
namespace PHPHealth\CDA\DataType\TextAndMultimedia; |
26
|
|
|
|
27
|
|
|
use PHPHealth\CDA\DataType\TextAndMultimedia\CharacterString; |
28
|
|
|
use PHPHealth\CDA\Elements\Paragraph; |
29
|
|
|
use PHPHealth\CDA\Elements\Table; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* A special character string which may contains narrative elements |
33
|
|
|
* |
34
|
|
|
* @author Julien Fastré <[email protected]> |
35
|
|
|
*/ |
36
|
|
|
class NarrativeString extends CharacterString |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* All the elements collected with the differents `add*` functions. |
40
|
|
|
* This array is ordered. |
41
|
|
|
* |
42
|
|
|
* @var \DOMElement[] |
43
|
|
|
*/ |
44
|
|
|
private $elements = array(); |
45
|
|
|
|
46
|
|
|
public function __construct() |
47
|
|
|
{ |
48
|
|
|
parent::__construct(''); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
private function addElement($type, $content) |
53
|
|
|
{ |
54
|
|
|
$this->elements[] = [$type, $content]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* |
59
|
|
|
* @param string $content |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function addParagraph($content) |
63
|
|
|
{ |
64
|
|
|
$this->addElement('paragraph', $content); |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* |
71
|
|
|
* @return Table |
72
|
|
|
*/ |
73
|
|
|
public function createTable() |
74
|
|
|
{ |
75
|
|
|
$table = new Table($this); |
76
|
|
|
|
77
|
|
|
$this->addElement('table', $table); |
78
|
|
|
|
79
|
|
|
return $table; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setValueToElement(\DOMElement &$el, \DOMDocument $doc = null) |
83
|
|
|
{ |
84
|
|
|
foreach ($this->elements as list($type, $element)) { |
85
|
|
|
switch ($type) |
86
|
|
|
{ |
87
|
|
|
case 'table': |
88
|
|
|
$el->appendChild($element->toDOMElement($doc)); |
89
|
|
|
break; |
90
|
|
|
case 'paragraph': |
91
|
|
|
$el->appendChild((new Paragraph($element)) |
92
|
|
|
->toDOMElement($doc)); |
|
|
|
|
93
|
|
|
break; |
94
|
|
|
default: |
95
|
|
|
// this should not happen |
96
|
|
|
throw new \LogicException(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):