PHP code example of nikic / include-interceptor

1. Go to this page and download the library: Download nikic/include-interceptor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nikic / include-interceptor example snippets


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


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();