1<?php
2/**
3 * DokuWiki Bootstrap3 Template: Core Functions
4 *
5 * @link     http://dokuwiki.org/template:bootstrap3
6 * @author   Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 */
9
10function get_property_reflection($object, $property)
11{
12    $reflection = new \ReflectionProperty(get_class($object), $property);
13    $reflection->setAccessible(true);
14    return $reflection->getValue($object);
15}
16
17function set_property_reflection($object, $property, $new_value)
18{
19    $reflection = new \ReflectionProperty(get_class($object), $property);
20    $reflection->setAccessible(true);
21    return $reflection->setValue($object, $new_value);
22}
23
24function get_property($object, $property)
25{
26    $array          = (array) $object;
27    $propertyLength = strlen($property);
28
29    foreach ($array as $key => $value) {
30        if (substr($key, -$propertyLength) === $property) {
31            return $value;
32        }
33    }
34}
35
36function set_property($object, $property, $new_value)
37{
38    array_walk($object, function (&$value, $key) use ($new_value, $property) {
39        if (substr($key, -strlen($property)) === $property) {
40            $value = $new_value;
41        }
42    });
43}
44
45function bootstrap3_content($content)
46{
47    global $TPL;
48    return $TPL->normalizeContent($content);
49}
50
51function iconify($icon, $attrs = [])
52{
53    $class = 'iconify';
54
55    if (isset($attrs['class'])) {
56        $class .= ' ' . $attrs['class'];
57        unset($attrs['class']);
58    }
59
60    $attrs['data-icon'] = $icon;
61
62    $attributes = '';
63
64    foreach ($attrs as $key => $value) {
65        $attributes .= ' ' . $key . '="' . hsc($value) . '"';
66    }
67
68    return '<span class="' . $class . '" ' . $attributes . '></span>';
69}
70