diff --git a/src/IncludeInterceptor.php b/src/IncludeInterceptor.php index cf3b6bd..081f705 100644 --- a/src/IncludeInterceptor.php +++ b/src/IncludeInterceptor.php @@ -377,12 +377,20 @@ public function unlink($path) return $return; } - public function url_stat($path) + public function url_stat($path, $flags) { self::disable(); try { - return is_readable($path) ? stat($path) : false; + if (is_readable($path) === false) { + return false; + } + + if ($flags & STREAM_URL_STAT_LINK) { + return lstat($path); + } + + return stat($path); } finally { self::enable(); } diff --git a/tests/IncludeInterceptorTest.php b/tests/IncludeInterceptorTest.php index 04a64cc..7b8900d 100644 --- a/tests/IncludeInterceptorTest.php +++ b/tests/IncludeInterceptorTest.php @@ -418,4 +418,19 @@ public function test_it_re_enables_interceptor_after_file_not_found_with_url_sta $this->fail('Badly set up test, exception was not thrown'); } + + public function test_it_respects_symlinks_in_url_stat(): void + { + $expected = include self::$files[2]; + + IncludeInterceptor::intercept(self::$files[1], self::$files[2]); + IncludeInterceptor::enable(); + + $symlink = sys_get_temp_dir() . '/symlink-intercept'; + self::$files[] = $symlink; + + symlink(self::$files[2], $symlink); + + $this->assertTrue(is_link($symlink)); + } }