Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/icewind1991/interceptor
Intercept php includes
https://github.com/icewind1991/interceptor
Last synced: 17 days ago
JSON representation
Intercept php includes
- Host: GitHub
- URL: https://github.com/icewind1991/interceptor
- Owner: icewind1991
- Created: 2015-09-26T15:06:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-12-23T11:01:48.000Z (almost 5 years ago)
- Last Synced: 2024-10-11T13:42:52.939Z (about 1 month ago)
- Language: PHP
- Size: 164 KB
- Stars: 16
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Interceptor
[![Build Status](https://travis-ci.org/icewind1991/interceptor.svg?branch=master)](https://travis-ci.org/icewind1991/interceptor)
[![Code Coverage](https://scrutinizer-ci.com/g/icewind1991/interceptor/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/icewind1991/interceptor/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/icewind1991/interceptor/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/icewind1991/interceptor/?branch=master)Intercept php includes
```
composer require icewind/interceptor
```## Usage
```php
use Icewind\Interceptor\Interceptor;$interceptor = new Interceptor();
$interceptor->addWhiteList(__DIR__ . '/src');
$interceptor->addHook(function($code) {
return str_replace('foo', 'bar', $code);
});$interceptor->setUp();
require 'src/foo.php'
```## API
- `addWhiteList(string $path)`: Add a folder to the white list
- `addBlackList(string $path)`: Add a folder to the black list
- Only white listed files will be intercepted
- A file is white listed if it has a parent folder that is white listed
without there being a more direct parent folder that is black listed
- `addHook(callable $hook)`: Register a hook to the intercepter
- the registered callback will be called for every include which is intercepted
- The code being included will be passed as the first argument
- The path being included will be passed as second argument
- If the hook returns a string the loaded code will be replaced by the return value
- `setUp()` start intercepting includes
- `tearDown()` stop intercepting includes