<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Support\Manager; use ModStart\Field\AbstractField; class WidgetManager { private static $availableWidgets = array(); private static $collectedAssets = null; private static $usedWidgets = array(); public static function registerBuiltinWidgets() { $NnNhz = array('statusText' => \ModStart\Widget\StatusText::class, 'textAjaxRequest' => \ModStart\Widget\TextAjaxRequest::class, 'textDialogRequest' => \ModStart\Widget\TextDialogRequest::class, 'textAction' => \ModStart\Widget\TextAction::class, 'textLink' => \ModStart\Widget\TextLink::class, 'buttonAjaxRequest' => \ModStart\Widget\ButtonAjaxRequest::class, 'buttonDialogRequest' => \ModStart\Widget\ButtonDialogRequest::class); foreach ($NnNhz as $eJvcv => $StsmC) { WidgetManager::extend($eJvcv, $StsmC); } } public static function collectWidgetAssets($BTuN4 = 'js|css|script|style') { goto eNd0L; fgymL: if (isset(static::$collectedAssets[$BTuN4])) { return static::$collectedAssets[$BTuN4]; } goto SAJ3f; ovudp: return static::$collectedAssets[$BTuN4]; goto e1bB3; NLXaw: static::$collectedAssets[$BTuN4] = $eC32r->flatten()->unique()->filter()->toArray(); goto ovudp; eNd0L: if (!in_array($BTuN4, array('js', 'css', 'script', 'style'))) { return array(); } goto fgymL; SAJ3f: $eC32r = collect(); goto g8pLw; g8pLw: foreach (static::$availableWidgets as $TUuqF => $Q2vn5) { goto GC_kV; BKJc0: if (!method_exists($Q2vn5, 'getAssets')) { continue; } goto GNGt7; GNGt7: $eC32r->push(array_get(call_user_func(array($Q2vn5, 'getAssets')), $BTuN4)); goto Vknlr; GC_kV: if (in_array($BTuN4, array('js', 'script'))) { if (empty(static::$usedWidgets[$TUuqF])) { continue; } } goto BKJc0; Vknlr: } goto NLXaw; e1bB3: } public static function extend($Q2vn5, $StsmC) { static::$availableWidgets[$Q2vn5] = $StsmC; } public static function findWidgetClass($WIVcd) { goto TGSBZ; XDitV: if (class_exists($StsmC)) { return $StsmC; } goto yL1Yx; TGSBZ: $StsmC = array_get(static::$availableWidgets, $WIVcd); goto XDitV; yL1Yx: return false; goto oYrpA; oYrpA: } public static function call($O30QX, $WIVcd, $MVaFK) { if ($Myw9a = static::findWidgetClass($WIVcd)) { goto YILM2; YILM2: static::$usedWidgets[$WIVcd] = true; goto j0dQf; NxI5h: return $vYKL4; goto bW6nr; j0dQf: $JNXBz = array_get($MVaFK, 0, ''); goto Luylk; Luylk: $vYKL4 = new $Myw9a($JNXBz, array_slice($MVaFK, 1)); goto O1hpY; O1hpY: $O30QX->pushField($vYKL4); goto NxI5h; bW6nr: } throw new \Exception('Widget [' . ucfirst($WIVcd) . '] not exists or registered, available: ' . json_encode(array_keys(static::$availableWidgets))); } }