PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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