/library/Zend/Filter/StringToUpper.php

https://bitbucket.org/hamidrezas/melobit · PHP · 121 lines · 52 code · 11 blank · 58 comment · 11 complexity · 8d8969fcddb0d6784ee1da55bf185e5c MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Filter
  17. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: StringToUpper.php 24594 2012-01-05 21:27:01Z matthew $
  20. */
  21. /**
  22. * @see Zend_Filter_Interface
  23. */
  24. require_once 'Zend/Filter/Interface.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Filter
  28. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Filter_StringToUpper implements Zend_Filter_Interface
  32. {
  33. /**
  34. * Encoding for the input string
  35. *
  36. * @var string
  37. */
  38. protected $_encoding = null;
  39. /**
  40. * Constructor
  41. *
  42. * @param string|array $options OPTIONAL
  43. */
  44. public function __construct($options = null)
  45. {
  46. if ($options instanceof Zend_Config) {
  47. $options = $options->toArray();
  48. } else if (!is_array($options)) {
  49. $options = func_get_args();
  50. $temp = array();
  51. if (!empty($options)) {
  52. $temp['encoding'] = array_shift($options);
  53. }
  54. $options = $temp;
  55. }
  56. if (!array_key_exists('encoding', $options) && function_exists('mb_internal_encoding')) {
  57. $options['encoding'] = mb_internal_encoding();
  58. }
  59. if (array_key_exists('encoding', $options)) {
  60. $this->setEncoding($options['encoding']);
  61. }
  62. }
  63. /**
  64. * Returns the set encoding
  65. *
  66. * @return string
  67. */
  68. public function getEncoding()
  69. {
  70. return $this->_encoding;
  71. }
  72. /**
  73. * Set the input encoding for the given string
  74. *
  75. * @param string $encoding
  76. * @return Zend_Filter_StringToUpper Provides a fluent interface
  77. * @throws Zend_Filter_Exception
  78. */
  79. public function setEncoding($encoding = null)
  80. {
  81. if ($encoding !== null) {
  82. if (!function_exists('mb_strtoupper')) {
  83. require_once 'Zend/Filter/Exception.php';
  84. throw new Zend_Filter_Exception('mbstring is required for this feature');
  85. }
  86. $encoding = (string) $encoding;
  87. if (!in_array(strtolower($encoding), array_map('strtolower', mb_list_encodings()))) {
  88. require_once 'Zend/Filter/Exception.php';
  89. throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
  90. }
  91. }
  92. $this->_encoding = $encoding;
  93. return $this;
  94. }
  95. /**
  96. * Defined by Zend_Filter_Interface
  97. *
  98. * Returns the string $value, converting characters to uppercase as necessary
  99. *
  100. * @param string $value
  101. * @return string
  102. */
  103. public function filter($value)
  104. {
  105. if ($this->_encoding) {
  106. return mb_strtoupper((string) $value, $this->_encoding);
  107. }
  108. return strtoupper((string) $value);
  109. }
  110. }