定制 addvilz/autoload_patcher 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

addvilz/autoload_patcher

Composer 安装命令:

composer require addvilz/autoload_patcher

包简介

Patch any class file before autoloading it

README 文档

README

Purpose of this library

Purpose of this library is to allow patching the source code of class files during runtime.

There are some cases when you need to modify functionality of vendor code but you are not able to replace the code, or extend it (static calls from other vendor code is a good example).

This library allows you to replace, augment or otherwise change original source code and eval it afterwards.

Installation

composer require addvilz/autoload_patcher

Example use:

$loader = require 'vendor/autoload.php';
$patcher = new \Addvilz\AutoloadPatcher\Patcher($loader);
$patcher
    ->register()
    ->addPatcher('Some\Vendor\UtilityClass', function ($code) {
    
        // Let's rename the class
        $code = str_replace(
            'class UtilityClass',
            'class VendorUtilityClass',
            $code
        );
        
        // ... More modification here, runtime code generation, etc.
        
        return $code;
    });

How does it work?

Patcher->register() method call appends an autoload callback to autoload stack. This means, all class loading will be proxied tru Patcher instance, and if patcher callback for given class is registered, it will be executed against source code from file determined by Composer ClassLoader class.

NB: Before the source code of the class is passed to the callback function, opening PHP tags are removed!

NB: Whatever the patcher callback function returns is passed on to eval().

License

Licensed under terms and conditions of Apache 2.0 license.

统计信息

  • 总下载量: 1.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2016-02-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固