[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/StreamFilters/ -> StringReplacementFilter.php (source)

   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  
  11  /**
  12   * Processes bytes as they pass through a buffer and replaces sequences in it.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_StreamFilters_StringReplacementFilter implements Swift_StreamFilter
  17  {
  18      /** The needle(s) to search for */
  19      private $_search;
  20  
  21      /** The replacement(s) to make */
  22      private $_replace;
  23  
  24      /**
  25       * Create a new StringReplacementFilter with $search and $replace.
  26       *
  27       * @param string|array $search
  28       * @param string|array $replace
  29       */
  30      public function __construct($search, $replace)
  31      {
  32          $this->_search = $search;
  33          $this->_replace = $replace;
  34      }
  35  
  36      /**
  37       * Returns true if based on the buffer passed more bytes should be buffered.
  38       *
  39       * @param string $buffer
  40       *
  41       * @return bool
  42       */
  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  
  55      /**
  56       * Perform the actual replacements on $buffer and return the result.
  57       *
  58       * @param string $buffer
  59       *
  60       * @return string
  61       */
  62      public function filter($buffer)
  63      {
  64          return str_replace($this->_search, $this->_replace, $buffer);
  65      }
  66  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1