1 | <?php |
||
16 | class Widget implements iWidget |
||
17 | { |
||
18 | use DynamicGlobal; |
||
19 | |||
20 | /** @var string|null */ |
||
21 | public static $class; |
||
22 | |||
23 | public static function widget(array $params = null) |
||
|
|||
24 | { |
||
25 | self::$class = get_called_class(); |
||
26 | |||
27 | // check if class exist |
||
28 | if (!class_exists(self::$class)) { |
||
29 | return 'Error: Widget is not founded: ' . App::$Security->strip_tags(self::$class); |
||
30 | } |
||
31 | |||
32 | // init class and pass properties |
||
33 | $object = new self::$class; |
||
34 | if (Obj::isArray($params) && count($params) > 0) { |
||
35 | foreach ($params as $property => $value) { |
||
36 | if (property_exists($object, $property)) { |
||
37 | $object->$property = $value; |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
42 | // prepare output |
||
43 | $out = null; |
||
44 | try { |
||
45 | $object->init(); |
||
46 | $out = $object->display(); |
||
47 | } catch (\Exception $e) { |
||
48 | throw $e; |
||
49 | } |
||
50 | |||
51 | return $out; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get widget configs from admin part as array $cfg=>$value |
||
56 | * @return array|null|string |
||
57 | */ |
||
58 | public function getConfigs() |
||
63 | |||
64 | public function display() {} |
||
66 | |||
67 | /** |
||
68 | * Check if widget is enabled. For native widget is always enabled |
||
69 | * @param string $name |
||
70 | * @return bool |
||
71 | */ |
||
72 | public static function enabled($name) |
||
76 | } |