Skip to content

Commit

Permalink
merge #14: allow overriding fluent functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Jul 8, 2023
2 parents d316bd9 + 6d216b7 commit 0dbb570
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Bundle/FluentBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ public function __construct(
private bool $allowOverrides = false,
) {
$this->functions = [
'NUMBER' => Closure::fromCallable([$this, 'numberFunction']),
'DATETIME' => Closure::fromCallable([$this, 'dateTimeFunction']),
'NUMBER' => $this->numberFunction(...),
'DATETIME' => $this->dateTimeFunction(...),
];
}

/**
* @return $this
*/
public function addResource(
FluentResource $resource,
?bool $allowOverrides = null,
): static {
public function addResource(FluentResource $resource, ?bool $allowOverrides = null): static
{
$allowOverrides ??= $this->allowOverrides;

foreach ($resource->body as $entry) {
Expand Down Expand Up @@ -87,9 +85,11 @@ public function addFtl(string $ftl, ?bool $allowOverrides = null): static
/**
* @return $this
*/
public function addFunction(string $name, Closure $function): static
public function addFunction(string $name, Closure $function, ?bool $allowOverrides = null): static
{
if ($this->hasFunction($name)) {
$allowOverrides ??= $this->allowOverrides;

if (! $allowOverrides && $this->hasFunction($name)) {
throw new FunctionExistsException($name);
}

Expand All @@ -103,10 +103,10 @@ public function addFunction(string $name, Closure $function): static
*
* @return $this
*/
public function addFunctions(array $functions): static
public function addFunctions(array $functions, ?bool $allowOverrides = null): static
{
foreach ($functions as $name => $function) {
$this->addFunction($name, $function);
$this->addFunction($name, $function, $allowOverrides);
}

return $this;
Expand Down

0 comments on commit 0dbb570

Please sign in to comment.