Php 在解析前调用zend_compile_file()时,如何更改源代码?

Php 在解析前调用zend_compile_file()时,如何更改源代码?,php,c,Php,C,我正在替换zend\u compile\u string()进行代码预处理,然后将其传递到原始zend\u compile\u string() 它起作用了 但是我还需要从文件中获得代码预处理(\u include/require,php)。 Zend提供了替换Zend\u compile\u file()的功能,但源文本仅在open\u file\u for\u scanning()中可用(Zend\u stream\u fixup(file\u handle,&buf,&size TSRML

我正在替换
zend\u compile\u string()
进行代码预处理,然后将其传递到原始
zend\u compile\u string()

它起作用了

但是我还需要从文件中获得代码预处理(
\u include/require
php
)。 Zend提供了替换
Zend\u compile\u file()
的功能,但源文本仅在
open\u file\u for\u scanning()
中可用(
Zend\u stream\u fixup(file\u handle,&buf,&size TSRMLS\u CC)
),无法从扩展名访问

在发送到
zendparse()
之前,如何更改代码


编辑:我找到了一个解决方案:

zend_op_array* ext_zend_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC)
{
    char *buf;
    size_t size;
    if (zend_stream_fixup(file_handle, &buf, &size TSRMLS_CC) == FAILURE) {
        return NULL;
    }

    char *res;
    size_t res_size;
    // My code that uses file_handle->handle.stream.mmap.buf/len is read-only and filling res/res_size

    file_handle->handle.stream.mmap.buf = res;
    file_handle->handle.stream.mmap.len = res_size;

    return ext_orig_zend_compile_file(file_handle, type TSRMLS_CC);
}