PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / widget / layout.php
vikappointments / site / helpers / libraries / widget Last commit date
radio 1 month ago searchbar 1 month ago index.html 1 month ago input.php 1 month ago layout.php 1 month ago
layout.php
68 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 VAPLoader::import('libraries.widget.input');
15
16 /**
17 * Base interface to display a custom input.
18 *
19 * @since 1.6
20 */
21 class UIWidgetLayout
22 {
23 /**
24 * Get an instance of the specified widget.
25 *
26 * @param string $widget The widget to load.
27 * @param mixed ... A list of parameters to use for the widget.
28 *
29 * @return UIInput The instantiated widget.
30 *
31 * @throws Exception
32 */
33 public static function getInstance()
34 {
35 // get method arguments
36 $args = func_get_args();
37
38 // make sure the first argument is the name of the widget
39 if (!count($args))
40 {
41 throw new Exception('Missing required argument', 500);
42 }
43
44 // pop the widget from the arguments
45 $widget = strtolower(array_shift($args));
46
47 // try to load the widget file
48 if (!VAPLoader::import('libraries.widget.' . $widget . '.' . $widget))
49 {
50 throw new Exception('Widget [' . $widget . '] not found', 404);
51 }
52
53 // get the reflection of the class
54 $reflect = new ReflectionClass('UI' . ucwords($widget));
55
56 // construct the class with the specified argument.
57 $obj = $reflect->newInstanceArgs($args);
58
59 // make sure the object is an instance of UIInput
60 if ($obj instanceof UIInput === false)
61 {
62 throw new Exception('The widget must be an instance of UIInput', 500);
63 }
64
65 return $obj;
66 }
67 }
68