Skip to content

Commit

Permalink
Adding PregReplace Filter that allows for filtering based on Regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
rdohms committed Apr 18, 2012
1 parent 48f7853 commit 5cba05c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Rules/PregReplace.php
@@ -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.