Permalink
Browse files

Adding PregReplace Filter that allows for filtering based on Regexp

  • Loading branch information...
1 parent 48f7853 commit 5cba05c2d12c6a203b572b87763199918ce7dd42 @rdohms committed Apr 18, 2012
Showing with 45 additions and 0 deletions.
  1. +45 −0 Rules/PregReplace.php
View
@@ -0,0 +1,45 @@
+<?php
+namespace DMS\Filter\Rules;
+
+/**
+ * PregReplace Rule
+ * Replaces based on regular expression, will replace with empty if no
+ * replacement is defined.
+ *
+ * @package DMS
+ * @subpackage Filter
+ *
+ * @Annotation
+ */
+class PregReplace extends Rule
+{
+ /**
+ * Regular Expression to use
+ *
+ * @var string
+ */
+ public $regexp = null;
+
+ /**
+ * Replacement
+ *
+ * @var string
+ */
+ public $replacement = "";
+
+ /**
+ * {@inheritDoc}
+ */
+ public function applyFilter($value)
+ {
+ return preg_replace($this->regexp, $this->replacement, $value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getDefaultOption()
+ {
+ return 'regexp';
+ }
+}

0 comments on commit 5cba05c

Please sign in to comment.