26 lines
400 B
PHP
26 lines
400 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\FreeGift\Model;
|
|
|
|
class InternalAddGuard
|
|
{
|
|
private int $depth = 0;
|
|
|
|
public function isAllowed(): bool
|
|
{
|
|
return $this->depth > 0;
|
|
}
|
|
|
|
public function execute(callable $callback): mixed
|
|
{
|
|
$this->depth++;
|
|
|
|
try {
|
|
return $callback();
|
|
} finally {
|
|
$this->depth--;
|
|
}
|
|
}
|
|
}
|