Skip to content

Commit

Permalink
forward calls
Browse files Browse the repository at this point in the history
  • Loading branch information
darrencoutts118 authored Dec 13, 2023
1 parent 37af500 commit 23f6ce8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/AttributeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\ForwardsCalls;
use Illuminate\View\ComponentAttributeBag;

class AttributeBuilder
{
use ForwardsCalls;

public function __construct(
protected ComponentAttributeBag &$attributeBag,
protected Collection $options
Expand Down Expand Up @@ -59,4 +62,9 @@ public function getAttributeBag()
{
return $this->attributeBag;
}

public function __call($method, $parameters)
{
return $this->forwardCallTo($this->attributeBag, $method, $parameters);
}
}
2 changes: 1 addition & 1 deletion tests/AttributeBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
it('can add classes in multiple ways', function (string $method, $data) {
$attributeBuilder = $this->attributeBuilder->addClass($data);

expect($attributeBuilder->getAttributeBag()->jsonSerialize())->toHaveKey('class', 'class-1 class-2 class-3 class-4 class-5');
expect($attributeBuilder->jsonSerialize())->toHaveKey('class', 'class-1 class-2 class-3 class-4 class-5');
})->with([
['as a single string', 'class-1 class-2 class-3 class-4 class-5'],
['as an array', ['class-1', 'class-2', 'class-3', 'class-4', 'class-5']],
Expand Down

0 comments on commit 23f6ce8

Please sign in to comment.