PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/koowa/filter/trim.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 94 lines | 33 code | 7 blank | 54 comment | 3 complexity | 140fd7629304601a02a85fe82754a206 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: trim.php 4477 2012-02-10 01:06:38Z johanjanssens $
  4. * @category Koowa
  5. * @package Koowa_Filter
  6. * @copyright Copyright (C) 2007 - 2012 Johan Janssens. All rights reserved.
  7. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
  8. * @link http://www.nooku.org
  9. */
  10. /**
  11. * Trim filter.
  12. *
  13. * @author Johan Janssens <johan@nooku.org>
  14. * @category Koowa
  15. * @package Koowa_Filter
  16. */
  17. class KFilterTrim extends KFilterAbstract
  18. {
  19. /**
  20. * List of characters provided to the trim() function
  21. *
  22. * If this is null, then trim() is called with no specific character list,
  23. * and its default behavior will be invoked, trimming whitespace.
  24. *
  25. * @var string|null
  26. */
  27. protected $_charList = null;
  28. /**
  29. * Constructor
  30. *
  31. * @param object An optional KConfig object with configuration options
  32. */
  33. public function __construct(KConfig $config)
  34. {
  35. parent::__construct($config);
  36. // List of user-defined tags
  37. if(isset($config->char_list)) {
  38. $this->_charList = $config->char_list;
  39. }
  40. }
  41. /**
  42. * Returns the charList option
  43. *
  44. * @return string|null
  45. */
  46. public function getCharList()
  47. {
  48. return $this->_charList;
  49. }
  50. /**
  51. * Sets the charList option
  52. *
  53. * @param string|null $charList
  54. * @return this
  55. */
  56. public function setCharList($charList)
  57. {
  58. $this->_charList = $charList;
  59. return $this;
  60. }
  61. /**
  62. * Validate a value
  63. *
  64. * @param scalar Value to be validated
  65. * @return bool True when the variable is valid
  66. */
  67. protected function _validate($value)
  68. {
  69. return (is_string($value));
  70. }
  71. /**
  72. * Sanitize a value
  73. *
  74. * Returns the variable with characters stripped from the beginning and end
  75. *
  76. * @param mixed Value to be sanitized
  77. * @return string
  78. */
  79. protected function _sanitize($value)
  80. {
  81. if (null === $this->_charList) {
  82. return trim((string) $value);
  83. } else {
  84. return trim((string) $value, $this->_charList);
  85. }
  86. }
  87. }