Skip to content

Commit c56ce36

Browse files
koriymclaude
andcommitted
Add early return in weaveAspects when no pointcuts defined
Skip unnecessary iteration when no AOP pointcuts are configured. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c45cac9 commit c56ce36

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/di/Container.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ public function merge(self $container): void
193193
*/
194194
public function weaveAspects(CompilerInterface $compiler): void
195195
{
196+
if (empty($this->pointcuts)) {
197+
return;
198+
}
199+
196200
foreach ($this->container as $dependency) {
197201
if ($dependency instanceof Dependency) {
198202
$dependency->weaveAspects($compiler, $this->pointcuts);

tests/di/ContainerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,16 @@ public function testUnbound(): void
173173
$this->expectException(Unbound::class);
174174
(new Container())->getInstanceWithArgs(FakeEngineInterface::class, []);
175175
}
176+
177+
public function testWeaveAspectsWithEmptyPointcuts(): void
178+
{
179+
$container = new Container();
180+
(new Bind($container, FakeEngine::class));
181+
182+
// Should work fine even when no pointcuts are defined
183+
$container->weaveAspects(new \Ray\Aop\Compiler(sys_get_temp_dir()));
184+
185+
$instance = $container->getInstance(FakeEngine::class);
186+
$this->assertInstanceOf(FakeEngine::class, $instance);
187+
}
176188
}

0 commit comments

Comments
 (0)