<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Support\Manager; use ModStart\Field\AbstractField; use ModStart\Support\Concern\HasFields; class FieldManager { private static $availableFields = array(); private static $collectedAssets = array(); private static $usedFields = array(); public static function registerBuiltinFields() { $NnNhz = array('text' => \ModStart\Field\Text::class, 'display' => \ModStart\Field\Display::class, 'tree' => \ModStart\Field\Tree::class, 'custom' => \ModStart\Field\Custom::class, 'checkbox' => \ModStart\Field\Checkbox::class, 'tags' => \ModStart\Field\Tags::class, 'code' => \ModStart\Field\Code::class, 'type' => \ModStart\Field\Type::class, 'password' => \ModStart\Field\Password::class, 'image' => \ModStart\Field\Image::class, 'images' => \ModStart\Field\Images::class, 'imagesTemp' => \ModStart\Field\ImagesTemp::class, 'link' => \ModStart\Field\Link::class, 'switch' => \ModStart\Field\SwitchField::class, 'textarea' => \ModStart\Field\Textarea::class, 'color' => \ModStart\Field\Color::class, 'date' => \ModStart\Field\Date::class, 'datetime' => \ModStart\Field\Datetime::class, 'time' => \ModStart\Field\Time::class, 'radio' => \ModStart\Field\Radio::class, 'select' => \ModStart\Field\Select::class, 'richHtml' => \ModStart\Field\RichHtml::class, 'markdown' => \ModStart\Field\Markdown::class, 'keyValueList' => \ModStart\Field\KeyValueList::class, 'values' => \ModStart\Field\Values::class, 'customField' => \ModStart\Field\CustomField::class, 'html' => \ModStart\Field\Html::class, 'cascadeGroup' => \ModStart\Field\CascadeGroup::class, 'number' => \ModStart\Field\Number::class, 'decimal' => \ModStart\Field\Decimal::class, 'currency' => \ModStart\Field\Currency::class, 'id' => \ModStart\Field\Id::class, 'captcha' => \ModStart\Field\Captcha::class, 'fileTemp' => \ModStart\Field\FileTemp::class, 'file' => \ModStart\Field\File::class, 'video' => \ModStart\Field\Video::class, 'areaChina' => \ModStart\Field\AreaChina::class, 'hidden' => \ModStart\Field\Hidden::class, 'icon' => \ModStart\Field\Icon::class); foreach ($NnNhz as $eJvcv => $StsmC) { FieldManager::extend($eJvcv, $StsmC); } } public static function collectFieldAssets($BTuN4 = 'js|css|script|style') { goto aYxKb; I3QUE: foreach (static::$availableFields as $TUuqF => $Q2vn5) { goto Wj7IV; N_GOZ: if (!method_exists($Q2vn5, 'getAssets')) { continue; } goto gssLR; gssLR: $eC32r->push(array_get(call_user_func(array($Q2vn5, 'getAssets')), $BTuN4)); goto NMl_j; Wj7IV: if (in_array($BTuN4, array('js', 'script'))) { if (empty(static::$usedFields[$TUuqF])) { continue; } } goto N_GOZ; NMl_j: } goto JHcI_; aYxKb: if (!in_array($BTuN4, array('js', 'css', 'script', 'style'))) { return array(); } goto XBj6K; T2IWC: return static::$collectedAssets[$BTuN4]; goto HsnbH; JHcI_: static::$collectedAssets[$BTuN4] = $eC32r->flatten()->unique()->filter()->toArray(); goto T2IWC; Ko12P: $eC32r = collect(); goto I3QUE; XBj6K: if (isset(static::$collectedAssets[$BTuN4])) { return static::$collectedAssets[$BTuN4]; } goto Ko12P; HsnbH: } public static function extend($Q2vn5, $StsmC) { static::$availableFields[$Q2vn5] = $StsmC; } public static function findFieldClass($WIVcd) { goto TnTGX; jTBoM: return false; goto fbP_F; TnTGX: $StsmC = array_get(static::$availableFields, $WIVcd); goto WCjIm; WCjIm: if (class_exists($StsmC)) { return $StsmC; } goto jTBoM; fbP_F: } public static function make($O30QX, $UHuqm, $JNXBz, ...$MVaFK) { goto OIpR2; VJYSQ: $vYKL4->context($O30QX); goto xTiyn; xTiyn: return $vYKL4; goto RpEkl; rzQds: $vYKL4 = new $Myw9a($JNXBz, $MVaFK); goto kS2JX; OIpR2: $Myw9a = static::findFieldClass($UHuqm); goto rzQds; kS2JX: $vYKL4->renderMode($O30QX->fieldDefaultRenderMode()); goto VJYSQ; RpEkl: } public static function call($O30QX, $WIVcd, $MVaFK) { if ($Myw9a = static::findFieldClass($WIVcd)) { goto GS9ly; q22k1: $JNXBz = array_get($MVaFK, 0, ''); goto TjqsY; TjqsY: $vYKL4 = new $Myw9a($JNXBz, array_slice($MVaFK, 1)); goto VedfS; VedfS: $vYKL4->renderMode($O30QX->fieldDefaultRenderMode()); goto J8m0m; GS9ly: static::$usedFields[$WIVcd] = true; goto q22k1; l9q5h: return $vYKL4; goto UtBfu; cN9OS: $O30QX->pushField($vYKL4); goto l9q5h; J8m0m: $vYKL4->context($O30QX); goto cN9OS; UtBfu: } throw new \Exception('Field [' . ucfirst($WIVcd) . '] not exists or registered, available: ' . json_encode(array_keys(static::$availableFields))); } }