Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Include Interceptor Laravel Package

nikic/include-interceptor

PHP extension and library to intercept and virtualize include/require. Lets you provide custom file contents, rewrite paths, or instrument included code without touching the filesystem—useful for loaders, build tools, testing, and sandboxing.

View on GitHub
Deep Wiki
Context7

Include Interceptor

Library to intercept PHP includes. A fork of icewind1991/interceptor.

composer require nikic/include-interceptor

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';
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport