<?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($PbprP) { if (is_array($PbprP)) { foreach ($PbprP as $w3jTU) { self::$uses[$w3jTU] = true; } } else { self::$uses[$PbprP] = true; } } public static function registerBuiltinWidgets() { $eYURB = 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 ($eYURB as $Eraue => $cTFJ4) { WidgetManager::extend($Eraue, $cTFJ4); } } public static function collectWidgetAssets($aHcWY = 'js|css|script|style') { goto YMneN; TY1my: if (isset(static::$collectedAssets[$aHcWY])) { return static::$collectedAssets[$aHcWY]; } goto u0obA; u0obA: $Pz0JK = collect(); goto riCJO; nBxuZ: return static::$collectedAssets[$aHcWY]; goto xXQzt; riCJO: foreach (static::$availableWidgets as $sQIr6 => $acdQI) { goto jhngl; jhngl: if (empty(self::$uses[$acdQI])) { continue; } goto IB3uI; IB3uI: if (!method_exists($acdQI, 'getAssets')) { continue; } goto M5lrv; M5lrv: $Pz0JK->push(array_get(call_user_func(array($acdQI, 'getAssets')), $aHcWY)); goto bkhwN; bkhwN: } goto CGaXO; CGaXO: static::$collectedAssets[$aHcWY] = $Pz0JK->flatten()->unique()->filter()->toArray(); goto nBxuZ; YMneN: if (!in_array($aHcWY, array('js', 'css', 'script', 'style'))) { return array(); } goto TY1my; xXQzt: } public static function extend($acdQI, $cTFJ4) { static::$availableWidgets[$acdQI] = $cTFJ4; } public static function findWidgetClass($fSCUf) { goto r3YEP; r3YEP: $cTFJ4 = array_get(static::$availableWidgets, $fSCUf); goto pB5fp; pB5fp: if (class_exists($cTFJ4)) { return $cTFJ4; } goto Z0H5p; Z0H5p: return false; goto O8g67; O8g67: } public static function call($V12FF, $fSCUf, $g59Hh) { if ($uS8I4 = static::findWidgetClass($fSCUf)) { goto G93_I; ouz0g: $D5Q3D = new $uS8I4($VDtGk, array_slice($g59Hh, 1)); goto NbMbf; G93_I: $VDtGk = array_get($g59Hh, 0, ''); goto ouz0g; NbMbf: $V12FF->pushField($D5Q3D); goto a8mfp; a8mfp: return $D5Q3D; goto nKnWv; nKnWv: } throw new \Exception('Widget [' . ucfirst($fSCUf) . '] not exists or registered, available: ' . json_encode(array_keys(static::$availableWidgets))); } }