*zin: optimize prop getter method

This commit is contained in:
Hao Sun
2023-02-16 16:46:37 +08:00
parent 06c7814443
commit 309c79ca77
4 changed files with 8 additions and 17 deletions
-1
View File
@@ -11,7 +11,6 @@
namespace zin;
require_once dirname(__DIR__) . DS . 'utils' . DS . 'flat.func.php';
require_once 'wg.class.php';
require_once 'wg.func.php';
+4 -12
View File
@@ -202,27 +202,19 @@ class wg
}
}
public function prop($name)
public function prop($name, $defaultValue = NULL)
{
$args = func_get_args();
if(count($args) > 1)
{
$name = $args;
}
if(is_string($name)) return $this->props->get($name);
if(is_array($name))
{
$values = array();
foreach($name as $propName)
foreach($name as $index => $propName)
{
$values[] = $this->props->get($propName);
$values[] = $this->props->get($propName, is_array($defaultValue) ? (isset($defaultValue[$propName]) ? $defaultValue[$propName] : $defaultValue[$index]) : $defaultValue);
}
return $values;
}
return NULL;
return $this->props->get($name, $defaultValue);
}
/**
+3 -3
View File
@@ -14,7 +14,7 @@ class actionItem extends wg
protected function buildHeadingItem()
{
list($icon, $text, $trailingIcon) = $this->prop('icon', 'text', 'trailingIcon');
list($icon, $text, $trailingIcon) = $this->prop(array('icon', 'text', 'trailingIcon'));
return h::span
(
@@ -37,7 +37,7 @@ class actionItem extends wg
$methodName = "build{$type}Item";
if(method_exists($this, $methodName)) return $this->$methodName();
list($tagName, $icon, $text, $trailingIcon) = $this->prop('tagName', 'icon', 'text', 'trailingIcon');
list($tagName, $icon, $text, $trailingIcon) = $this->prop(array('tagName', 'icon', 'text', 'trailingIcon'));
return h::create
(
@@ -52,7 +52,7 @@ class actionItem extends wg
protected function build()
{
list($name, $type, $outerTag, $tagName, $url, $target, $active, $disabled, $outerProps) = $this->prop('name', 'type', 'outerTag', 'tagName', 'url', 'target', 'active', 'disabled', 'outerProps');
list($name, $type, $outerTag, $tagName, $url, $target, $active, $disabled, $outerProps) = $this->prop(array('name', 'type', 'outerTag', 'tagName', 'url', 'target', 'active', 'disabled', 'outerProps'));
return h::create
(
+1 -1
View File
@@ -27,7 +27,7 @@ class nav extends wg
(
setClass('nav'),
set($this->props->skip(array_keys(static::getDefinedProps()))),
is_array($items) ? array_map(array($this, 'onBuildItem'), $this->prop('items')) : NULL,
is_array($items) ? array_map(array($this, 'onBuildItem'), $items) : NULL,
$this->children(),
);
}