infection / include-interceptor
Stream Wrapper: Include Interceptor. Allows to replace included (autoloaded) file with another one.
Fund package maintenance!
infection
Open Collective
Installs: 13 669 996
Dependents: 3
Suggesters: 0
Security: 0
Stars: 28
Watchers: 3
Forks: 5
Open Issues: 4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- infection/infection: ^0.15.0
- phan/phan: ^2.4 || ^3
- php-coveralls/php-coveralls: ^2.2
- phpstan/phpstan: ^0.12.8
- phpunit/phpunit: ^8.5
- vimeo/psalm: ^3.8
README
Infection - Include Interceptor Stream Wrapper
It's a Stream Wrapper that wraps a file://
protocol and allows overriding content of any (auto) loaded file, including files autoloaded by Composer package manager.
Installation
composer require infection/include-interceptor
How it works
If you want to replace the content of the file whenever it's loaded (by executing include '/path/to/file.php
, by calling file_get_contents('/path/to/file.php')
, etc.), you need to register IncludeInterceptor
before loading original file:
use Infection\StreamWrapper\IncludeInterceptor; IncludeInterceptor::intercept('/path/to/original_file.php', '/path/to/replacement_file.php'); IncludeInterceptor::enable();
After enabling IncludeInterceptor
, content of the replacement_file.php
will be loaded instead of content of the original_file.php
.
Use cases
- This Stream Wrapper is used to replace the original file with the Mutant in Infection Mutation Testing Framework
- The same approach is used in the
dg/bypass-finals
package that allows to mockfinal
classes, by overriding original content and removingfinal
keyword in runtime
Infection - Mutation Testing Framework
Please read documentation here: infection.github.io
Twitter: @infection_php