[ Index ]

MailPress 7.2

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

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/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          if ('' === $buffer) {
  46              return false;
  47          }
  48  
  49          $endOfBuffer = substr($buffer, -1);
  50          foreach ((array) $this->search as $needle) {
  51              if (false !== strpos($needle, $endOfBuffer)) {
  52                  return true;
  53              }
  54          }
  55  
  56          return false;
  57      }
  58  
  59      /**
  60       * Perform the actual replacements on $buffer and return the result.
  61       *
  62       * @param string $buffer
  63       *
  64       * @return string
  65       */
  66      public function filter($buffer)
  67      {
  68          return str_replace($this->search, $this->replace, $buffer);
  69      }
  70  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1