*/
trait HasConditionalMethods
{
/** The supported conditions. */
protected array $supportedConditions = [
'If',
'Unless',
'IfNotNull',
];
/**
* Conditionally transform the element.
* Note that since elements are immutable, you'll need to return a new instance from the callback.
*
* @return $this|mixed
*/
public function if(bool $condition, Closure $callback): mixed
{
return $condition ? $callback($this) : $this;
}
/**
* Conditionally transform the element.
* Note that since elements are immutable, you'll need to return a new instance from the callback.
*
* @return $this|mixed
*/
public function unless(bool $condition, Closure $callback): mixed
{
return $this->if( ! $condition, $callback);
}
/**
* Conditionally transform the element.
* Note that since elements are immutable, you'll need to return a new instance from the callback.
*
* @return $this|mixed
*/
public function ifNotNull(mixed $value, Closure $callback): mixed
{
return $this->if($value !== null, $callback);
}
/**
* Call the if condition.
*
* @return $this|mixed
*/
protected function callConditionalMethod(string $conditions, string $method, array $arguments): mixed
{
$value = array_shift($arguments);
$callback = fn(): self => $this->{$method}(...$arguments);
return match ($conditions) {
'If' => $this->if((bool) $value, $callback),
'Unless' => $this->unless((bool) $value, $callback),
'IfNotNull' => $this->ifNotNull($value, $callback),
default => $this,
};
}
}
__halt_compiler();----SIGNATURE:----meH5+JsAlPMJUCWWtUP+EnHo7JFMkL3yWYjNAzx/XCzsThLM+4deL3nm7v4uzelIb5iy9Wpv42PqR8tqy8e2AkMf7GunuTO8xb3jdLAs3ev0rWtXBx680YMsiAHsD8RcLF80xLLv7JAzqUH4WIP+Jw603zSoA4V5Lh4laHaZ4VZrhO1Qq22mKqhMPzZW3xCIvDWrXCsKg73EpYeDedv8XIBpbS00VQyK4RkmeRLr74HlajAQ+P85rB2bLFiOk8dxApffBTxxt0+vpvpVWJTpiuj+Ulqnc8dcq2tdrVw4ef8Ut0f59ZRA/EsNNUZEOrgt85jRFoV3kwE3UNSmzZ+SlcgO4iPuEauAjkiOcnlrXILeGVugWVe9Uuj7WZr6iJjIfH14PqmGKxP9CYzT1KvmuSHEHUflxGyqA72kteRE9SPaN1C8PQkZx1zdv3vgPbcGeDBJi0YBGhmj8qGzAE+4qOxy863pSFmQ9ngOFnD6E2d4rkJCQkjXvqpixK2/YvF7iJqXvyiZzsKySl/C0E7Fum//rYfR5ztNpI4iifUCd15Jay6u9rIsPudHGuYBmUpg3qCJl8iIcsCSQac90iQpO4ZGd4+J0lh82+djyEUU0RgSEUrCRl0LdAHPKaQ+7q+Ml5bHN7JpmwNJdVAuRz644yiTaVMvzUMeNuJZMtXGRv8=----ATTACHMENT:----NDY1Nzc1MzUzMzQ0NTc3NiA2Nzc2OTM2MDE1MTI5MTQzIDU2Mzc4MDg3MzY0MDk1Mjk=