PHPackages                             nikic/include-interceptor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nikic/include-interceptor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nikic/include-interceptor
=========================

Intercept PHP includes

v0.1.2(4y ago)6967.4k↑60.9%3[1 issues](https://github.com/nikic/include-interceptor/issues)2MITPHPPHP &gt;=7.1CI passing

Since Dec 29Pushed 9mo ago3 watchersCompare

[ Source](https://github.com/nikic/include-interceptor)[ Packagist](https://packagist.org/packages/nikic/include-interceptor)[ RSS](/packages/nikic-include-interceptor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (2)

Include Interceptor
===================

[](#include-interceptor)

Library to intercept PHP includes. A fork of [icewind1991/interceptor](https://github.com/icewind1991/interceptor).

```
composer require nikic/include-interceptor

```

Usage
-----

[](#usage)

```
use Nikic\IncludeInterceptor\Interceptor;

$interceptor = new Interceptor(function(string $path) {
    if (!wantToIntercept($path)) {
        return null;
    }
    return transformCode(file_get_contents($path));
});
$interceptor->setUp(); // Start intercepting includes

require 'src/foo.php';

$interceptor->tearDown(); // Stop intercepting includes
```

The interception hook follows the following contract:

- It is only called if the included file exists.
- The passed `$path` is the realpath.
- If the hook returns `null`, no interception is performed.
- If the hook returns a string, these are taken as the transformed content of the file.

For convenience, a `FileFilter` is provided that implements white- and black-listing of files and directories. Paths passed to `addBlackList()` and `addWhiteList()` should always be realpaths.

```
use Nikic\IncludeInterceptor\Interceptor;
use Nikic\IncludeInterceptor\FileFilter;

$fileFilter = FileFilter::createAllWhitelisted();    // Start with everything whitelisted
$fileFilter->addBlackList(__DIR__ . '/src/');        // Blacklist the src/ directory
$fileFilter->addWhiteList(__DIR__ . '/src/foo.php'); // But whitelist the src/foo.php file
$interceptor = new Interceptor(function(string $path) use ($fileFilter) {
    if (!$fileFilter->test($path)) {
        return null;
    }
    return transformCode(file_get_contents($path));
});
$interceptor->setUp();

require 'src/foo.php';
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance41

Moderate activity, may be stable

Popularity46

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 53.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~350 days

Total

3

Last Release

1633d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a66e9e6117ecedd55b7cbfe3cd6a74d6f785be1b9f9e512b5a225b95b19f4d4b?d=identicon)[nikic](/maintainers/nikic)

---

Top Contributors

[![nikic](https://avatars.githubusercontent.com/u/216080?v=4)](https://github.com/nikic "nikic (26 commits)")[![icewind1991](https://avatars.githubusercontent.com/u/1283854?v=4)](https://github.com/icewind1991 "icewind1991 (20 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nikic-include-interceptor/health.svg)

```
[![Health](https://phpackages.com/badges/nikic-include-interceptor/health.svg)](https://phpackages.com/packages/nikic-include-interceptor)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
