From 2aacbfc89f8605de686c7cd8b30988ac35982a86 Mon Sep 17 00:00:00 2001 From: dingyongliang Date: Mon, 10 Jul 2023 15:46:59 +0800 Subject: [PATCH] * zin: add type for wg. --- lib/zin/core/directive.class.php | 18 +++--- lib/zin/core/h.class.php | 28 +++++----- lib/zin/core/h.func.php | 47 ++++++++-------- lib/zin/core/item.class.php | 2 +- lib/zin/core/props.class.php | 43 +++++++++------ lib/zin/core/rawcontent.class.php | 3 +- lib/zin/core/render.func.php | 8 +-- lib/zin/core/selector.func.php | 31 ++++++++--- lib/zin/core/wg.class.php | 92 +++++++++++++++---------------- lib/zin/utils/dataset.class.php | 36 ++++++------ lib/zin/utils/style.class.php | 20 +++---- lib/zin/wg/actionitem/v1.php | 2 +- lib/zin/wg/avatar/v1.php | 2 +- lib/zin/wg/batchactions/v1.php | 2 +- lib/zin/wg/btn/v1.php | 2 +- lib/zin/wg/btngroup/v1.php | 4 +- lib/zin/wg/burn/v1.php | 5 +- lib/zin/wg/cell/v1.php | 2 +- lib/zin/wg/center/v1.php | 2 +- lib/zin/wg/checkbox/v1.php | 2 +- lib/zin/wg/checklist/v1.php | 4 +- lib/zin/wg/col/v1.php | 2 +- lib/zin/wg/collapsebtn/v1.php | 2 +- lib/zin/wg/detailbody/v1.php | 2 +- lib/zin/wg/dragul/v1.php | 2 +- lib/zin/wg/dropdown/v1.php | 2 +- lib/zin/wg/dropmenu/v1.php | 2 +- lib/zin/wg/dtable/v1.php | 2 +- lib/zin/wg/echarts/v1.php | 2 +- lib/zin/wg/editor/v1.php | 2 +- lib/zin/wg/featurebar/v1.php | 2 +- lib/zin/wg/formbatchitem/v1.php | 3 +- lib/zin/wg/formgroup/v1.php | 2 +- lib/zin/wg/formlabel/v1.php | 2 +- lib/zin/wg/formrow/v1.php | 4 +- lib/zin/wg/formsettingbtn/v1.php | 2 +- lib/zin/wg/fragment/v1.php | 2 +- lib/zin/wg/header/v1.php | 3 +- lib/zin/wg/heading/v1.php | 5 +- lib/zin/wg/icon/v1.php | 2 +- lib/zin/wg/input/v1.php | 2 +- lib/zin/wg/inputgroup/v1.php | 4 +- lib/zin/wg/inputgroupaddon/v1.php | 2 +- lib/zin/wg/label/v1.php | 2 +- lib/zin/wg/mainmenu/v1.php | 2 +- lib/zin/wg/mainnavbar/v1.php | 2 +- lib/zin/wg/menu/v1.php | 4 +- lib/zin/wg/modal/v1.php | 2 +- lib/zin/wg/modaldialog/v1.php | 2 +- lib/zin/wg/modalheader/v1.php | 2 +- lib/zin/wg/modaltrigger/v1.php | 2 +- lib/zin/wg/modulemenu/v1.php | 6 +- lib/zin/wg/monaco/v1.php | 2 +- lib/zin/wg/nav/v1.php | 7 +-- lib/zin/wg/navbar/v1.php | 3 +- lib/zin/wg/overviewblock/v1.php | 10 ++-- lib/zin/wg/page/v1.php | 7 +-- lib/zin/wg/pagebase/v1.php | 2 +- lib/zin/wg/pageform/v1.php | 2 +- lib/zin/wg/pager/v1.php | 2 +- lib/zin/wg/panel/v1.php | 18 +++--- lib/zin/wg/pastedialog/v1.php | 1 - lib/zin/wg/picker/v1.php | 7 +-- lib/zin/wg/popovers/v1.php | 2 +- lib/zin/wg/pripicker/v1.php | 2 +- lib/zin/wg/productmenu/v1.php | 4 +- lib/zin/wg/programmenu/v1.php | 2 +- lib/zin/wg/row/v1.php | 3 +- lib/zin/wg/searchform/v1.php | 2 +- lib/zin/wg/searchtoggle/v1.php | 2 +- lib/zin/wg/sectioncard/v1.php | 4 +- lib/zin/wg/select/v1.php | 4 +- lib/zin/wg/severitylabel/v1.php | 2 +- lib/zin/wg/severitypicker/v1.php | 2 +- lib/zin/wg/sidebar/v1.php | 2 +- lib/zin/wg/tabledata/v1.php | 8 +-- lib/zin/wg/tabpane/v1.php | 2 +- lib/zin/wg/tabs/v1.php | 2 +- lib/zin/wg/textarea/v1.php | 2 +- lib/zin/wg/timepicker/v1.php | 2 +- lib/zin/wg/toolbar/v1.php | 4 +- lib/zin/wg/tooltip/v1.php | 2 +- lib/zin/wg/tree/v1.php | 2 +- lib/zin/wg/upload/v1.php | 2 +- lib/zin/wg/uploadimgs/v1.php | 2 +- lib/zin/wg/useravatar/v1.php | 2 +- lib/zin/zui/zui.class.php | 2 +- 87 files changed, 281 insertions(+), 275 deletions(-) diff --git a/lib/zin/core/directive.class.php b/lib/zin/core/directive.class.php index fd5bcdbf47..9e268ae524 100644 --- a/lib/zin/core/directive.class.php +++ b/lib/zin/core/directive.class.php @@ -15,13 +15,13 @@ require_once __DIR__ . DS . 'zin.class.php'; class directive { - public $type; + public string $type; - public $data; + public mixed $data; - public $options; + public ?array $options; - public $parent = null; + public ?wg $parent = null; /** * Construct a directive object @@ -30,7 +30,7 @@ class directive * @param array $options * @access public */ - public function __construct($type, $data, $options = null) + public function __construct(string $type, mixed $data, ?array $options = null) { $this->type = $type; $this->data = $data; @@ -39,7 +39,7 @@ class directive zin::renderInGlobal($this); } - public function __debugInfo() + public function __debugInfo(): array { return array( 'type' => $this->type, @@ -48,9 +48,9 @@ class directive ); } - public static function is($item, $type = null) + public static function is(mixed $item, ?string $type = null): bool { - return is_object($item) && $item instanceof directive && ($type === null || $item->type === $type); + return $item instanceof directive && ($type === null || $item->type === $type); } } @@ -59,7 +59,7 @@ function directive($type, $data, $options = null): directive return new directive($type, $data, $options); } -function isDirective($item, $type = null) +function isDirective(mixed $item, ?string $type = null): bool { return directive::is($item, $type); } diff --git a/lib/zin/core/h.class.php b/lib/zin/core/h.class.php index 4886e0744a..578c2327c8 100644 --- a/lib/zin/core/h.class.php +++ b/lib/zin/core/h.class.php @@ -23,12 +23,12 @@ class h extends wg 'selfClose?: bool' ); - public function getTagName() + public function getTagName(): string { return $this->props->get('tagName'); } - public function isDomElement() + public function isDomElement(): bool { return true; } @@ -41,70 +41,70 @@ class h extends wg return in_array($this->getTagName(), static::$selfCloseTags); } - public function build() + public function build(): array { if($this->isSelfClose()) return array($this->buildSelfCloseTag()); return array($this->buildTagBegin(), parent::build(), $this->buildTagEnd()); } - public function toJsonData() + public function toJsonData(): array { $data = parent::toJsonData(); $data['type'] = 'h:' . $this->getTagName(); return $data; } - public function type() + public function type(): string { return $this->getTagName(); } - public function shortType() + public function shortType(): string { return $this->getTagName(); } - protected function getPropsStr() + protected function getPropsStr(): string { $propStr = $this->props->toStr(array_keys(static::getDefinedProps())); if($this->props->hasEvent() && empty($this->id()) && $this->getTagName() !== 'html') $propStr = "$propStr id='$this->gid'"; return empty($propStr) ? '' : " $propStr"; } - protected function buildSelfCloseTag() + protected function buildSelfCloseTag(): string { $tagName = $this->getTagName(); $propStr = $this->getPropsStr(); return "<$tagName$propStr />"; } - protected function buildTagBegin() + protected function buildTagBegin(): string { $tagName = $this->getTagName(); $propStr = $this->getPropsStr(); return "<$tagName$propStr>"; } - protected function buildTagEnd() + protected function buildTagEnd(): string { $tagName = $this->getTagName(); return ""; } - public static function create() + public static function create(): h { $args = func_get_args(); $tagName = array_shift($args); return new h(is_string($tagName) ? set('tagName', $tagName) : $tagName, $args); } - public static function __callStatic($tagName, $args) + public static function __callStatic(string $tagName, array $args): h { return new h(set('tagName', $tagName), $args); } - public static function a() + public static function a(): h { $a = static::create('a', func_get_args()); if($a->prop('target') === '_blank' && !$a->hasProp('rel')) $a->prop('rel', 'noopener noreferrer'); @@ -271,7 +271,7 @@ class h extends wg return "(function(){\n$codes\n}());"; } - public static function jsRaw() + public static function jsRaw(): string { return 'RAWJS<' . implode("\n", func_get_args()) . '>RAWJS'; } diff --git a/lib/zin/core/h.func.php b/lib/zin/core/h.func.php index 589be4862c..ef751faf45 100644 --- a/lib/zin/core/h.func.php +++ b/lib/zin/core/h.func.php @@ -1,4 +1,5 @@ parent instanceof wg && method_exists($this->parent, 'onBuildItem')) { diff --git a/lib/zin/core/props.class.php b/lib/zin/core/props.class.php index bcf6375e3e..74026bacec 100644 --- a/lib/zin/core/props.class.php +++ b/lib/zin/core/props.class.php @@ -11,6 +11,9 @@ namespace zin; +use zin\utils\classlist; +use zin\utils\style; + require_once dirname(__DIR__) . DS . 'utils' . DS . 'dataset.class.php'; require_once dirname(__DIR__) . DS . 'utils' . DS . 'classlist.class.php'; require_once dirname(__DIR__) . DS . 'utils' . DS . 'style.class.php'; @@ -26,7 +29,7 @@ class props extends \zin\utils\dataset * @access public * @var style */ - public $style; + public style $style; /** * Class property @@ -34,7 +37,9 @@ class props extends \zin\utils\dataset * @access public * @var classlist */ - public $class; + public classlist $class; + + public static array $booleanAttrs = array('allowfullscreen', 'async', 'autofocus', 'autoplay', 'checked', 'controls', 'default', 'defer', 'disabled', 'formnovalidate', 'inert', 'ismap', 'itemscope', 'loop', 'multiple', 'muted', 'nomodule', 'novalidate', 'open', 'playsinline', 'readonly', 'required', 'reversed', 'selected'); /** * Create properties instance @@ -42,7 +47,7 @@ class props extends \zin\utils\dataset * @access public * @param array $props - Properties list array */ - public function __construct($props = null) + public function __construct(?array $props = null) { $this->style = new \zin\utils\style(); $this->class = new \zin\utils\classlist(); @@ -54,10 +59,10 @@ class props extends \zin\utils\dataset * Method for sub class to modify value on setting it * * @access public - * @param array|string $prop - Property name or properties list + * @param string $prop - Property name or properties list * @param mixed $value - Property value */ - protected function setVal($prop, $value) + protected function setVal(string $prop, mixed $value): props { if($prop === 'class' || $prop === '.') $this->class->set($value); elseif($prop === 'style' || $prop === '~') $this->style->set($value); @@ -73,7 +78,7 @@ class props extends \zin\utils\dataset return $this; } - protected function getVal($prop) + protected function getVal(string $prop): mixed { if($prop === 'class' || $prop === '.') { @@ -88,7 +93,11 @@ class props extends \zin\utils\dataset return parent::getVal($prop); } - public function reset($name, $value = null) + /** + * @param string|string[] $name + * @param mixed $value + */ + public function reset(array|string $name, mixed $value = null) { if(is_array($name)) { @@ -117,7 +126,7 @@ class props extends \zin\utils\dataset parent::setVal("@$name", $events); } - public function events() + public function events(): array { $events = array(); foreach($this->data as $name => $value) @@ -128,7 +137,7 @@ class props extends \zin\utils\dataset return $events; } - public function hasEvent() + public function hasEvent(): bool { foreach($this->data as $name => $value) { @@ -138,7 +147,7 @@ class props extends \zin\utils\dataset return false; } - public function hx($name, $value = null) + public function hx(array|string $name, ?string $value = null) { if(is_array($name)) { @@ -165,7 +174,7 @@ class props extends \zin\utils\dataset * * @access public */ - public function toStr($skipProps = array()) + public function toStr(array|string $skipProps = array()): string { if(is_string($skipProps)) $skipProps = explode(',', $skipProps); @@ -198,7 +207,7 @@ class props extends \zin\utils\dataset return implode(' ', $pairs); } - public function toJsonData() + public function toJsonData(): array { $data = $this->data; if(!empty($this->style->data)) $data['style'] = $this->style->data; @@ -206,7 +215,7 @@ class props extends \zin\utils\dataset return $data; } - public function skip($skipProps = array(), $skipFalse = false) + public function skip(array|string $skipProps = array(), bool $skipFalse = false): array { if(is_string($skipProps)) $skipProps = explode(',', $skipProps); @@ -220,7 +229,7 @@ class props extends \zin\utils\dataset return $data; } - public function pick($pickProps = array()) + public function pick(array|string $pickProps = array()): array { if(is_string($pickProps)) $pickProps = explode(',', $pickProps); @@ -237,15 +246,13 @@ class props extends \zin\utils\dataset * Clone a new instance * * @access public - * @return object + * @return props */ - public function clone() + public function clone(): props { $props = new props($this->data); $props->style = clone $this->style; $props->class = clone $this->class; return $props; } - - public static $booleanAttrs = ['allowfullscreen', 'async', 'autofocus', 'autoplay', 'checked', 'controls', 'default', 'defer', 'disabled', 'formnovalidate', 'inert', 'ismap', 'itemscope', 'loop', 'multiple', 'muted', 'nomodule', 'novalidate', 'open', 'playsinline', 'readonly', 'required', 'reversed', 'selected']; } diff --git a/lib/zin/core/rawcontent.class.php b/lib/zin/core/rawcontent.class.php index 56719e4b2e..023a73f211 100644 --- a/lib/zin/core/rawcontent.class.php +++ b/lib/zin/core/rawcontent.class.php @@ -1,4 +1,5 @@ $setting); diff --git a/lib/zin/core/selector.func.php b/lib/zin/core/selector.func.php index 98a83e8017..20c291c0a8 100644 --- a/lib/zin/core/selector.func.php +++ b/lib/zin/core/selector.func.php @@ -16,7 +16,7 @@ namespace zin; * @param string|object $selector * @return object|null */ -function parseWgSelector($selector) +function parseWgSelector(string|object $selector): ?object { if(is_object($selector)) return $selector; @@ -25,7 +25,15 @@ function parseWgSelector($selector) if($len < 1) return null; - $result = ['class' => [], 'id' => null, 'tag' => null, 'inner' => false, 'name' => null, 'first' => false, 'selector' => $selector]; + $result = array( + 'class' => array(), + 'id' => null, + 'tag' => null, + 'inner' => false, + 'name' => null, + 'first' => false, + 'selector' => $selector + ); if(str_contains($selector, '/')) { $parts = explode('/', $selector, 2); @@ -113,15 +121,15 @@ function parseWgSelector($selector) } /** - * Parse wg selectors - * @param array|string|object $selectors - * @return array + * Parse wg selectors. + * @param object|string|object[]|string[] $selectors + * @return object[] */ -function parseWgSelectors($selectors) +function parseWgSelectors(object|string|array $selectors): array { - if(is_object($selectors)) return [$selectors]; + if(is_object($selectors)) return array($selectors); if(is_string($selectors)) $selectors = explode(',', trim($selectors)); - $results = []; + $results = array(); foreach($selectors as $selector) { $selector = parseWgSelector($selector); @@ -130,7 +138,12 @@ function parseWgSelectors($selectors) return $results; } -function stringifyWgSelectors($selector) +/** + * Stringify wg selectors. + * @param object|object[] $selector + * @return string + */ +function stringifyWgSelectors(array|object $selector): string { if(empty($selector)) return ''; if(is_array($selector)) diff --git a/lib/zin/core/wg.class.php b/lib/zin/core/wg.class.php index 1667b5f1e1..56e4371d8f 100644 --- a/lib/zin/core/wg.class.php +++ b/lib/zin/core/wg.class.php @@ -44,19 +44,17 @@ class wg * @access public * @var props */ - public $props; + public props $props; - public $blocks = array(); + public array $blocks = array(); - public $parent = null; + public ?wg $parent = null; - public $gid; + public string $gid; - public $displayed = false; + public bool $displayed = false; - protected $matchedPortals = null; - - protected $renderOptions = null; + protected array $renderOptions = array(); public function __construct(/* string|element|object|array|null ...$args */) { @@ -73,12 +71,12 @@ class wg $this->checkErrors(); } - public function __debugInfo() + public function __debugInfo(): array { return $this->toJsonData(); } - public function isDomElement() + public function isDomElement(): bool { return false; } @@ -87,7 +85,7 @@ class wg * Check if the element is match any of the selectors * @param string|array|object $selectors */ - public function isMatch($selectors) + public function isMatch(string|array|object $selectors): bool { $list = parseWgSelectors($selectors); foreach($list as $selector) @@ -105,7 +103,7 @@ class wg * Build dom object * @return dom */ - public function buildDom() + public function buildDom(): dom { $before = $this->buildBefore(); $children = $this->build(); @@ -127,7 +125,7 @@ class wg * Render widget to html * @return string */ - public function render() + public function render(): string { $dom = $this->buildDom(); $result = $dom->render(); @@ -135,7 +133,7 @@ class wg return is_string($result) ? $result : json_encode($result); } - public function display(?array $options = array()): wg + public function display(array $options = array()): wg { zin::disableGlobalRender(); $this->renderOptions = $options; @@ -197,22 +195,22 @@ class wg protected function created() {} - protected function buildBefore() + protected function buildBefore(): array { return $this->block('before'); } - protected function buildAfter() + protected function buildAfter(): array { return $this->block('after'); } - protected function build() + protected function build(): array|wg|directive { return $this->children(); } - public function buildEvents() + public function buildEvents(): ?string { $events = $this->props->events(); if(empty($events)) return null; @@ -250,17 +248,17 @@ class wg } - protected function onAddBlock($child, $name) + protected function onAddBlock(array|string|wg|directive $child, string $name) { return $child; } - protected function onAddChild($child) + protected function onAddChild(array|string|wg|directive $child) { return $child; } - protected function onSetProp($prop, $value) + protected function onSetProp(array|string $prop, mixed $value) { if($prop === 'id' && $value === '$GID') $value = $this->gid; if($prop[0] === '@') @@ -271,12 +269,12 @@ class wg $this->props->set($prop, $value); } - protected function onGetProp($prop, $defaultValue) + protected function onGetProp(string $prop, mixed $defaultValue): mixed { return $this->props->get($prop, $defaultValue); } - public function add($item, $blockName = 'children') + public function add($item, string $blockName = 'children') { if($item === null || is_bool($item)) return $this; @@ -298,7 +296,7 @@ class wg return $this; } - public function addToBlock($name, $child = null) + public function addToBlock(array|string $name, array|string|null|wg|directive $child = null) { if(is_array($name)) { @@ -334,12 +332,12 @@ class wg else $this->blocks[$name] = array($child); } - public function children() + public function children(): array { return $this->block('children'); } - public function block($name) + public function block(string $name): array { $list = array(); if(isset($this->blocks[$name])) @@ -356,16 +354,15 @@ class wg return $list; } - public function hasBlock($name) + public function hasBlock(string $name): bool { return isset($this->blocks[$name]); } /** * Apply directive - * @param object $directive */ - public function directive(&$directive, $blockName) + public function directive(directive &$directive, array|string $blockName) { $data = $directive->data; $type = $directive->type; @@ -402,11 +399,10 @@ class wg { $this->add($blockChildren, $blockName); } - return; } } - public function prop($name, $defaultValue = null) + public function prop(array|string $name, mixed $defaultValue = null): mixed { if(is_array($name)) { @@ -425,11 +421,10 @@ class wg * Set property, an array can be passed to set multiple properties * * @access public - * @param array|string $prop - Property name or properties list + * @param props|array|string $prop - Property name or properties list * @param mixed $value - Property value - * @return dataset */ - public function setProp($prop, $value = null) + public function setProp(props|array|string $prop, mixed $value = null) { if($prop instanceof props) $prop = $prop->toJsonData(); @@ -444,22 +439,25 @@ class wg if($prop[0] === '#') { $this->add($value, substr($prop, 1)); - return; + return $this; } $this->onSetProp($prop, $value); return $this; } - public function hasProp() + public function hasProp(): bool { $names = func_get_args(); if(empty($names)) return false; - foreach ($names as $name) if(!$this->props->has($name)) return false; + foreach($names as $name) + { + if(!$this->props->has($name)) return false; + } return true; } - public function setDefaultProps($props) + public function setDefaultProps(array $props) { if(!is_array($props) || empty($props)) return; @@ -470,29 +468,29 @@ class wg } } - public function getRestProps() + public function getRestProps(): array { return $this->props->skip(array_keys(static::getDefinedProps())); } - public function type() + public function type(): string { return get_called_class(); } - public function shortType() + public function shortType(): string { $type = $this->type(); $pos = strrpos($type, '\\'); return $pos === false ? $type : substr($type, $pos + 1); } - public function id() + public function id(): ?string { return $this->prop('id'); } - public function toJsonData() + public function toJsonData(): array { $data = array(); $data['gid'] = $this->gid; @@ -599,7 +597,7 @@ class wg if(!empty($pageJS)) context::js($pageJS); } - public static function wgBlockMap() + public static function wgBlockMap(): array { $wgName = get_called_class(); if(!isset(wg::$wgToBlockMap[$wgName])) @@ -620,7 +618,7 @@ class wg return wg::$wgToBlockMap[$wgName]; } - public static function getBlockNameForWg($wg) + public static function getBlockNameForWg(wg|string $wg): ?string { $wgType = ($wg instanceof wg) ? $wg->type() : $wg; $wgBlockMap = static::wgBlockMap(); @@ -628,7 +626,7 @@ class wg return isset($wgBlockMap[$wgType]) ? $wgBlockMap[$wgType] : null; } - protected static function getDefinedProps(string|null $wgName = null): array + protected static function getDefinedProps(?string $wgName = null): array { if($wgName === null) $wgName = get_called_class(); @@ -639,7 +637,7 @@ class wg return wg::$definedPropsMap[$wgName]; } - protected static function getDefaultProps(string|null $wgName = null): array + protected static function getDefaultProps(?string $wgName = null): array { $defaultProps = array(); foreach(static::getDefinedProps($wgName) as $name => $definition) diff --git a/lib/zin/utils/dataset.class.php b/lib/zin/utils/dataset.class.php index 535a0de1f4..208a220d0e 100644 --- a/lib/zin/utils/dataset.class.php +++ b/lib/zin/utils/dataset.class.php @@ -22,7 +22,7 @@ class dataset * @var array * @access public */ - public $data = array(); + public array $data = array(); /** * Create an instance, the initialed data can be passed @@ -30,7 +30,7 @@ class dataset * @access public * @param array $data - Properties list array */ - public function __construct($data = null) + public function __construct(?array $data = null) { if($data !== null) $this->set($data); } @@ -43,7 +43,7 @@ class dataset * @param mixed $value - Property value * @return void */ - public function __set($name, $value) + public function __set(string $name, mixed $value) { $this->set($name, $value); } @@ -55,7 +55,7 @@ class dataset * @param string $prop - Property name * @return mixed */ - public function __get($name) + public function __get(string $name) { $this->get($name); } @@ -67,7 +67,7 @@ class dataset * @param string $prop - Property name * @return bool */ - public function __isset($name) + public function __isset(string $name): bool { return $this->has($name); } @@ -79,7 +79,7 @@ class dataset * @param string $prop - Property name * @return void */ - public function __unset($name) + public function __unset(string $name) { $this->remove($name); } @@ -90,7 +90,7 @@ class dataset * @access public * @return string */ - public function __toString() + public function __toString(): string { return $this->toStr(); } @@ -101,7 +101,7 @@ class dataset * @access public * @return string */ - public function __invoke($name = null, $value = null) + public function __invoke(string|array $name = null, mixed $value = null): string { if($value !== null || is_array($name)) return $this->set($name, $value); if(is_string($name)) return $this->get($name); @@ -125,7 +125,7 @@ class dataset * @access public * @return mixed */ - public function __call($name, $args) + public function __call(string $name, array $args): mixed { if(count($args)) return $this->set($name, $args[0]); @@ -135,18 +135,18 @@ class dataset /** * Method for sub class to modify value on setting it * - * @access public - * @param array|string $prop - Property name or properties list + * @access protected + * @param string $prop - Property name or properties list * @param mixed $value - Property value * @return dataset */ - protected function setVal($prop, $value) + protected function setVal(string $prop, mixed $value): dataset { $this->data[$prop] = $value; return $this; } - protected function getVal($prop) + protected function getVal(string $prop): mixed { return isset($this->data[$prop]) ? $this->data[$prop] : null; } @@ -158,7 +158,7 @@ class dataset * @param bool $skipEmpty - Whether to skip to count empty value * @return int */ - public function count($skipEmpty = false) + public function count($skipEmpty = false): int { if(!$skipEmpty) return count($this->data); @@ -176,12 +176,13 @@ class dataset * @access public * @return string */ - public function toStr() + public function toStr(): string { return json_encode($this->toJsonData()); } - public function toJsonData() { + public function toJsonData(): array + { return $this->data; } @@ -191,10 +192,9 @@ class dataset * @access public * @param array|string $prop - Property name or properties list * @param mixed $value - Property value - * @param bool $removeEmpty - Whether to remove empty value * @return dataset */ - public function set($prop, $value = null) + public function set(array|string $prop, mixed $value = null): dataset { if(is_array($prop)) { diff --git a/lib/zin/utils/style.class.php b/lib/zin/utils/style.class.php index 3f6fc66f22..797b940d0e 100644 --- a/lib/zin/utils/style.class.php +++ b/lib/zin/utils/style.class.php @@ -56,14 +56,14 @@ class style extends dataset * $style->cssVar('text-size', '14px'); * * // Set multiple variables - * $style->cssVar(array('text-color' => 'yellow', 'background-image': 'none')); + * $style->cssVar(array('text-color' => 'yellow', 'background-image' => 'none')); * * // Get variable value * echo $style->cssVar('text-size'); // Output "14px" * * // Get all variables value * echo $style->cssVar(); - * // Output array('text-size' => '14px', 'color' => 'yellow', 'background': 'none'); + * // Output array('text-size' => '14px', 'color' => 'yellow', 'background' => 'none'); * * // Remove variable by setting value with an empty string * $style->cssVar('text-color', ''); @@ -73,7 +73,7 @@ class style extends dataset * @param mixed $value - Property value * @return mixed */ - public function cssVar($name = '', $value = null) + public function cssVar(array|string $name = '', ?string $value = null): style|array|string { /* Support for setting multiple variables by an array */ if(is_array($name)) @@ -110,7 +110,7 @@ class style extends dataset * @access public * @return string */ - public function toStr() + public function toStr(): string { return $this->toCss(); } @@ -121,7 +121,7 @@ class style extends dataset * @access public * @return string */ - public function toCss() + public function toCss(): string { $pairs = array(); @@ -139,10 +139,10 @@ class style extends dataset /** * Create an instance * - * @param string $style - CSS style list + * @param ?array $style - CSS style list * @return style */ - static public function new($style = null) + public static function new(?array $style = null): style { return new style($style); } @@ -151,10 +151,10 @@ class style extends dataset * Create css from style list * * @access public - * @param string $style - CSS style list + * @param ?array $style - CSS style list * @return string */ - static public function css($style) + public static function css(?array $style): string { return (new style($style))->toCss(); } @@ -166,7 +166,7 @@ class style extends dataset * @param string $name - CSS variable name * @return string */ - static public function formatVarName($name) + public static function formatVarName(string $name): string { return \zin\str_starts_with($name, '--') ? $name : "--$name"; } diff --git a/lib/zin/wg/actionitem/v1.php b/lib/zin/wg/actionitem/v1.php index c45bb7074f..97c34e9ac7 100644 --- a/lib/zin/wg/actionitem/v1.php +++ b/lib/zin/wg/actionitem/v1.php @@ -123,7 +123,7 @@ class actionItem extends wg ); } - protected function build() + protected function build(): wg { list($name, $type, $outerTag, $outerProps, $outerClass) = $this->prop(array('name', 'type', 'outerTag', 'outerProps', 'outerClass')); diff --git a/lib/zin/wg/avatar/v1.php b/lib/zin/wg/avatar/v1.php index c623b57c6e..6fd91bd39a 100644 --- a/lib/zin/wg/avatar/v1.php +++ b/lib/zin/wg/avatar/v1.php @@ -39,7 +39,7 @@ class avatar extends wg return $child; } - protected function build() + protected function build(): wg { /* Attach classes. */ $this->finalClass[] = $this->prop('className'); diff --git a/lib/zin/wg/batchactions/v1.php b/lib/zin/wg/batchactions/v1.php index 62fcd23a36..a751a69def 100644 --- a/lib/zin/wg/batchactions/v1.php +++ b/lib/zin/wg/batchactions/v1.php @@ -13,7 +13,7 @@ class batchActions extends wg return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build() + protected function build(): wg { return formGroup ( diff --git a/lib/zin/wg/btn/v1.php b/lib/zin/wg/btn/v1.php index 29555a35ae..e2ef19c5ce 100644 --- a/lib/zin/wg/btn/v1.php +++ b/lib/zin/wg/btn/v1.php @@ -89,7 +89,7 @@ class btn extends wg return $classList; } - protected function build() + protected function build(): wg { $props = $this->getProps(); $children = $this->getChildren(); diff --git a/lib/zin/wg/btngroup/v1.php b/lib/zin/wg/btngroup/v1.php index 2684ede4e2..6bdb96898d 100644 --- a/lib/zin/wg/btngroup/v1.php +++ b/lib/zin/wg/btngroup/v1.php @@ -10,7 +10,7 @@ class btnGroup extends wg 'size?:string', ); - public function onBuildItem($item) + public function onBuildItem($item): btn { if(!($item instanceof item)) $item = item(set($item)); return btn(inherit($item)); @@ -28,7 +28,7 @@ class btnGroup extends wg return $className; } - protected function build() + protected function build(): wg { $items = $this->prop('items'); $className = $this->getclassName(); diff --git a/lib/zin/wg/burn/v1.php b/lib/zin/wg/burn/v1.php index 91e0decb22..bb1c038e53 100644 --- a/lib/zin/wg/burn/v1.php +++ b/lib/zin/wg/burn/v1.php @@ -26,8 +26,7 @@ class burn extends wg * @var array * @access protected */ - protected static array $defineProps = array - ( + protected static array $defineProps = array( 'data?: string|array', // 数据源 'referenceLine?: bool=false' // 参考线 ); @@ -35,7 +34,7 @@ class burn extends wg /** * Build widget. */ - protected function build(): wg + protected function build(): zui { return zui::burn(inherit($this)); } diff --git a/lib/zin/wg/cell/v1.php b/lib/zin/wg/cell/v1.php index e54adc517b..3925c0ee9d 100644 --- a/lib/zin/wg/cell/v1.php +++ b/lib/zin/wg/cell/v1.php @@ -13,7 +13,7 @@ class cell extends wg 'flex:string' ); - protected function build() + protected function build(): wg { $basis = empty($this->prop('width')) ? 'auto' : $this->prop('width'); if(is_numeric($basis)) $basis .= 'px'; diff --git a/lib/zin/wg/center/v1.php b/lib/zin/wg/center/v1.php index f80cbc62d9..74255b09e9 100644 --- a/lib/zin/wg/center/v1.php +++ b/lib/zin/wg/center/v1.php @@ -4,7 +4,7 @@ namespace zin; class center extends wg { - protected function build() + protected function build(): wg { return div ( diff --git a/lib/zin/wg/checkbox/v1.php b/lib/zin/wg/checkbox/v1.php index 191ec85c1d..eaadd75e9d 100644 --- a/lib/zin/wg/checkbox/v1.php +++ b/lib/zin/wg/checkbox/v1.php @@ -53,7 +53,7 @@ class checkbox extends wg ); } - protected function build() + protected function build(): wg { if($this->prop('primary')) return $this->buildPrimary(); list($text, $type, $typeClass) = $this->prop(array('text', 'type', 'typeClass')); diff --git a/lib/zin/wg/checklist/v1.php b/lib/zin/wg/checklist/v1.php index 0ec8f03cfc..48125e73cb 100644 --- a/lib/zin/wg/checklist/v1.php +++ b/lib/zin/wg/checklist/v1.php @@ -24,7 +24,7 @@ class checkList extends wg return [$value]; } - public function onBuildItem($item) + public function onBuildItem($item): checkbox { if($item instanceof item) $item = $item->props->toJsonData(); @@ -40,7 +40,7 @@ class checkList extends wg return new checkbox(set($props), set($item)); } - protected function build() + protected function build(): wg { list($items, $inline) = $this->prop(['items', 'inline']); diff --git a/lib/zin/wg/col/v1.php b/lib/zin/wg/col/v1.php index d7fd49e6a7..cfa83ee973 100644 --- a/lib/zin/wg/col/v1.php +++ b/lib/zin/wg/col/v1.php @@ -9,7 +9,7 @@ class col extends wg 'align?:string' ); - protected function build() + protected function build(): wg { $classList = 'col'; list($justify, $align) = $this->prop(array('justify', 'align')); diff --git a/lib/zin/wg/collapsebtn/v1.php b/lib/zin/wg/collapsebtn/v1.php index e4829431c5..9d5b3665cb 100644 --- a/lib/zin/wg/collapsebtn/v1.php +++ b/lib/zin/wg/collapsebtn/v1.php @@ -11,7 +11,7 @@ class collapseBtn extends wg 'parent: string' // 目标元素与按钮共同的父级元素选择器,使用 closest 辅助目标元素的确定。 ); - protected function build() + protected function build(): wg { $target = $this->prop('target'); $parent = $this->prop('parent'); diff --git a/lib/zin/wg/detailbody/v1.php b/lib/zin/wg/detailbody/v1.php index a4a810ad05..bbbff10d64 100644 --- a/lib/zin/wg/detailbody/v1.php +++ b/lib/zin/wg/detailbody/v1.php @@ -25,7 +25,7 @@ class detailBody extends wg return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build() + protected function build(): wg { $main = $this->block('main'); $side = $this->block('side'); diff --git a/lib/zin/wg/dragul/v1.php b/lib/zin/wg/dragul/v1.php index bbec48ef06..fb7cb027ba 100644 --- a/lib/zin/wg/dragul/v1.php +++ b/lib/zin/wg/dragul/v1.php @@ -100,7 +100,7 @@ class dragUl extends wg $this->ul->add(on::drop($func)); } - protected function build() + protected function build(): wg { $ul = ul ( diff --git a/lib/zin/wg/dropdown/v1.php b/lib/zin/wg/dropdown/v1.php index c7943fb91e..88df196494 100644 --- a/lib/zin/wg/dropdown/v1.php +++ b/lib/zin/wg/dropdown/v1.php @@ -31,7 +31,7 @@ class dropdown extends wg 'items' => array('map' => 'item') ); - protected function build() + protected function build(): array { list($items, $placement, $strategy, $offset, $flip, $subMenuTrigger, $arrow, $trigger, $menuProps, $target, $id, $menuClass, $hasIcons, $staticMenu) = $this->prop(array('items', 'placement', 'strategy', 'offset', 'flip', 'subMenuTrigger', 'arrow', 'trigger', 'menuProps', 'target', 'id', 'menuClass', 'hasIcons', 'staticMenu')); diff --git a/lib/zin/wg/dropmenu/v1.php b/lib/zin/wg/dropmenu/v1.php index 8019a4b7a0..e57dbdaaae 100644 --- a/lib/zin/wg/dropmenu/v1.php +++ b/lib/zin/wg/dropmenu/v1.php @@ -46,7 +46,7 @@ class dropmenu extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build(): zui { list($url, $text, $objectID, $cache, $tab, $module, $method, $extra, $id, $data) = $this->prop(array('url', 'text', 'objectID', 'cache', 'tab', 'module', 'method', 'extra', 'id', 'data')); diff --git a/lib/zin/wg/dtable/v1.php b/lib/zin/wg/dtable/v1.php index 0dac6023fd..b7e99443be 100644 --- a/lib/zin/wg/dtable/v1.php +++ b/lib/zin/wg/dtable/v1.php @@ -113,7 +113,7 @@ class dtable extends wg return $setting; } - protected function build() + protected function build(): zui { if(empty($this->prop('data'))) { diff --git a/lib/zin/wg/echarts/v1.php b/lib/zin/wg/echarts/v1.php index 229b36f0be..df06f4d6d4 100644 --- a/lib/zin/wg/echarts/v1.php +++ b/lib/zin/wg/echarts/v1.php @@ -30,7 +30,7 @@ class echarts extends wg return $this; } - protected function build() + protected function build(): zui { return zui::echarts(inherit($this)); } diff --git a/lib/zin/wg/editor/v1.php b/lib/zin/wg/editor/v1.php index dc0f0fb456..ca2ea0cf56 100644 --- a/lib/zin/wg/editor/v1.php +++ b/lib/zin/wg/editor/v1.php @@ -25,7 +25,7 @@ class editor extends wg // 'userColor?: string="#ffcc00"' ); - protected function build() + protected function build(): wg { $editor = new h(set::tagName('tiptap-editor')); $props = $this->props->pick(array('createInput', 'uploadUrl', 'placeholder', 'fullscreenable', 'resizable', 'exposeEditor', 'size', 'hideMenubar', 'bubbleMenu', 'menubarMode', 'collaborative', 'hocuspocus', 'docName', 'username', 'userColor')); diff --git a/lib/zin/wg/featurebar/v1.php b/lib/zin/wg/featurebar/v1.php index ee8917d9bc..9bf40f91ad 100644 --- a/lib/zin/wg/featurebar/v1.php +++ b/lib/zin/wg/featurebar/v1.php @@ -135,7 +135,7 @@ class featureBar extends wg ); } - protected function build() + protected function build(): wg { return div ( diff --git a/lib/zin/wg/formbatchitem/v1.php b/lib/zin/wg/formbatchitem/v1.php index 4226af6c5b..60ba7f7b0e 100644 --- a/lib/zin/wg/formbatchitem/v1.php +++ b/lib/zin/wg/formbatchitem/v1.php @@ -54,10 +54,9 @@ class formBatchItem extends wg /** * Define default properties. * - * @var array * @access protected */ - protected function build() + protected function build(): array { list($name, $label, $labelClass, $labelProps, $required, $tip, $tipClass, $tipProps, $tipIcon, $control, $width, $strong, $value, $disabled, $items, $placeholder, $ditto, $defaultDitto, $hidden, $readonly, $multiple) = $this->prop(array('name', 'label', 'labelClass', 'labelProps', 'required', 'tip', 'tipClass', 'tipProps', 'tipIcon', 'control', 'width', 'strong', 'value', 'disabled', 'items', 'placeholder', 'ditto', 'defaultDitto', 'hidden', 'readonly', 'multiple')); diff --git a/lib/zin/wg/formgroup/v1.php b/lib/zin/wg/formgroup/v1.php index 9eba657446..a64723f0cf 100644 --- a/lib/zin/wg/formgroup/v1.php +++ b/lib/zin/wg/formgroup/v1.php @@ -27,7 +27,7 @@ class formGroup extends wg 'placeholder?: string' ); - protected function build() + protected function build(): wg { list($name, $label, $labelClass, $labelProps, $labelWidth, $required, $tip, $tipClass, $tipProps, $control, $width, $strong, $value, $disabled, $items, $placeholder, $readonly) = $this->prop(['name', 'label', 'labelClass', 'labelProps', 'labelWidth', 'required', 'tip', 'tipClass', 'tipProps', 'control', 'width', 'strong', 'value', 'disabled', 'items', 'placeholder', 'readonly']); diff --git a/lib/zin/wg/formlabel/v1.php b/lib/zin/wg/formlabel/v1.php index 88537ab30a..7f4a112ace 100644 --- a/lib/zin/wg/formlabel/v1.php +++ b/lib/zin/wg/formlabel/v1.php @@ -19,7 +19,7 @@ class formLabel extends wg } } - protected function build() + protected function build(): wg { list($text, $required, $for) = $this->prop(['text', 'required', 'for']); return h::label diff --git a/lib/zin/wg/formrow/v1.php b/lib/zin/wg/formrow/v1.php index 346e83e2a9..86fda43654 100644 --- a/lib/zin/wg/formrow/v1.php +++ b/lib/zin/wg/formrow/v1.php @@ -12,7 +12,7 @@ class formRow extends wg 'hidden?: boolean' ); - public function onBuildItem($item) + public function onBuildItem($item): wg { if(!($item instanceof item)) { @@ -23,7 +23,7 @@ class formRow extends wg return new formGroup(inherit($item)); } - protected function build() + protected function build(): wg { list($width, $items, $hidden) = $this->prop(['width', 'items', 'hidden']); diff --git a/lib/zin/wg/formsettingbtn/v1.php b/lib/zin/wg/formsettingbtn/v1.php index f6520020ba..baf74b892b 100644 --- a/lib/zin/wg/formsettingbtn/v1.php +++ b/lib/zin/wg/formsettingbtn/v1.php @@ -29,7 +29,7 @@ class formSettingBtn extends wg return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build() + protected function build(): wg { $customFields = $this->prop('customFields', array()); diff --git a/lib/zin/wg/fragment/v1.php b/lib/zin/wg/fragment/v1.php index 6ce4902b31..ebdfb09f54 100644 --- a/lib/zin/wg/fragment/v1.php +++ b/lib/zin/wg/fragment/v1.php @@ -9,7 +9,7 @@ class fragment extends wg 'rawContent?: bool' ); - protected function build() + protected function build(): array { $css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/'); $js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS')); diff --git a/lib/zin/wg/header/v1.php b/lib/zin/wg/header/v1.php index cb1bbe847c..7295f0ff5f 100644 --- a/lib/zin/wg/header/v1.php +++ b/lib/zin/wg/header/v1.php @@ -57,9 +57,8 @@ class header extends wg * Build. * * @access protected - * @return object */ - protected function build() + protected function build(): wg { return h::header ( diff --git a/lib/zin/wg/heading/v1.php b/lib/zin/wg/heading/v1.php index 61f2b01941..6b29f0b263 100644 --- a/lib/zin/wg/heading/v1.php +++ b/lib/zin/wg/heading/v1.php @@ -90,12 +90,9 @@ class heading extends wg * Build. * * @access protected - * @return object */ - protected function build() + protected function build(): wg { - $showAppName = $this->prop('showAppName'); - return div ( set::id('heading'), diff --git a/lib/zin/wg/icon/v1.php b/lib/zin/wg/icon/v1.php index 9191b65a2c..369b0d6c4e 100644 --- a/lib/zin/wg/icon/v1.php +++ b/lib/zin/wg/icon/v1.php @@ -18,7 +18,7 @@ class icon extends wg } } - protected function build() + protected function build(): wg { list($name, $size) = $this->prop(array('name', 'size')); return h::i diff --git a/lib/zin/wg/input/v1.php b/lib/zin/wg/input/v1.php index 20f8449912..02ac3bdd77 100644 --- a/lib/zin/wg/input/v1.php +++ b/lib/zin/wg/input/v1.php @@ -22,7 +22,7 @@ class input extends wg 'class' => 'form-control', ); - protected function build() + protected function build(): wg { $props = $this->props->skip('required'); $required = $this->prop('required'); diff --git a/lib/zin/wg/inputgroup/v1.php b/lib/zin/wg/inputgroup/v1.php index a9bfbf1fe8..eeb98f0c10 100644 --- a/lib/zin/wg/inputgroup/v1.php +++ b/lib/zin/wg/inputgroup/v1.php @@ -13,7 +13,7 @@ class inputGroup extends wg 'seg?:bool' ); - public function onBuildItem($item) + public function onBuildItem($item): wg { if(is_string($item)) $item = new item(set(['type' => 'addon', 'text' => $item])); elseif(is_array($item)) $item = new item(set($item)); @@ -37,7 +37,7 @@ class inputGroup extends wg return new input(inherit($item)); } - protected function build() + protected function build(): wg { list($items, $seg) = $this->prop(['items', 'seg']); $children = $this->children(); diff --git a/lib/zin/wg/inputgroupaddon/v1.php b/lib/zin/wg/inputgroupaddon/v1.php index 4d207dddbb..4da97ef37c 100644 --- a/lib/zin/wg/inputgroupaddon/v1.php +++ b/lib/zin/wg/inputgroupaddon/v1.php @@ -20,7 +20,7 @@ namespace zin; */ class inputGroupAddon extends wg { - protected function build() + protected function build(): wg { return h::span(setClass('input-group-addon'), set($this->props), $this->children()); } diff --git a/lib/zin/wg/label/v1.php b/lib/zin/wg/label/v1.php index 5b9689bfaa..8e1ea8c562 100644 --- a/lib/zin/wg/label/v1.php +++ b/lib/zin/wg/label/v1.php @@ -17,7 +17,7 @@ class label extends wg } } - public function build() + public function build(): wg { return span ( diff --git a/lib/zin/wg/mainmenu/v1.php b/lib/zin/wg/mainmenu/v1.php index b831fdd96f..7cdac2b5ab 100644 --- a/lib/zin/wg/mainmenu/v1.php +++ b/lib/zin/wg/mainmenu/v1.php @@ -27,7 +27,7 @@ class mainMenu extends wg return null; } - protected function build() + protected function build(): wg { $others = $this->prop('others'); diff --git a/lib/zin/wg/mainnavbar/v1.php b/lib/zin/wg/mainnavbar/v1.php index 235577e2e8..3cab0bedba 100644 --- a/lib/zin/wg/mainnavbar/v1.php +++ b/lib/zin/wg/mainnavbar/v1.php @@ -83,7 +83,7 @@ class mainNavbar extends nav * @access protected * @return wg */ - protected function build(): wg + protected function build(): h { if(!$this->prop('items')) return div(); diff --git a/lib/zin/wg/menu/v1.php b/lib/zin/wg/menu/v1.php index 0dcfc24bfc..d05752314b 100644 --- a/lib/zin/wg/menu/v1.php +++ b/lib/zin/wg/menu/v1.php @@ -10,7 +10,7 @@ class menu extends wg 'items?:array' ); - public function onBuildItem($item) + public function onBuildItem($item): wg { if(!($item instanceof item)) $item = item(set($item)); return actionItem @@ -23,7 +23,7 @@ class menu extends wg /** * @return builder */ - protected function build() + protected function build(): wg { $items = $this->prop('items'); return h::menu diff --git a/lib/zin/wg/modal/v1.php b/lib/zin/wg/modal/v1.php index c7f9c644b8..2641289ad1 100644 --- a/lib/zin/wg/modal/v1.php +++ b/lib/zin/wg/modal/v1.php @@ -15,7 +15,7 @@ class modal extends modalDialog 'modalProps' => array() ); - protected function build() + protected function build(): wg { list($id, $modalProps) = $this->prop(array('id', 'modalProps')); diff --git a/lib/zin/wg/modaldialog/v1.php b/lib/zin/wg/modaldialog/v1.php index ecf222cf0a..af2dd99195 100644 --- a/lib/zin/wg/modaldialog/v1.php +++ b/lib/zin/wg/modaldialog/v1.php @@ -93,7 +93,7 @@ class modalDialog extends wg ); } - protected function build() + protected function build(): wg { $size = $this->prop('size'); if($size) diff --git a/lib/zin/wg/modalheader/v1.php b/lib/zin/wg/modalheader/v1.php index c51f5e590f..be5fe359d8 100644 --- a/lib/zin/wg/modalheader/v1.php +++ b/lib/zin/wg/modalheader/v1.php @@ -33,7 +33,7 @@ class modalHeader extends wg $this->setDefaultProps(array('title' => $title, 'entityText' => $entityText, 'entityID' => $entityID)); } - protected function build() + protected function build(): wg { list($title, $entityText, $entityID) = $this->prop(array('title', 'entityText', 'entityID')); diff --git a/lib/zin/wg/modaltrigger/v1.php b/lib/zin/wg/modaltrigger/v1.php index 3f1d32d2b5..db0b4c603a 100644 --- a/lib/zin/wg/modaltrigger/v1.php +++ b/lib/zin/wg/modaltrigger/v1.php @@ -32,7 +32,7 @@ class modalTrigger extends wg 'modal' => array('map' => 'modal') ); - protected function build() + protected function build(): array { list($target, $url, $type) = $this->prop(['target', 'url', 'type']); diff --git a/lib/zin/wg/modulemenu/v1.php b/lib/zin/wg/modulemenu/v1.php index c1f8b5e6d0..9aa47992ed 100644 --- a/lib/zin/wg/modulemenu/v1.php +++ b/lib/zin/wg/modulemenu/v1.php @@ -4,7 +4,7 @@ namespace zin; class moduleMenu extends wg { - private $modules = array(); + private array $modules = array(); protected static array $defineProps = array( 'modules: array', @@ -75,7 +75,7 @@ class moduleMenu extends wg return ''; } - private function buildBtns() + private function buildBtns(): wg { $settingLink = $this->prop('settingLink'); $showDisplay = $this->prop('showDisplay'); @@ -113,7 +113,7 @@ class moduleMenu extends wg ); } - private function buildCloseBtn() + private function buildCloseBtn(): ?wg { $activeKey = $this->prop('activeKey'); if(empty($activeKey)) return null; diff --git a/lib/zin/wg/monaco/v1.php b/lib/zin/wg/monaco/v1.php index c47a019408..1586d63bb9 100644 --- a/lib/zin/wg/monaco/v1.php +++ b/lib/zin/wg/monaco/v1.php @@ -23,7 +23,7 @@ class monaco extends wg return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build() + protected function build(): wg { global $app; $vsPath = $app->getWebRoot() . 'js/monaco-editor/min/vs'; diff --git a/lib/zin/wg/nav/v1.php b/lib/zin/wg/nav/v1.php index 8bbe23ccc7..5f52b0d427 100644 --- a/lib/zin/wg/nav/v1.php +++ b/lib/zin/wg/nav/v1.php @@ -10,7 +10,7 @@ class nav extends wg 'items?:array' // 使用数组指定导航中的每一项。 ); - public function onBuildItem($item) + public function onBuildItem($item): wg { return new actionItem ( @@ -19,10 +19,7 @@ class nav extends wg ); } - /** - * @return builder - */ - protected function build() + protected function build(): wg { $items = $this->prop('items'); return h::menu diff --git a/lib/zin/wg/navbar/v1.php b/lib/zin/wg/navbar/v1.php index 3940389cd0..3527dd0d8e 100644 --- a/lib/zin/wg/navbar/v1.php +++ b/lib/zin/wg/navbar/v1.php @@ -277,9 +277,8 @@ class navbar extends wg * Build. * * @access protected - * @return object */ - protected function build() + protected function build(): wg { return h::nav ( diff --git a/lib/zin/wg/overviewblock/v1.php b/lib/zin/wg/overviewblock/v1.php index 1078b87703..eb04394b2c 100644 --- a/lib/zin/wg/overviewblock/v1.php +++ b/lib/zin/wg/overviewblock/v1.php @@ -26,7 +26,7 @@ class overviewBlock extends wg return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - protected function buildCard($card) + protected function buildCard($card): wg { $class = 'text-2xl text-center font-bold leading-relaxed ' . (!empty($card->class) ? $card->class : ''); @@ -51,7 +51,7 @@ class overviewBlock extends wg ); } - protected function buildCards($group) + protected function buildCards($group): wg { $cards = array(); foreach($group->cards as $card) $cards[] = $this->buildCard($card); @@ -63,7 +63,7 @@ class overviewBlock extends wg ); } - protected function buildBarChart($group) + protected function buildBarChart($group): wg { $bars = array(); $labels = array(); @@ -116,7 +116,7 @@ class overviewBlock extends wg ); } - protected function buildBody($groups) + protected function buildBody($groups): array { $body = array(); foreach($groups as $group) @@ -128,7 +128,7 @@ class overviewBlock extends wg return $body; } - protected function build() + protected function build(): wg { list($id, $title, $block, $groups) = $this->prop(array('id', 'title', 'block', 'groups')); diff --git a/lib/zin/wg/page/v1.php b/lib/zin/wg/page/v1.php index 52799f19d9..01b763bfe3 100644 --- a/lib/zin/wg/page/v1.php +++ b/lib/zin/wg/page/v1.php @@ -11,8 +11,7 @@ class page extends pageBase { protected static array $defaultProps = array('zui' => true); - protected static array $defineBlocks = array - ( + protected static array $defineBlocks = array( 'head' => array(), 'header' => array('map' => 'header'), 'heading' => array('map' => 'heading'), @@ -21,7 +20,7 @@ class page extends pageBase 'footer' => array(), ); - protected function buildHeader() + protected function buildHeader(): array|wg { if($this->hasBlock('header')) return $this->block('header'); @@ -32,7 +31,7 @@ class page extends pageBase return new header(new heading($dropmenuBlock)); } - protected function buildBody() + protected function buildBody(): array { if($this->hasBlock('main')) { diff --git a/lib/zin/wg/pagebase/v1.php b/lib/zin/wg/pagebase/v1.php index eee3b53bc2..67a0ecffdb 100644 --- a/lib/zin/wg/pagebase/v1.php +++ b/lib/zin/wg/pagebase/v1.php @@ -42,7 +42,7 @@ class pageBase extends wg return $this->children(); } - protected function build() + protected function build(): wg { global $lang, $config, $app; diff --git a/lib/zin/wg/pageform/v1.php b/lib/zin/wg/pageform/v1.php index 47a56ebdd0..49befd4ecb 100644 --- a/lib/zin/wg/pageform/v1.php +++ b/lib/zin/wg/pageform/v1.php @@ -11,7 +11,7 @@ class pageForm extends page 'formPanel?: array' ); - public function children() + public function children(): array { return array( formPanel(set($this->prop('formPanel')), parent::children()) diff --git a/lib/zin/wg/pager/v1.php b/lib/zin/wg/pager/v1.php index 54aaca3267..bbd3147eaf 100644 --- a/lib/zin/wg/pager/v1.php +++ b/lib/zin/wg/pager/v1.php @@ -4,7 +4,7 @@ namespace zin; class pager extends wg { - protected function build() + protected function build(): zui { return zui::pager(inherit($this)); } diff --git a/lib/zin/wg/panel/v1.php b/lib/zin/wg/panel/v1.php index 566ee2e0ea..89a509d7c6 100644 --- a/lib/zin/wg/panel/v1.php +++ b/lib/zin/wg/panel/v1.php @@ -4,8 +4,7 @@ namespace zin; class panel extends wg { - protected static array $defineProps = array - ( + protected static array $defineProps = array( 'class?: string="rounded shadow ring-0 canvas"', // 类名。 'size?: "sm"|"lg"', // 额外尺寸。 'title?: string', // 标题。 @@ -21,14 +20,13 @@ class panel extends wg 'footerProps?: array' // 底部属性。 ); - protected static array $defineBlocks = array - ( + protected static array $defineBlocks = array( 'heading' => array(), 'headingActions' => array('map' => 'toolbar'), 'footer' => array('map' => 'nav') ); - protected function buildHeadingActions() + protected function buildHeadingActions(): ?wg { $actionsBlock = $this->block('headingActions'); $actions = $this->prop('headingActions'); @@ -43,7 +41,7 @@ class panel extends wg ); } - protected function buildHeading() + protected function buildHeading(): wg { list($title, $size) = $this->prop(['title', 'size']); $headingBlock = $this->block('heading'); @@ -61,7 +59,7 @@ class panel extends wg ); } - protected function buildBody() + protected function buildBody(): wg { return div ( @@ -71,12 +69,12 @@ class panel extends wg ); } - protected function buildFooter() + protected function buildFooter(): ?wg { list($footerActions) = $this->prop(array('footerActions')); $footerBlock = $this->block('footer'); - if(empty($footerActions) && empty($footerBlock)) return; + if(empty($footerActions) && empty($footerBlock)) return null; return div ( @@ -93,7 +91,7 @@ class panel extends wg return array(setClass('panel', $class, empty($size) ? null : "size-$size")); } - protected function build() + protected function build(): wg { return div ( diff --git a/lib/zin/wg/pastedialog/v1.php b/lib/zin/wg/pastedialog/v1.php index 21a2eaab33..623265fe97 100644 --- a/lib/zin/wg/pastedialog/v1.php +++ b/lib/zin/wg/pastedialog/v1.php @@ -1,6 +1,5 @@ props->toJsonData(); $items = $props['items']; @@ -103,7 +102,7 @@ class picker extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build(): zui { return zui::picker ( diff --git a/lib/zin/wg/popovers/v1.php b/lib/zin/wg/popovers/v1.php index 633863c229..56b50af1f2 100644 --- a/lib/zin/wg/popovers/v1.php +++ b/lib/zin/wg/popovers/v1.php @@ -23,7 +23,7 @@ class popovers extends wg 'target' => array(), ); - protected function build() + protected function build(): array { $trigger = $this->block('trigger')[0]->children()[0]; $target = $this->block('target')[0]; diff --git a/lib/zin/wg/pripicker/v1.php b/lib/zin/wg/pripicker/v1.php index 63e6b7cd1d..28164e3fb6 100644 --- a/lib/zin/wg/pripicker/v1.php +++ b/lib/zin/wg/pripicker/v1.php @@ -49,7 +49,7 @@ class priPicker extends wg * * @access protected */ - protected function build(): wg + protected function build(): zui { $items = $this->prop('items'); if($items === null) diff --git a/lib/zin/wg/productmenu/v1.php b/lib/zin/wg/productmenu/v1.php index f42bc78d44..162f03561a 100644 --- a/lib/zin/wg/productmenu/v1.php +++ b/lib/zin/wg/productmenu/v1.php @@ -16,7 +16,7 @@ class productMenu extends wg return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - private function buildMenu() + private function buildMenu(): array { $link = $this->prop('link'); $items = $this->prop('items'); @@ -36,7 +36,7 @@ class productMenu extends wg return $menus; } - protected function build() + protected function build(): wg { $title = $this->prop('title'); $items = $this->buildMenu(); diff --git a/lib/zin/wg/programmenu/v1.php b/lib/zin/wg/programmenu/v1.php index 950115ae4a..cf132ccef8 100644 --- a/lib/zin/wg/programmenu/v1.php +++ b/lib/zin/wg/programmenu/v1.php @@ -65,7 +65,7 @@ class programMenu extends wg return array_filter($this->programs, function($program) use($id) {return $program->parent == $id;}); } - protected function build() + protected function build(): zui { $this->programs = (array)$this->prop('programs'); $activeKey = $this->prop('activeKey'); diff --git a/lib/zin/wg/row/v1.php b/lib/zin/wg/row/v1.php index ed01b35588..d130613194 100644 --- a/lib/zin/wg/row/v1.php +++ b/lib/zin/wg/row/v1.php @@ -1,4 +1,5 @@ prop(array('justify', 'align')); diff --git a/lib/zin/wg/searchform/v1.php b/lib/zin/wg/searchform/v1.php index 403fb6e56f..9d00cff4ab 100644 --- a/lib/zin/wg/searchform/v1.php +++ b/lib/zin/wg/searchform/v1.php @@ -4,7 +4,7 @@ namespace zin; class searchForm extends wg { - protected function build() + protected function build(): zui { return zui::searchForm(inherit($this)); } diff --git a/lib/zin/wg/searchtoggle/v1.php b/lib/zin/wg/searchtoggle/v1.php index 1b2ade99ec..51920342dc 100644 --- a/lib/zin/wg/searchtoggle/v1.php +++ b/lib/zin/wg/searchtoggle/v1.php @@ -20,7 +20,7 @@ class searchToggle extends wg return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build() + protected function build(): wg { global $lang; $module = $this->prop('module'); diff --git a/lib/zin/wg/sectioncard/v1.php b/lib/zin/wg/sectioncard/v1.php index ac37f98acc..765c99841a 100644 --- a/lib/zin/wg/sectioncard/v1.php +++ b/lib/zin/wg/sectioncard/v1.php @@ -17,7 +17,7 @@ class sectionCard extends wg ); } - public function onBuildItem(item $item) + public function onBuildItem(item $item): wg { return div ( @@ -27,7 +27,7 @@ class sectionCard extends wg ); } - protected function build() + protected function build(): wg { $title = $this->block('title'); diff --git a/lib/zin/wg/select/v1.php b/lib/zin/wg/select/v1.php index 13f111acd4..3ce55fe03f 100644 --- a/lib/zin/wg/select/v1.php +++ b/lib/zin/wg/select/v1.php @@ -62,7 +62,7 @@ class select extends wg * @access public * @return wg */ - public function onBuildItem($item): wg|array + public function onBuildItem(wg|array $item): wg { if($item instanceof item) $item = $item->props->toJsonData(); @@ -99,7 +99,7 @@ class select extends wg * @access protected * @return wg */ - protected function build() + protected function build(): wg { list($items, $multiple, $required) = $this->prop(array('items', 'multiple', 'required')); diff --git a/lib/zin/wg/severitylabel/v1.php b/lib/zin/wg/severitylabel/v1.php index d17a18489c..efe2c4aaf2 100644 --- a/lib/zin/wg/severitylabel/v1.php +++ b/lib/zin/wg/severitylabel/v1.php @@ -19,7 +19,7 @@ class severityLabel extends wg } } - protected function build() + protected function build(): wg { $text = $this->prop('text'); $level = $this->prop('level'); diff --git a/lib/zin/wg/severitypicker/v1.php b/lib/zin/wg/severitypicker/v1.php index 9b272439fd..189357ba65 100644 --- a/lib/zin/wg/severitypicker/v1.php +++ b/lib/zin/wg/severitypicker/v1.php @@ -49,7 +49,7 @@ class severityPicker extends wg * * @access protected */ - protected function build(): wg + protected function build(): zui { $items = $this->prop('items'); if($items === null) diff --git a/lib/zin/wg/sidebar/v1.php b/lib/zin/wg/sidebar/v1.php index 5fbff6359a..ca0419e011 100644 --- a/lib/zin/wg/sidebar/v1.php +++ b/lib/zin/wg/sidebar/v1.php @@ -19,7 +19,7 @@ class sidebar extends wg return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build() + protected function build(): wg { list($side, $showToggle) = $this->prop(array('side', 'showToggle')); return div diff --git a/lib/zin/wg/tabledata/v1.php b/lib/zin/wg/tabledata/v1.php index 2a301a353c..c33ca58330 100644 --- a/lib/zin/wg/tabledata/v1.php +++ b/lib/zin/wg/tabledata/v1.php @@ -19,7 +19,7 @@ class tableData extends wg return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - private function buildItemWithTr($item) + private function buildItemWithTr($item): wg { return h::tr ( @@ -37,7 +37,7 @@ class tableData extends wg ); } - private function buildItemWithDiv($item) + private function buildItemWithDiv($item): wg { if($item->prop('collapse')) { @@ -79,7 +79,7 @@ class tableData extends wg ); } - public function onBuildItem($item) + public function onBuildItem($item): wg { $item->setProp(array('thClass' => $this->prop('thClass'), 'tdClass' => $this->prop('tdClass'))); @@ -89,7 +89,7 @@ class tableData extends wg return $this->buildItemWithDiv($item); } - private function caption() + private function caption(): ?wg { $title = $this->prop('title'); if(empty($title)) return null; diff --git a/lib/zin/wg/tabpane/v1.php b/lib/zin/wg/tabpane/v1.php index ab19f5b31a..3982409cf9 100644 --- a/lib/zin/wg/tabpane/v1.php +++ b/lib/zin/wg/tabpane/v1.php @@ -16,7 +16,7 @@ class tabPane extends wg 'divider' => false, ); - protected function build() + protected function build(): wg { $key = $this->prop('key'); $active = $this->prop('active'); diff --git a/lib/zin/wg/tabs/v1.php b/lib/zin/wg/tabs/v1.php index ffe6f99efe..803a16d436 100644 --- a/lib/zin/wg/tabs/v1.php +++ b/lib/zin/wg/tabs/v1.php @@ -92,7 +92,7 @@ class tabs extends wg } } - private function buildCollapseBtn() + private function buildCollapseBtn(): ?wg { $collapse = $this->prop('collapse'); if(!$collapse) return null; diff --git a/lib/zin/wg/textarea/v1.php b/lib/zin/wg/textarea/v1.php index f435826d88..158c7d9073 100644 --- a/lib/zin/wg/textarea/v1.php +++ b/lib/zin/wg/textarea/v1.php @@ -19,7 +19,7 @@ class textarea extends wg 'rows' => 10 ); - protected function build() + protected function build(): wg { return h::textarea(set($this->props), $this->children()); } diff --git a/lib/zin/wg/timepicker/v1.php b/lib/zin/wg/timepicker/v1.php index 227b1f3cd6..96cc2e5b42 100644 --- a/lib/zin/wg/timepicker/v1.php +++ b/lib/zin/wg/timepicker/v1.php @@ -52,7 +52,7 @@ class timePicker extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build(): zui { list($name, $id, $defaultValue) = $this->prop(array('name', 'id', 'defaultValue')); return zui::timePicker diff --git a/lib/zin/wg/toolbar/v1.php b/lib/zin/wg/toolbar/v1.php index 5f0c2746b3..cc94323e73 100644 --- a/lib/zin/wg/toolbar/v1.php +++ b/lib/zin/wg/toolbar/v1.php @@ -13,7 +13,7 @@ class toolbar extends wg 'btnProps?: array' ); - public function onBuildItem($item) + public function onBuildItem($item): wg { if($item === null) return null; @@ -37,7 +37,7 @@ class toolbar extends wg ); } - protected function build() + protected function build(): wg { $items = $this->prop('items'); return div diff --git a/lib/zin/wg/tooltip/v1.php b/lib/zin/wg/tooltip/v1.php index 03b038f9f0..8dd75f4a43 100644 --- a/lib/zin/wg/tooltip/v1.php +++ b/lib/zin/wg/tooltip/v1.php @@ -4,7 +4,7 @@ namespace zin; class tooltip extends wg { - protected function build() + protected function build(): zui { $tooltip = zui::tooltip(inherit($this)); diff --git a/lib/zin/wg/tree/v1.php b/lib/zin/wg/tree/v1.php index b5f789c309..22e37331f3 100644 --- a/lib/zin/wg/tree/v1.php +++ b/lib/zin/wg/tree/v1.php @@ -10,7 +10,7 @@ class tree extends wg 'class?: string', ); - protected function build() + protected function build(): zui { $this->setProp('items', $this->buildTree($this->prop('items'))); return zui::tree(set($this->props->pick(array('items', 'activeClass', 'activeIcon', 'activeKey', 'onClickItem', 'defaultNestedShow', 'changeActiveKey', 'isDropdownMenu', 'collapsedIcon', 'expandedIcon', 'normalIcon', 'id')))); diff --git a/lib/zin/wg/upload/v1.php b/lib/zin/wg/upload/v1.php index 62f8305c85..979f4ed4a6 100644 --- a/lib/zin/wg/upload/v1.php +++ b/lib/zin/wg/upload/v1.php @@ -40,7 +40,7 @@ class upload extends wg 'exceededCountHint?: string', // 上传超出个数限制提示 ); - protected function build() + protected function build(): zui { global $lang; diff --git a/lib/zin/wg/uploadimgs/v1.php b/lib/zin/wg/uploadimgs/v1.php index 3ebed3acb5..b766a398a3 100644 --- a/lib/zin/wg/uploadimgs/v1.php +++ b/lib/zin/wg/uploadimgs/v1.php @@ -35,7 +35,7 @@ class uploadImgs extends wg 'totalCountText?: string', // 文件数量文本 ); - protected function build() + protected function build(): zui { return zui::uploadImgs(inherit($this)); } diff --git a/lib/zin/wg/useravatar/v1.php b/lib/zin/wg/useravatar/v1.php index c1e5e0fa45..91dd5ecbf4 100644 --- a/lib/zin/wg/useravatar/v1.php +++ b/lib/zin/wg/useravatar/v1.php @@ -37,7 +37,7 @@ class userAvatar extends wg return parent::onAddChild($child); } - protected function build() + protected function build(): wg { list($user, $avatar, $account, $realname) = $this->prop(array('user', 'avatar', 'account', 'realname')); if(is_array($user)) diff --git a/lib/zin/zui/zui.class.php b/lib/zin/zui/zui.class.php index 20fbbfbd89..2dda0d28fa 100644 --- a/lib/zin/zui/zui.class.php +++ b/lib/zin/zui/zui.class.php @@ -31,7 +31,7 @@ class zui extends wg '_class?: string' ); - protected function build() + protected function build(): array { list($name, $target, $tagName, $targetProps, $size, $id, $class, $map) = $this->prop(array('_name', '_to', '_tag', '_props', '_size', '_id', '_class', '_map')); list($width, $height) = $size;