mirror of
https://github.com/archtechx/gloss.git
synced 2025-12-12 11:14:04 +00:00
more special handling for closures
This commit is contained in:
parent
fb61ed809b
commit
91d07ec44b
1 changed files with 11 additions and 2 deletions
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Lean\Gloss;
|
namespace Lean\Gloss;
|
||||||
|
|
||||||
use Countable;
|
use Countable;
|
||||||
|
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Translation\Translator;
|
use Illuminate\Translation\Translator;
|
||||||
|
|
||||||
|
|
@ -229,7 +230,11 @@ class GlossTranslator extends Translator
|
||||||
return $this->makeReplacements($line, $replace);
|
return $this->makeReplacements($line, $replace);
|
||||||
} elseif (is_array($line) && count($line) > 0) {
|
} elseif (is_array($line) && count($line) > 0) {
|
||||||
foreach ($line as $key => $value) {
|
foreach ($line as $key => $value) {
|
||||||
$line[$key] = $this->makeReplacements($value, $replace);
|
if (! is_callable($value)) {
|
||||||
|
$value = $this->makeReplacements($value, $replace);
|
||||||
|
}
|
||||||
|
|
||||||
|
$line[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $line;
|
return $line;
|
||||||
|
|
@ -241,7 +246,11 @@ class GlossTranslator extends Translator
|
||||||
protected function makeReplacements($line, array $replace)
|
protected function makeReplacements($line, array $replace)
|
||||||
{
|
{
|
||||||
if (is_callable($line) && ! is_string($line)) {
|
if (is_callable($line) && ! is_string($line)) {
|
||||||
$line = app()->call($line, $replace);
|
try {
|
||||||
|
$line = app()->call($line, $replace);
|
||||||
|
} catch (BindingResolutionException $exception) {
|
||||||
|
// We keep it a Closure if we can't safely call it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::makeReplacements($line, $replace);
|
return parent::makeReplacements($line, $replace);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue