/administrator/components/com_widgetkit/vendor/yootheme/framework/src/View/Helper/AttributeHelper.php

https://gitlab.com/vnsoftdev/amms · PHP · 45 lines · 27 code · 7 blank · 11 comment · 2 complexity · 13b248134b76bb05ffa213abc6430bd9 MD5 · raw file

  1. <?php
  2. namespace YOOtheme\Framework\View\Helper;
  3. class AttributeHelper
  4. {
  5. /**
  6. * Render shortcut.
  7. *
  8. * @see render()
  9. */
  10. public function __invoke($attrs)
  11. {
  12. return $this->render($attrs);
  13. }
  14. /**
  15. * Renders html attributes.
  16. *
  17. * @param array $attrs
  18. * @return string
  19. */
  20. public function render($attrs)
  21. {
  22. $html = array();
  23. $attrs = call_user_func_array('array_merge', func_get_args());
  24. foreach ($attrs as $key => $value) {
  25. if (is_array($value)) {
  26. $value = implode(' ', $value);
  27. }
  28. if (is_numeric($key)) {
  29. $html[] = $value;
  30. } elseif ($value === true) {
  31. $html[] = $key;
  32. } elseif ($value !== '') {
  33. $html[] = sprintf('%s="%s"', $key, htmlspecialchars($value));
  34. }
  35. }
  36. return $html ? ' '.implode(' ', $html) : '';
  37. }
  38. }