GitXplorerGitXplorer
n

include-interceptor

public
69 stars
3 forks
2 issues

Commits

List of commits on branch master.
Unverified
176d8598c3fa3596342881767b7390d41decbca0

Add PHP 8.4 to CI matrix

nnikic committed 6 months ago
Unverified
90830534c7e506caca15d9dd04b99c13836b00d2

Add PHP 8.2 and PHP 8.3 to CI

nnikic committed a year ago
Unverified
1e2f2adf8712df6a64a039c046825929c9abb1f3

Autoload tests in develeopment only

sszepeviktor committed 3 years ago
Unverified
faaae4bb7bd34d7030ec6c185c8971220f7002a6

Switch to setup-php@v2

nnikic committed 3 years ago
Unverified
3579520b92fab39ce5721fbd1c785da70980837f

Add PHP 8.0 and 8.1 to CI

nnikic committed 3 years ago
Unverified
061f7ddea7cb6ea743535d8cda16cfa145f3aee3

Install PHPStan

sszepeviktor committed 3 years ago

README

The README file for this repository.

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