TYPO3  7.6
StringReplacementFilter.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of SwiftMailer.
5  * (c) 2004-2009 Chris Corbyn
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 
17 {
19  private $_search;
20 
22  private $_replace;
23 
30  public function __construct($search, $replace)
31  {
32  $this->_search = $search;
33  $this->_replace = $replace;
34  }
35 
43  public function shouldBuffer($buffer)
44  {
45  $endOfBuffer = substr($buffer, -1);
46  foreach ((array) $this->_search as $needle) {
47  if (false !== strpos($needle, $endOfBuffer)) {
48  return true;
49  }
50  }
51 
52  return false;
53  }
54 
62  public function filter($buffer)
63  {
64  return str_replace($this->_search, $this->_replace, $buffer);
65  }
66 }