Library to intercept PHP includes

Overview

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';
You might also like...
A small PHP library for validating VAT identification numbers (VATINs).

VATIN A small PHP library for validating VAT identification numbers (VATINs). Installation This library is available on Packagist: $ composer require

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

Laravel Package for TMDB API Wrapper A Laravel package that provides easy access to the php-tmdb/api TMDB (The Movie Database) API wrapper. This packa

Laravel breeze is a PHP Laravel library that provides Authentication features such as Login page , Register, Reset Password and creating all Sessions Required.

About Laravel breeze To give you a head start building your new Laravel application, we are happy to offer authentication and application starter kits

PHP library for sending messages using a ntfy server.

ntfy-php-library PHP library for sending messages using a ntfy server. Supports ntfy server version 1.27.2. Install composer require verifiedjoseph/nt

Library extra fields for Laravel Orchid Platform
Library extra fields for Laravel Orchid Platform

Orchid Fields Extra library which add different fields in Laravel Orchid Platform Installation You may install into your project using the Composer pa

Base library for repeated layout fields, content builders and other collection components

laravel-flexible-content This package's only purpose is to build custom repeated layout components, such as Laravel Nova's Flexible Content field or y

Laravel Echo library for beautiful Pusher and Ably integration.

Introduction In many modern web applications, WebSockets are used to implement realtime, live-updating user interfaces. When some data is updated on t

 BigBlueButton Server API Library for Laravel
BigBlueButton Server API Library for Laravel

BigBlueButton Server API Library for Laravel Package that provides easily communicate between BigBlueButton server and laravel framework Requirements

SSLCommerz Payment gateway library for Laravel framework

SSLCommerz SSLCommerz Payment gateway library for Laravel framework. Official documentation is here. install composer require sam-asif/sslcommerz Pro

Comments
  • proc_open() with

    proc_open() with "file" descriptor does not work with active interceptor

    I added a file to a composer package into the "autoload/files" config from composer.json. As soon as I setup the interceptor and run "composer update", I'm getting a "fseek(): Stream does not support seeking" exception.

    I'm running a laravel application on PHP 8.1

    This is my code:

    $interceptor = new \Nikic\IncludeInterceptor\Interceptor(function (string $path) {
        if (str_contains($path, '/public/index.php')) {
            echo($path);
            exit();
        }
    
        return null;
    });
    $interceptor->setUp();
    
    opened by WalterWoshid 3
Releases(v0.1.2)
  • v0.1.2(Nov 27, 2021)

  • v0.1.1(Dec 30, 2019)

  • v0.1.0(Dec 29, 2019)

    Initial release. Relative to https://github.com/icewind1991/interceptor 0.3.0, the following changes have been made:

    • Remove support for PHP < 7.1. Add type annotations.
    • Fix notice that is thrown every time a non-absolute path is used outside include. (Main motivation for this fork...)
    • Don't call interception hook if the included file does not exist.
    • Perform pseudo-realpath resolution for phar:// paths to make filtering work.
    • Change the interceptor API to remove the FileFilter dependency. There now is only a single hook that both decides whether it wants to intercept and performs the interception. FileFilter is still provided as an optional convenience.
    • Add support for white/blacklisting single files in FileFilter.
    • Don't filter extensions by default in FileFilter.
    • Allow overriding overridden stream protocols in Interceptor constructor.
    Source code(tar.gz)
    Source code(zip)
Owner
Nikita Popov
Nikita Popov
Laravel Ajax Datatable is a nice laravel admin panel which includes authentication, CRUD and Ajax datatable.

Laravel Ajax Datatable is a nice laravel admin panel which includes authentication, CRUD and Ajax datatable. the datatable is created with laravel & ajax so No need to install another package, yout can do search, sort, paginate and show records per page fastly.

Jumah 3 Oct 3, 2022
Bootstrap Theme Generator inside of a Wordpress-Settings-Page. Includes live compilation of SCSS!

Bootstrap-Theme-Generator Bootstrap Theme Generator enables you to choose which components of Bootstrap you want to load. It also gives you the possib

null 3 Aug 15, 2022
Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.

Lavacharts 3.1.12 Lavacharts is a graphing / chart library for PHP5.4+ that wraps the Google Chart API. Stable: Dev: Developer Note Please don't be di

Kevin Hill 616 Dec 17, 2022
A laravel service provider for the netsuite-php library service

netsuite-laravel A PHP supplemental package to the ryanwinchester/netsuite-php package to add the NetSuite service client to the service container of

NetsuitePHP 6 Nov 9, 2022
PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.

reCAPTCHA PHP client library reCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse. This is a PHP library that wraps up the s

Google 3.3k Dec 23, 2022
Menu Library for PHP

KnpMenu The KnpMenu library provides object oriented menus for PHP. It is used by the KnpMenuBundle for Symfony but can now be used stand-alone. Insta

KNP Labs 1.3k Jan 1, 2023
PHP 5.3 Object Oriented image manipulation library

Imagine Tweet about it using the #php_imagine hashtag. Image manipulation library for PHP 5.3 inspired by Python's PIL and other image libraries. Requ

null 4.3k Dec 29, 2022
Flexihash is a small PHP library which implements consistent hashing.

Flexihash Flexihash is a small PHP library which implements consistent hashing, which is most useful in distributed caching. It requires PHP5 and uses

Paul Annesley 364 Oct 18, 2022
Geo-related tools PHP 7.3+ library built atop Geocoder and React libraries

Geotools Geotools is a PHP geo-related library, built atop Geocoder and React libraries. Features Batch geocode & reverse geocoding request(s) in seri

The League of Extraordinary Packages 1.3k Dec 27, 2022
A PHP library for simplifying the use of accessors.

Accessor A PHP library for simplifying the use of accessors. Usage use Doctrine\ORM\Mapping as ORM; use Phine\Accessor\AccessorTrait; use Phine\Access

KHerGe - Archived Projects 5 May 14, 2020