Warning, file /webapps/ocs-webserver/library/Zend/Filter/Word/SeparatorToSeparator.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Filter
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * @see Zend_Filter_PregReplace
0024  */
0025 // require_once 'Zend/Filter/PregReplace.php';
0026 
0027 /**
0028  * @category   Zend
0029  * @package    Zend_Filter
0030  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0031  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0032  */
0033 class Zend_Filter_Word_SeparatorToSeparator extends Zend_Filter_PregReplace
0034 {
0035 
0036     protected $_searchSeparator = null;
0037     protected $_replacementSeparator = null;
0038 
0039     /**
0040      * Constructor
0041      *
0042      * @param  string  $searchSeparator      Seperator to search for
0043      * @param  string  $replacementSeperator Seperator to replace with
0044      * @return void
0045      */
0046     public function __construct($searchSeparator = ' ', $replacementSeparator = '-')
0047     {
0048         $this->setSearchSeparator($searchSeparator);
0049         $this->setReplacementSeparator($replacementSeparator);
0050     }
0051 
0052     /**
0053      * Sets a new seperator to search for
0054      *
0055      * @param  string  $separator  Seperator to search for
0056      * @return $this
0057      */
0058     public function setSearchSeparator($separator)
0059     {
0060         $this->_searchSeparator = $separator;
0061         return $this;
0062     }
0063 
0064     /**
0065      * Returns the actual set seperator to search for
0066      *
0067      * @return  string
0068      */
0069     public function getSearchSeparator()
0070     {
0071         return $this->_searchSeparator;
0072     }
0073 
0074     /**
0075      * Sets a new seperator which replaces the searched one
0076      *
0077      * @param  string  $separator  Seperator which replaces the searched one
0078      * @return $this
0079      */
0080     public function setReplacementSeparator($separator)
0081     {
0082         $this->_replacementSeparator = $separator;
0083         return $this;
0084     }
0085 
0086     /**
0087      * Returns the actual set seperator which replaces the searched one
0088      *
0089      * @return  string
0090      */
0091     public function getReplacementSeparator()
0092     {
0093         return $this->_replacementSeparator;
0094     }
0095 
0096     /**
0097      * Defined by Zend_Filter_Interface
0098      *
0099      * Returns the string $value, replacing the searched seperators with the defined ones
0100      *
0101      * @param  string $value
0102      * @return string
0103      */
0104     public function filter($value)
0105     {
0106         return $this->_separatorToSeparatorFilter($value);
0107     }
0108 
0109     /**
0110      * Do the real work, replaces the seperator to search for with the replacement seperator
0111      *
0112      * Returns the replaced string
0113      *
0114      * @param  string $value
0115      * @return string
0116      */
0117     protected function _separatorToSeparatorFilter($value)
0118     {
0119         if ($this->_searchSeparator == null) {
0120             // require_once 'Zend/Filter/Exception.php';
0121             throw new Zend_Filter_Exception('You must provide a search separator for this filter to work.');
0122         }
0123 
0124         $this->setMatchPattern('#' . preg_quote($this->_searchSeparator, '#') . '#');
0125         $this->setReplacement($this->_replacementSeparator);
0126         return parent::filter($value);
0127     }
0128 
0129 }