Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/infection/include-interceptor
Stream Wrapper: Include Interceptor. Allows to replace included (autoloaded) file with another one.
https://github.com/infection/include-interceptor
Last synced: 6 days ago
JSON representation
Stream Wrapper: Include Interceptor. Allows to replace included (autoloaded) file with another one.
- Host: GitHub
- URL: https://github.com/infection/include-interceptor
- Owner: infection
- License: bsd-3-clause
- Created: 2020-01-19T20:04:56.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-03T21:48:07.000Z (6 months ago)
- Last Synced: 2024-10-29T18:42:37.329Z (14 days ago)
- Language: PHP
- Size: 48.8 KB
- Stars: 28
- Watchers: 3
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/infection/include-interceptor.svg?branch=master)](https://travis-ci.org/infection/include-interceptor)
[![Coverage Status](https://coveralls.io/repos/github/infection/include-interceptor/badge.svg?branch=master)](https://coveralls.io/github/infection/include-interceptor?branch=master)# Infection - Include Interceptor Stream Wrapper
It's a [Stream Wrapper](https://www.php.net/manual/en/book.stream.php) that wraps a [`file://`](https://www.php.net/manual/en/wrappers.file.php) protocol and allows overriding content of any (auto) loaded file, including files autoloaded by Composer package manager.
## Installation
```bash
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:
```php
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](http://infection.github.io) Mutation Testing Framework
* The same approach is used in the [`dg/bypass-finals`](https://github.com/dg/bypass-finals/) package that allows to mock `final` classes, by overriding original content and removing `final` keyword in runtime## Infection - Mutation Testing Framework
Please read documentation here: [infection.github.io](http://infection.github.io)
Twitter: [@infection_php](http://twitter.com/infection_php)