00001 <?php 00002 /*************************************************************************** 00003 * Copyright (C) 2008 by Evgeniy N. Sokolov * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Lesser General Public License as * 00007 * published by the Free Software Foundation; either version 3 of the * 00008 * License, or (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00015 final class WordSplitterFilter implements Filtrator 00016 { 00017 private $maxWordLength = 25; 00018 private $delimer = '​'; 00019 00023 public static function create() 00024 { 00025 return new self; 00026 } 00027 00031 public function setMaxWordLength($length) 00032 { 00033 $this->maxWordLength = $length; 00034 return $this; 00035 } 00036 00037 public function getMaxWordLength() 00038 { 00039 return $this->maxWordLength; 00040 } 00041 00045 public function setDelimer($delimer) 00046 { 00047 $this->delimer = $delimer; 00048 return $this; 00049 } 00050 00051 public function getDelimer() 00052 { 00053 return $this->delimer; 00054 } 00055 00056 public function apply($value) 00057 { 00058 return 00059 preg_replace( 00060 '/([^\s]{'.$this->getMaxWordLength().',' 00061 .$this->getMaxWordLength().'})([^\s])/u', 00062 '$1'.$this->getDelimer().'$2', 00063 $value 00064 ); 00065 } 00066 } 00067 ?>