<?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($nsF6n) { if (is_array($nsF6n)) { foreach ($nsF6n as $kMUEA) { self::$uses[$kMUEA] = true; } } else { self::$uses[$nsF6n] = true; } } public static function registerBuiltinWidgets() { $yW3Iq = 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 ($yW3Iq as $nfL94 => $cl6c3) { WidgetManager::extend($nfL94, $cl6c3); } } public static function collectWidgetAssets($XcezL = 'js|css|script|style') { goto jHmxs; TcmNI: foreach (static::$availableWidgets as $L1g9F => $VWt5t) { goto yGgqd; yGgqd: if (empty(self::$uses[$VWt5t])) { continue; } goto O12C8; O12C8: if (!method_exists($VWt5t, 'getAssets')) { continue; } goto pZVlg; pZVlg: $urR5B->push(array_get(call_user_func(array($VWt5t, 'getAssets')), $XcezL)); goto VQFDX; VQFDX: } goto s3fgR; jHmxs: if (!in_array($XcezL, array('js', 'css', 'script', 'style'))) { return array(); } goto u13tn; u13tn: if (isset(static::$collectedAssets[$XcezL])) { return static::$collectedAssets[$XcezL]; } goto qYIW_; s3fgR: static::$collectedAssets[$XcezL] = $urR5B->flatten()->unique()->filter()->toArray(); goto V3g3I; V3g3I: return static::$collectedAssets[$XcezL]; goto wjemu; qYIW_: $urR5B = collect(); goto TcmNI; wjemu: } public static function extend($VWt5t, $cl6c3) { static::$availableWidgets[$VWt5t] = $cl6c3; } public static function findWidgetClass($HxDDI) { goto iyL3T; iyL3T: $cl6c3 = array_get(static::$availableWidgets, $HxDDI); goto dy1n_; sr3Zg: return false; goto TILY5; dy1n_: if (class_exists($cl6c3)) { return $cl6c3; } goto sr3Zg; TILY5: } public static function call($KJ9Sf, $HxDDI, $CUZy6) { if ($Bkn_0 = static::findWidgetClass($HxDDI)) { goto YiXaI; zWxn8: $F6q3h = new $Bkn_0($XrXh2, array_slice($CUZy6, 1)); goto BxnDI; YiXaI: $XrXh2 = array_get($CUZy6, 0, ''); goto zWxn8; BxnDI: $KJ9Sf->pushField($F6q3h); goto TgQya; TgQya: return $F6q3h; goto LAWPA; LAWPA: } throw new \Exception('Widget [' . ucfirst($HxDDI) . '] not exists or registered, available: ' . json_encode(array_keys(static::$availableWidgets))); } }