wheakerd / php-mimic
A transparent AOP library for PHP.
dev-main
2026-04-09 10:43 UTC
Requires
- php: ~8.4.0
- nikic/php-parser: ~5.7.0
Requires (Dev)
- super-kernel/command: dev-main
- super-kernel/framework: dev-main
README
A transparent AOP library for PHP.
What is Mimic?
PHP-Mimic is a transparent AOP (Aspect-Oriented Programming) framework that intercepts class loading at the stream level. It reshapes code on-the-fly via AST (Abstract Syntax Tree) manipulation, enabling non-intrusive logic injection into any class—including final classes and methods—without modifying original source files or requiring manual proxies.
Core Philosophy
- Transparent: Works with native new, static, and instanceof calls.
- Intrusive but Safe: Capability to intercept final members and private scopes.
- Debug-First: Integrated source-mapping ensures stack traces and error reports point back to original file paths and line numbers.
- Zero Eval: No eval() is used. All code is processed via custom stream wrappers and the Zend OPcache.
Installation
composer require wheakerd/php-mimic
Quick Start
1. Initialize the Kernel
Register the aop:// protocol and hijack the autoloader.
$mimic = new MimicFactory(); $mimic->register( [ TestCaseService::class => $composerLoader->findFile(TestCaseService::class), ], )->intercept([TestCaseService::class, 'handle'], function (ProceedingJoinPoint $point) { var_dump('Print return value:' . $point->proceed()); return 999; }); // Direct your autoloader to use the aop:// prefix
License
BSD 3-Clause License (New or Revised)