1 | <?php |
||
12 | abstract class AbstractWidgetFactory |
||
13 | { |
||
14 | use ViewExpressionTrait; |
||
15 | |||
16 | /** |
||
17 | * Widget object to work with. |
||
18 | * |
||
19 | * @var AbstractWidget |
||
20 | */ |
||
21 | protected $widget; |
||
22 | |||
23 | /** |
||
24 | * Widget configuration array. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $widgetConfig; |
||
29 | |||
30 | /** |
||
31 | * The name of the widget being called. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | public $widgetName; |
||
36 | |||
37 | /** |
||
38 | * Array of widget parameters excluding the first one (config). |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | public $widgetParams; |
||
43 | |||
44 | /** |
||
45 | * Array of widget parameters including the first one (config). |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | public $widgetFullParams; |
||
50 | |||
51 | /** |
||
52 | * Laravel application wrapper for better testability. |
||
53 | * |
||
54 | * @var ApplicationWrapperContract; |
||
55 | */ |
||
56 | public $app; |
||
57 | |||
58 | /** |
||
59 | * Another factory that produces some javascript. |
||
60 | * |
||
61 | * @var JavascriptFactory |
||
62 | */ |
||
63 | protected $javascriptFactory; |
||
64 | |||
65 | /** |
||
66 | * The flag for not wrapping content in a special container. |
||
67 | * |
||
68 | * @var bool |
||
69 | */ |
||
70 | public static $skipWidgetContainer = false; |
||
71 | |||
72 | /** |
||
73 | * The flag for not wrapping content in a special container. |
||
74 | * |
||
75 | * @var bool |
||
76 | */ |
||
77 | public static $allowOnlyWidgetsWithDisabledEncryption = false; |
||
78 | |||
79 | /** |
||
80 | * Constructor. |
||
81 | * |
||
82 | * @param ApplicationWrapperContract $app |
||
83 | */ |
||
84 | public function __construct(ApplicationWrapperContract $app) |
||
90 | |||
91 | /** |
||
92 | * Magic method that catches all widget calls. |
||
93 | * |
||
94 | * @param string $widgetName |
||
95 | * @param array $params |
||
96 | * |
||
97 | * @return mixed |
||
98 | */ |
||
99 | public function __call($widgetName, array $params = []) |
||
105 | |||
106 | /** |
||
107 | * Set class properties and instantiate a widget object. |
||
108 | * |
||
109 | * @param $params |
||
110 | * |
||
111 | * @throws InvalidWidgetClassException |
||
112 | * @throws EncryptException |
||
113 | */ |
||
114 | protected function instantiateWidget(array $params = []) |
||
138 | |||
139 | /** |
||
140 | * Convert stuff like 'profile.feedWidget' to 'Profile\FeedWidget'. |
||
141 | * |
||
142 | * @param $widgetName |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | protected function parseFullWidgetNameFromString($widgetName) |
||
150 | |||
151 | /** |
||
152 | * Wrap the given content in a container if it's not an ajax call. |
||
153 | * |
||
154 | * @param $content |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | protected function wrapContentInContainer($content) |
||
171 | |||
172 | /** |
||
173 | * Encrypt widget params to be transported via HTTP. |
||
174 | * |
||
175 | * @param string $params |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | public function encryptWidgetParams($params) |
||
183 | |||
184 | /** |
||
185 | * Decrypt widget params that were transported via HTTP. |
||
186 | * |
||
187 | * @param string $params |
||
188 | * |
||
189 | * @return string |
||
190 | */ |
||
191 | public function decryptWidgetParams($params) |
||
195 | } |
||
196 |