Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
26 changes: 26 additions & 0 deletions src/Extension/EmptyInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Twig\Extension;

/**
* Allows objects to declare whether they should be considered empty.
*
* @author Brandon Kelly <brandon@pixelandtonic.com>
* @since 3.24.1
*/
interface EmptyInterface
{
/**
* @return bool
*/
public function getIsEmpty(): bool;
}
Loading