summaryrefslogtreecommitdiffstats
path: root/src/Modifier/RowFilter.php
diff options
context:
space:
mode:
authorIgnace Nyamagana Butera <nyamsprod@gmail.com>2015-02-20 10:10:10 +0100
committerIgnace Nyamagana Butera <nyamsprod@gmail.com>2015-02-20 10:10:10 +0100
commit1ba1cdde337df1c0edfa8960cb45f077258cf8bf (patch)
tree42a674e6bbf2b578163e5f96f0982eddd01e4620 /src/Modifier/RowFilter.php
parent42169da9f32996b274bc0d125974660ee999c6cf (diff)
downloadcsv-1ba1cdde337df1c0edfa8960cb45f077258cf8bf.zip
csv-1ba1cdde337df1c0edfa8960cb45f077258cf8bf.tar.gz
csv-1ba1cdde337df1c0edfa8960cb45f077258cf8bf.tar.bz2
improve rowfilter trait
Diffstat (limited to 'src/Modifier/RowFilter.php')
-rw-r--r--src/Modifier/RowFilter.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Modifier/RowFilter.php b/src/Modifier/RowFilter.php
index b0aec16..8a0bf1f 100644
--- a/src/Modifier/RowFilter.php
+++ b/src/Modifier/RowFilter.php
@@ -12,6 +12,8 @@
*/
namespace League\Csv\Modifier;
+use League\Csv\Exception\InvalidRowException;
+
/**
* Trait to format and validate the row before insertion
*
@@ -148,4 +150,40 @@ trait RowFilter
return $this;
}
+
+ /**
+ * Format the given row
+ *
+ * @param array|string $row
+ *
+ * @return array
+ */
+ protected function formatRow(array $row)
+ {
+ foreach ($this->formatters as $formatter) {
+ $row = $formatter($row);
+ }
+
+ return $row;
+ }
+
+ /**
+ * validate a row
+ *
+ * @param array $row
+ *
+ * @throws \League\Csv\Exception\InvalidRowException If the validation failed
+ *
+ * @return void
+ */
+ protected function validateRow(array $row)
+ {
+ foreach ($this->validators as $name => $validator) {
+ if (true !== $validator($row)) {
+ throw new InvalidRowException($name, $row, 'row validation failed');
+ }
+ }
+ }
+
+
}