Helper.php 775 B

123456789101112131415161718192021222324252627282930313233
  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. public static function htmlspecialchars_utf8(mixed $var): mixed {
  20. if (is_array($var)) {
  21. // @phpstan-ignore argument.type, return.type
  22. return array_map([self::class, 'htmlspecialchars_utf8'], $var);
  23. } elseif (is_string($var)) {
  24. // @phpstan-ignore return.type
  25. return htmlspecialchars($var, ENT_COMPAT, 'UTF-8');
  26. } else {
  27. return $var;
  28. }
  29. }
  30. }