Skip to content

Commit 523f8e4

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 523f8e4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
use BadMethodCallException;
88
use PHPUnit\Framework\TestCase;
9+
use Ray\Aop\Compiler;
910
use Ray\Aop\Matcher;
1011
use Ray\Aop\Pointcut;
1112
use Ray\Di\Exception\Unbound;
1213
use Throwable;
1314

1415
use function get_class;
16+
use function sys_get_temp_dir;
1517

1618
class ContainerTest extends TestCase
1719
{
@@ -173,4 +175,16 @@ public function testUnbound(): void
173175
$this->expectException(Unbound::class);
174176
(new Container())->getInstanceWithArgs(FakeEngineInterface::class, []);
175177
}
178+
179+
public function testWeaveAspectsWithEmptyPointcuts(): void
180+
{
181+
$container = new Container();
182+
(new Bind($container, FakeEngine::class));
183+
184+
// Should work fine even when no pointcuts are defined
185+
$container->weaveAspects(new Compiler(sys_get_temp_dir()));
186+
187+
$instance = $container->getInstance(FakeEngine::class);
188+
$this->assertInstanceOf(FakeEngine::class, $instance);
189+
}
176190
}

0 commit comments

Comments
 (0)