Helper.php 806 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * MINZ - Copyright 2011 Marien Fressinaud
  5. * Sous licence AGPL3 <http://www.gnu.org/licenses/>
  6. */
  7. /**
  8. * The Minz_Helper class contains some misc. help functions
  9. */
  10. final class Minz_Helper {
  11. /**
  12. * Wrapper for htmlspecialchars.
  13. * Force UTF-8 value and can be used on array too.
  14. *
  15. * @phpstan-template T of mixed
  16. * @phpstan-param T $var
  17. * @phpstan-return T
  18. *
  19. * @param mixed $var
  20. * @return mixed
  21. */
  22. public static function htmlspecialchars_utf8($var) {
  23. if (is_array($var)) {
  24. // @phpstan-ignore argument.type, return.type
  25. return array_map([self::class, 'htmlspecialchars_utf8'], $var);
  26. } elseif (is_string($var)) {
  27. // @phpstan-ignore return.type
  28. return htmlspecialchars($var, ENT_COMPAT, 'UTF-8');
  29. } else {
  30. return $var;
  31. }
  32. }
  33. }