Skip to content

Commit

Permalink
добавил в модуль определение соответствия дженерику - соответствующег…
Browse files Browse the repository at this point in the history
…о используемого класса
  • Loading branch information
arutyunyan committed Apr 3, 2024
1 parent a00d13b commit bb9d0f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/modules/generics/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ public function addName($name)
{
$this->object->scope['modules'][self::class]['generics'][] = $name;
}

public function addEntities($entities)
{
$this->object->scope['modules'][self::class]['entities'] = $entities;

foreach ($entities as $i => $entity) {
$name = $this->object->scope['modules'][self::class]['generics'][$i];
$this->object->scope['modules'][self::class]['match'][$name] = $entity;
}
}
}
2 changes: 2 additions & 0 deletions src/modules/generics/aliases/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public function wrapper(mixed $callback_or_object_or_property_or_value)
{
$generic = Generic::install($this->getObject());
$generic->addName(static::class);

return fn(...$args) => $generic->addEntities($args);
}
}
8 changes: 7 additions & 1 deletion tests/GenericsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public function testGenericModule(): void
$box = new MyBox();
$box(Pen::class, Pencil::class);

$this->assertSame($box->scope['modules'][Generic::class]['generics'], [T::class, A::class]);
$this->assertSame(
$box->scope['modules'][Generic::class]['match'],
[
T::class => Pen::class,
A::class => Pencil::class
]
);
}
}

0 comments on commit bb9d0f4

Please sign in to comment.