Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding PregReplace Filter that allows for filtering based on Regexp
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
} |