<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Support\Manager; use ModStart\Widget\AbstractWidget; class WidgetManager { private static $availableWidgets = array(); private static $collectedAssets = null; private static $uses = array(); public static function uses($q5sLX) { if (is_array($q5sLX)) { foreach ($q5sLX as $zlxcE) { self::$uses[$zlxcE] = true; } } else { self::$uses[$q5sLX] = true; } } public static function registerBuiltinWidgets() { $WOJ4L = 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 ($WOJ4L as $Lw_xM => $MsA2r) { WidgetManager::extend($Lw_xM, $MsA2r); } } public static function collectWidgetAssets($FDNZs = 'js|css|script|style') { goto K596e; uKXPO: static::$collectedAssets[$FDNZs] = $yLlsp->flatten()->unique()->filter()->toArray(); goto zA2KK; zA2KK: return static::$collectedAssets[$FDNZs]; goto YPzQt; nr73H: $yLlsp = collect(); goto XffQL; K596e: if (!in_array($FDNZs, array('js', 'css', 'script', 'style'))) { return array(); } goto d0OCO; XffQL: foreach (static::$availableWidgets as $L4owo => $Lgjfa) { goto oMQvM; TbVS2: $yLlsp->push(array_get(call_user_func(array($Lgjfa, 'getAssets')), $FDNZs)); goto N6ZjO; AVi0N: if (!method_exists($Lgjfa, 'getAssets')) { continue; } goto TbVS2; oMQvM: if (empty(self::$uses[$Lgjfa])) { continue; } goto AVi0N; N6ZjO: } goto uKXPO; d0OCO: if (isset(static::$collectedAssets[$FDNZs])) { return static::$collectedAssets[$FDNZs]; } goto nr73H; YPzQt: } public static function extend($Lgjfa, $MsA2r) { static::$availableWidgets[$Lgjfa] = $MsA2r; } public static function findWidgetClass($HkVnj) { goto XUBmi; S0IE4: if (class_exists($MsA2r)) { return $MsA2r; } goto xjdhF; xjdhF: return false; goto ApF2c; XUBmi: $MsA2r = array_get(static::$availableWidgets, $HkVnj); goto S0IE4; ApF2c: } public static function call($DapY3, $HkVnj, $nvZ9A) { if ($vtWM8 = static::findWidgetClass($HkVnj)) { goto U2dsx; heOc_: $DapY3->pushField($WfvRK); goto cvnd8; cvnd8: return $WfvRK; goto hpxAX; U2dsx: $JJepM = array_get($nvZ9A, 0, ''); goto KTRCm; KTRCm: $WfvRK = new $vtWM8($JJepM, array_slice($nvZ9A, 1)); goto heOc_; hpxAX: } throw new \Exception('Widget [' . ucfirst($HkVnj) . '] not exists or registered, available: ' . json_encode(array_keys(static::$availableWidgets))); } }