utils.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Return the value of the given item.
  4. * If the given item is a Closure the result of the Closure will be returned.
  5. *
  6. * @param mixed $value
  7. * @return mixed
  8. */
  9. function value($value)
  10. {
  11. return (is_callable($value) and !is_string($value)) ? call_user_func($value) : $value;
  12. }
  13. /**
  14. * Checks if a scalar value is FALSE, without content or only full of whitespaces.
  15. * For non-scalar values will evaluate if value is empty().
  16. *
  17. * @param string $value
  18. * @return bool
  19. */
  20. function is_empty($value)
  21. {
  22. return !isset($value) || (is_scalar($value) ? (trim($value) === '') : empty($value));
  23. }
  24. /**
  25. * @param string $route controller/action
  26. * @param array $params
  27. * @param null $https
  28. * @param bool $asset
  29. *
  30. * @return string
  31. */
  32. function url($route = '', array $params = array(), $https = null, $asset = false)
  33. {
  34. return \Pimf\Url::compute($route, $params, $https, $asset);
  35. }
  36. /**
  37. * Escape HTML entities in a string.
  38. *
  39. * @param string $value
  40. *
  41. * @return string
  42. */
  43. function e($value)
  44. {
  45. return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
  46. }