Skip to content

Commit 80f1aec

Browse files
authored
Merge pull request #92 from allforme3/master
Support for multilines in FieldValue
2 parents 65ad7f9 + ccebc30 commit 80f1aec

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

src/DataFields.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,34 @@ private function parseData($dataString)
6666
{
6767
$output = array();
6868
$field = array();
69+
$currentField = "";
6970
foreach (explode("\n", $dataString) as $line) {
7071
$trimmedLine = trim($line);
71-
if ($trimmedLine === '---' || $trimmedLine === '') {
72+
73+
// ($trimmedLine === '' && $currentField != 'FieldValue')
74+
// Don't start new field for an empty line in a multi-line FieldValue
75+
if ($trimmedLine === '---' || ($currentField !== 'FieldValue' && $trimmedLine === '')) {
7276
// Block completed; process it
7377
if (sizeof($field) > 0) {
7478
$output[] = $field;
7579
}
7680
$field = array();
7781
continue;
7882
}
83+
7984
// Process contents of data block
8085
$parts = explode(':', $line);
8186
$key = null;
8287
$value = null;
8388

89+
//Continue through lines already processed from FieldValue
90+
if($currentField === 'FieldValue'
91+
&& $parts[0] !== 'FieldJustification'
92+
&& !empty($field['FieldValue'])){
93+
94+
continue;
95+
}
96+
8497
// Handle colon in the value
8598
if (sizeof($parts) !== 2) {
8699
$key = $parts[0];
@@ -90,6 +103,13 @@ private function parseData($dataString)
90103

91104
$key = $key ?: trim($parts[0]);
92105
$value = $value ?: trim($parts[1]);
106+
107+
if ($currentField === 'FieldValue' && !empty($value)) {
108+
$value = $this->getFieldValue($line,$dataString);
109+
} else if ($currentField === 'FieldValue'){
110+
$value = "";
111+
}
112+
93113
if (isset($field[$key])) {
94114
$field[$key] = (array) $field[$key];
95115
$field[$key][] = $value;
@@ -106,4 +126,35 @@ private function parseData($dataString)
106126

107127
return $output;
108128
}
129+
130+
/**
131+
* Parses a FieldValue for Multiple Lines e.g.
132+
* FieldValue: Text
133+
*
134+
* MoreText
135+
* Something
136+
* ExtraText
137+
* OtherText
138+
*
139+
* FieldJustification: Left
140+
*
141+
* @param string $line The current line being searched
142+
* @param string $dataString
143+
* @return bool|string Returns a string containing the value for FieldValue e.g. Text\n\nMoreText\nSomething etc.
144+
*/
145+
private function getFieldValue($line, $dataString)
146+
{
147+
// Offset 'FieldValue:'
148+
$pos1 = strpos($dataString, $line) + 11;
149+
$pos2 = strpos($dataString, "FieldJustification", $pos1);
150+
$length = $pos2 - $pos1;
151+
152+
$value = substr(
153+
$dataString,
154+
$pos1,
155+
$length
156+
);
157+
158+
return $value;
159+
}
109160
}

0 commit comments

Comments
 (0)