*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Filter / Alpha.php
blob5215eaf86895b558ad5d3d496c30c3b67e8aa52b
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Filter
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Alpha.php 16870 2009-07-20 10:17:59Z mikaelkael $
22 /**
23 * @see Zend_Filter_Interface
25 require_once 'Zend/Filter/Interface.php';
26 /**
27 * @see Zend_Locale
29 require_once 'Zend/Locale.php';
31 /**
32 * @category Zend
33 * @package Zend_Filter
34 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
35 * @license http://framework.zend.com/license/new-bsd New BSD License
37 class Zend_Filter_Alpha implements Zend_Filter_Interface
39 /**
40 * Whether to allow white space characters; off by default
42 * @var boolean
43 * @deprecated
45 public $allowWhiteSpace;
47 /**
48 * Is PCRE is compiled with UTF-8 and Unicode support
50 * @var mixed
51 **/
52 protected static $_unicodeEnabled;
54 /**
55 * Locale in browser.
57 * @var Zend_Locale object
59 protected $_locale;
61 /**
62 * The Alphabet means english alphabet.
64 * @var boolean
66 protected static $_meansEnglishAlphabet;
68 /**
69 * Sets default option values for this instance
71 * @param boolean $allowWhiteSpace
72 * @return void
74 public function __construct($allowWhiteSpace = false)
76 $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
77 if (null === self::$_unicodeEnabled) {
78 self::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
81 if (null === self::$_meansEnglishAlphabet) {
82 $this->_locale = new Zend_Locale('auto');
83 self::$_meansEnglishAlphabet = in_array($this->_locale->getLanguage(),
84 array('ja', 'ko', 'zh')
90 /**
91 * Returns the allowWhiteSpace option
93 * @return boolean
95 public function getAllowWhiteSpace()
97 return $this->allowWhiteSpace;
101 * Sets the allowWhiteSpace option
103 * @param boolean $allowWhiteSpace
104 * @return Zend_Filter_Alpha Provides a fluent interface
106 public function setAllowWhiteSpace($allowWhiteSpace)
108 $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
109 return $this;
113 * Defined by Zend_Filter_Interface
115 * Returns the string $value, removing all but alphabetic characters
117 * @param string $value
118 * @return string
120 public function filter($value)
122 $whiteSpace = $this->allowWhiteSpace ? '\s' : '';
123 if (!self::$_unicodeEnabled) {
124 // POSIX named classes are not supported, use alternative a-zA-Z match
125 $pattern = '/[^a-zA-Z' . $whiteSpace . ']/';
126 } else if (self::$_meansEnglishAlphabet) {
127 //The Alphabet means english alphabet.
128 $pattern = '/[^a-zA-Z' . $whiteSpace . ']/u';
129 } else {
130 //The Alphabet means each language's alphabet.
131 $pattern = '/[^\p{L}' . $whiteSpace . ']/u';
134 return preg_replace($pattern, '', (string) $value);