|
@@ -68,6 +68,23 @@ abstract class Widget implements Renderable
|
|
|
return new static(...$params);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 符合条件则执行.
|
|
|
+ *
|
|
|
+ * @param mixed $value
|
|
|
+ * @param callable $callback
|
|
|
+ *
|
|
|
+ * @return $this|mixed
|
|
|
+ */
|
|
|
+ public function when($value, $callback)
|
|
|
+ {
|
|
|
+ if ($value) {
|
|
|
+ return $callback($this, $value) ?: $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 批量设置选项.
|
|
|
*
|