diff --git a/classes/CSVXMLValidator.php b/classes/CSVXMLValidator.php
index 484af01..238ecf6 100644
--- a/classes/CSVXMLValidator.php
+++ b/classes/CSVXMLValidator.php
@@ -20,9 +20,9 @@ final class CSVXMLValidator
*/
public function __construct()
{
- $error_msgs = [];
- $inv_errors = [];
- $depcon_errors = [];
+ $this->error_msgs = [];
+ $this->inv_errors = [];
+ $this->depcon_errors = [];
}
public function addError(String $error)
diff --git a/public/index3.php b/public/index3.php
index 6d19257..6c05132 100644
--- a/public/index3.php
+++ b/public/index3.php
@@ -44,11 +44,11 @@ foreach ($availableFields as $categoryName => $fieldCategory) {
}
foreach ($fieldCategory as $key => $value) {
- if (!empty($value["dependsOn"])) {
- $fieldsWithDependency[$key] = $value['dependsOn'];
+ if (!empty($value->dependsOn)) {
+ $fieldsWithDependency[$key] = $value->dependsOn;
}
- if (!empty($value["allowedValues"])) {
- $fieldsWithAllowedValueSet[$key] = $value['allowedValues'];
+ if (!empty($value->allowedValues)) {
+ $fieldsWithAllowedValueSet[$key] = $value->allowedValues;
}
}
@@ -68,23 +68,28 @@ echo '';
//echo '
';print_r($allowed);echo '
';
echo '1: Only allowed tags (column names) used?';
$fp = fopen($csv_datei, 'r');
-$y = 1;
-$zeile = fgetcsv($fp, 100000, ';');
-$maxLoopLen = count($zeile);
-for ($x = 0; $x < $maxLoopLen; $x++) {
+$y = 0;
+while ($zeile = fgetcsv($fp, 100000, ';')) {
- $zeile[$x] = str_replace("\xEF\xBB\xBF", "", $zeile[$x]);
- $inhalt[$y][$x] = $zeile[$x];
- if (!in_array($inhalt[1][$x], $allowed)) {
- $validator->addError(
- '
ERROR in column ' . $x
- . ' created by value: ' . $inhalt[1][$x] . ''
- );
+ $y++;
+ $maxLoopLen = count($zeile);
+ for ($x = 0; $x < $maxLoopLen; $x++) {
+ $inhalt[$y][$x] = str_replace("'", "\'", $zeile[$x]);
+ if ($y == 1) {
+ // remove byte order mark
+ $inhalt[$y][$x] = str_replace("\xEF\xBB\xBF", "", $inhalt[$y][$x]);
+ if (!in_array($inhalt[$y][$x], $allowed)) {
+ $validator->addError(
+ '
ERROR in column ' . $x
+ . ' created by value: ' . $inhalt[$y][$x] . ''
+ );
+ }
+ }
}
- //echo '
';var_dump($inhalt[1][$x]);
}
fclose($fp);
-$erstezeile = $zeile;
+
+$erstezeile = $inhalt[1];
if (count($validator->error_msgs) != 0) {
echo '
Not allowed tags found !';
} else {
@@ -93,9 +98,9 @@ if (count($validator->error_msgs) != 0) {
//// Check #2
echo '
2: Not allowed multiple use of tags (column names)?';
-$compare = array_unique($zeile);
+$compare = array_unique($erstezeile);
-if (count($zeile) != count($compare)) {
+if (count($erstezeile) != count($compare)) {
$validator->addError(
'
There are duplicate column names !'
);
@@ -103,21 +108,6 @@ if (count($zeile) != count($compare)) {
echo '
No duplicate column names !';
}
-
-//// Get values into memory for following checks
-//TODO: Merge with loop on line 74
-$fp = fopen($csv_datei, 'r');
-$y = 0;
-while ($zeile = fgetcsv($fp, 100000, ';')) {
-
- $y++;
- $maxLoopLen = count($zeile);
- for ($x = 0; $x < $maxLoopLen; $x++) {
- $inhalt[$y][$x] = str_replace("'", "\'", $zeile[$x]);
- }
-}
-fclose($fp);
-
///// Check #3
echo '
3: Mandatory tags available and always filled in?';
unset($inv_array);
@@ -202,7 +192,7 @@ foreach ($fieldsWithDependency as $tField => $tDependentFields) {
if (!empty($depencymessage)) {
echo 'Dependent columns were not observed !';
foreach ($depencymessage as $tDepMsg) {
- $validator->addError('
' . $tDepMsg)
+ $validator->addError('
' . $tDepMsg);
}
} else {
echo 'Dependent columns were observed !';