summaryrefslogtreecommitdiffstats
path: root/examples/lib
diff options
context:
space:
mode:
authorMatt Beale <matt@heyratfans.co.uk>2015-10-12 09:29:56 +0100
committervagrant <vagrant@homestead>2015-10-13 07:19:31 +0000
commitbfdc19f44a9fcbbd439ac937dc61b41f30e0e892 (patch)
tree1d49e6ba0f2e565c9c0a9a12cb63bb731fa18b64 /examples/lib
parent1336fd426f5822f9b703fcc68fe24273a726f40c (diff)
downloadcsv-bfdc19f44a9fcbbd439ac937dc61b41f30e0e892.zip
csv-bfdc19f44a9fcbbd439ac937dc61b41f30e0e892.tar.gz
csv-bfdc19f44a9fcbbd439ac937dc61b41f30e0e892.tar.bz2
Don't trim $filter_name in sanitizeStreamFilter - Fixes filters which pass newline character as an argument.
Diffstat (limited to 'examples/lib')
-rw-r--r--examples/lib/FilterReplace.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/lib/FilterReplace.php b/examples/lib/FilterReplace.php
new file mode 100644
index 0000000..962555c
--- /dev/null
+++ b/examples/lib/FilterReplace.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace lib;
+
+use php_user_filter;
+
+class FilterReplace extends php_user_filter
+{
+ const FILTER_NAME = 'convert.replace.';
+
+ private $search;
+
+ private $replace;
+
+ public function onCreate()
+ {
+ if( strpos( $this->filtername, self::FILTER_NAME ) !== 0 ){
+ return false;
+ }
+
+ $params = substr( $this->filtername, strlen( self::FILTER_NAME ) );
+
+ if( !preg_match( '/([^:]+):([^$]+)$/', $params, $matches ) ){
+ return false;
+ }
+
+ $this->search = $matches[1];
+ $this->replace = $matches[2];
+
+ return true;
+ }
+
+ public function filter( $in, $out, &$consumed, $closing )
+ {
+ while( $res = stream_bucket_make_writeable( $in ) ){
+
+ $res->data = str_replace( $this->search, $this->replace, $res->data );
+
+ $consumed += $res->datalen;
+
+ /** @noinspection PhpParamsInspection */
+ stream_bucket_append( $out, $res );
+ }
+
+ return PSFS_PASS_ON;
+ }
+}