PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/koowa/filter/trim.php

https://bitbucket.org/organicdevelopment/nooku-framework
PHP | 93 lines | 33 code | 7 blank | 53 comment | 3 complexity | b7ab4788d8b62c995694bc51dc7ce948 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  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. * @package Koowa_Filter
  15. */
  16. class KFilterTrim extends KFilterAbstract
  17. {
  18. /**
  19. * List of characters provided to the trim() function
  20. *
  21. * If this is null, then trim() is called with no specific character list,
  22. * and its default behavior will be invoked, trimming whitespace.
  23. *
  24. * @var string|null
  25. */
  26. protected $_charList = null;
  27. /**
  28. * Constructor
  29. *
  30. * @param object An optional KConfig object with configuration options
  31. */
  32. public function __construct(KConfig $config)
  33. {
  34. parent::__construct($config);
  35. // List of user-defined tags
  36. if(isset($config->char_list)) {
  37. $this->_charList = $config->char_list;
  38. }
  39. }
  40. /**
  41. * Returns the charList option
  42. *
  43. * @return string|null
  44. */
  45. public function getCharList()
  46. {
  47. return $this->_charList;
  48. }
  49. /**
  50. * Sets the charList option
  51. *
  52. * @param string|null $charList
  53. * @return this
  54. */
  55. public function setCharList($charList)
  56. {
  57. $this->_charList = $charList;
  58. return $this;
  59. }
  60. /**
  61. * Validate a value
  62. *
  63. * @param scalar Value to be validated
  64. * @return bool True when the variable is valid
  65. */
  66. protected function _validate($value)
  67. {
  68. return (is_string($value));
  69. }
  70. /**
  71. * Sanitize a value
  72. *
  73. * Returns the variable with characters stripped from the beginning and end
  74. *
  75. * @param mixed Value to be sanitized
  76. * @return string
  77. */
  78. protected function _sanitize($value)
  79. {
  80. if (null === $this->_charList) {
  81. return trim((string) $value);
  82. } else {
  83. return trim((string) $value, $this->_charList);
  84. }
  85. }
  86. }