Skip to content

Commit 83d916c

Browse files
authored
feat: add object support for MemoryFactory::addTool (#264)
1 parent e347295 commit 83d916c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Chain/Toolbox/MetadataFactory/MemoryFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ final class MemoryFactory extends AbstractFactory
1414
*/
1515
private array $tools = [];
1616

17-
public function addTool(string $className, string $name, string $description, string $method = '__invoke'): self
17+
public function addTool(string|object $class, string $name, string $description, string $method = '__invoke'): self
1818
{
19+
$className = is_object($class) ? $class::class : $class;
1920
$this->tools[$className][] = new AsTool($name, $description, $method);
2021

2122
return $this;

tests/Chain/Toolbox/MetadataFactory/MemoryFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getMetadataWithDistinctToolPerClass(): void
4242
{
4343
$factory = (new MemoryFactory())
4444
->addTool(ToolNoAttribute1::class, 'happy_birthday', 'Generates birthday message')
45-
->addTool(ToolNoAttribute2::class, 'checkout', 'Buys a number of items per product', 'buy');
45+
->addTool(new ToolNoAttribute2(), 'checkout', 'Buys a number of items per product', 'buy');
4646

4747
$metadata = iterator_to_array($factory->getMetadata(ToolNoAttribute1::class));
4848

0 commit comments

Comments
 (0)