diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index b89321ebe44..49e60e6d369 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -1419,6 +1419,10 @@ public static function toArray($seq, $preserveKeys = true) */ public static function testEmpty($value): bool { + if ($value instanceof EmptyInterface) { + return $value->getIsEmpty(); + } + if ($value instanceof \Countable) { return 0 === \count($value); } diff --git a/src/Extension/EmptyInterface.php b/src/Extension/EmptyInterface.php new file mode 100644 index 00000000000..71dbba64486 --- /dev/null +++ b/src/Extension/EmptyInterface.php @@ -0,0 +1,26 @@ + + * @since 3.24.1 + */ +interface EmptyInterface +{ + /** + * @return bool + */ + public function getIsEmpty(): bool; +}