/framework/vendor/swift/lib/classes/Swift/StreamFilters/StringReplacementFilterFactory.php

http://zoop.googlecode.com/ · PHP · 53 lines · 23 code · 9 blank · 21 comment · 3 complexity · 6064e9e7e02fdec0b50cc2d3f03cc8b2 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. //@require 'Swift/StreamFilters/StringReplacementFilter.php';
  10. //@require 'Swift/StreamFilterFactory.php';
  11. /**
  12. * Creates filters for replacing needles in a string buffer.
  13. * @package Swift
  14. * @author Chris Corbyn
  15. */
  16. class Swift_StreamFilters_StringReplacementFilterFactory
  17. implements Swift_ReplacementFilterFactory
  18. {
  19. /** Lazy-loaded filters */
  20. private $_filters = array();
  21. /**
  22. * Create a new StreamFilter to replace $search with $replace in a string.
  23. * @param string $search
  24. * @param string $replace
  25. * @return Swift_StreamFilter
  26. */
  27. public function createFilter($search, $replace)
  28. {
  29. if (!isset($this->_filters[$search][$replace]))
  30. {
  31. if (!isset($this->_filters[$search]))
  32. {
  33. $this->_filters[$search] = array();
  34. }
  35. if (!isset($this->_filters[$search][$replace]))
  36. {
  37. $this->_filters[$search][$replace] = array();
  38. }
  39. $this->_filters[$search][$replace]
  40. = new Swift_StreamFilters_StringReplacementFilter($search, $replace);
  41. }
  42. return $this->_filters[$search][$replace];
  43. }
  44. }