include-interceptor icon indicating copy to clipboard operation
include-interceptor copied to clipboard

Is this supposed to work only on CLI?

Open ceap80 opened this issue 1 year ago • 0 comments

I'm trying to use this in a Wordpress site in a local environment to no avail.

I tested this on a cli script and it worked perfectly.

But while testing this on a Wordpress site with Apache and mod_php 8.1 a see that Stream::stream_open doesn't get called for php files being included. It's only getting called from calls like file_get_contents

Not sure if there is anything I can do so this works under a Apache + mod_php

public function stream_open($path, $mode, $options) {
    $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
    return $this->runUnwrapped(function (Interceptor $interceptor) use ($path, $mode, $options, $backtrace) {
        $path = $this->fixPath($path, $backtrace);

        $including = (bool)($options & self::STREAM_OPEN_FOR_INCLUDE);

        /***************************************************************
         *                    START LOGGING                            *
         ***************************************************************/
        echo "<pre>";
        print_r(compact('path', 'options', 'including'));
        echo "</pre>";
        /***************************************************************
         *                    END LOGGING                              *
         ***************************************************************/

        if ($including) {
            $realPath = $this->realpath($path);
            if ($realPath !== null) {
                $this->resource = $interceptor->intercept($realPath);
                if ($this->resource !== null) {
                    return true;
                }
            }
        }

        if (isset($this->context)) {
            $this->resource = fopen($path, $mode, $options, $this->context);
        } else {
            $this->resource = fopen($path, $mode, $options);
        }
        return $this->resource !== false;
    });
}
Array
(
    [path] => /wp-includes/block-i18n.json
    [options] => 0
    [including] => 
)
Array
(
    [path] => /wp-includes/theme.json
    [options] => 0
    [including] => 
)

ceap80 avatar Jul 16 '24 19:07 ceap80