|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* 00004 * This file is part of SwiftMailer. 00005 * (c) 2004-2009 Chris Corbyn 00006 * 00007 * For the full copyright and license information, please view the LICENSE 00008 * file that was distributed with this source code. 00009 */ 00010 00011 //@require 'Swift/StreamFilter.php'; 00012 00013 /** 00014 * Processes bytes as they pass through a buffer and replaces sequences in it. 00015 * @package Swift 00016 * @author Chris Corbyn 00017 */ 00018 class Swift_StreamFilters_StringReplacementFilter implements Swift_StreamFilter 00019 { 00020 00021 /** The needle(s) to search for */ 00022 private $_search; 00023 00024 /** The replacement(s) to make */ 00025 private $_replace; 00026 00027 /** 00028 * Create a new StringReplacementFilter with $search and $replace. 00029 * @param string|array $search 00030 * @param string|array $replace 00031 */ 00032 public function __construct($search, $replace) 00033 { 00034 $this->_search = $search; 00035 $this->_replace = $replace; 00036 } 00037 00038 /** 00039 * Returns true if based on the buffer passed more bytes should be buffered. 00040 * @param string $buffer 00041 * @return boolean 00042 */ 00043 public function shouldBuffer($buffer) 00044 { 00045 $endOfBuffer = substr($buffer, -1); 00046 foreach ((array) $this->_search as $needle) 00047 { 00048 if (false !== strpos($needle, $endOfBuffer)) 00049 { 00050 return true; 00051 } 00052 } 00053 return false; 00054 } 00055 00056 /** 00057 * Perform the actual replacements on $buffer and return the result. 00058 * @param string $buffer 00059 * @return string 00060 */ 00061 public function filter($buffer) 00062 { 00063 return str_replace($this->_search, $this->_replace, $buffer); 00064 } 00065 00066 }
1.8.0