@@ -17,7 +17,6 @@ class SourcePatcher
1717 public static function init (): void
1818 {
1919 // FileSystem::addSourceExtractHook('swow', [SourcePatcher::class, 'patchSwow']);
20- FileSystem::addSourceExtractHook ('micro ' , [SourcePatcher::class, 'patchMicro ' ]);
2120 FileSystem::addSourceExtractHook ('openssl ' , [SourcePatcher::class, 'patchOpenssl11Darwin ' ]);
2221 FileSystem::addSourceExtractHook ('swoole ' , [SourcePatcher::class, 'patchSwoole ' ]);
2322 FileSystem::addSourceExtractHook ('php-src ' , [SourcePatcher::class, 'patchPhpLibxml212 ' ]);
@@ -105,7 +104,7 @@ public static function patchBeforeConfigure(BuilderBase $builder): void
105104 * @throws RuntimeException
106105 * @throws FileSystemException
107106 */
108- public static function patchMicro (string $ name = '' , string $ target = '' , ?array $ items = null ): bool
107+ public static function patchMicro (?array $ items = null ): bool
109108 {
110109 if (!file_exists (SOURCE_PATH . '/php-src/sapi/micro/php_micro.c ' )) {
111110 return false ;
@@ -152,11 +151,7 @@ public static function patchMicro(string $name = '', string $target = '', ?array
152151
153152 foreach ($ patches as $ patch ) {
154153 logger ()->info ("Patching micro with {$ patch }" );
155- $ patchesStr = str_replace ('/ ' , DIRECTORY_SEPARATOR , $ patch );
156- f_passthru (
157- 'cd ' . SOURCE_PATH . '/php-src && ' .
158- (PHP_OS_FAMILY === 'Windows ' ? 'type ' : 'cat ' ) . ' ' . $ patchesStr . ' | patch -p1 '
159- );
154+ self ::patchFile (SOURCE_PATH . "/php-src {$ patch }" , SOURCE_PATH . '/php-src ' );
160155 }
161156
162157 return true ;
@@ -165,24 +160,29 @@ public static function patchMicro(string $name = '', string $target = '', ?array
165160 /**
166161 * Use existing patch file for patching
167162 *
168- * @param string $patch_name Patch file name in src/globals/patch/
163+ * @param string $patch_name Patch file name in src/globals/patch/ or absolute path
169164 * @param string $cwd Working directory for patch command
170165 * @param bool $reverse Reverse patches (default: False)
171166 * @throws RuntimeException
172167 */
173168 public static function patchFile (string $ patch_name , string $ cwd , bool $ reverse = false ): bool
174169 {
175- if (!file_exists (ROOT_DIR . "/src/globals/patch/ {$ patch_name }" )) {
170+ if (FileSystem::isRelativePath ($ patch_name )) {
171+ $ patch_file = ROOT_DIR . "/src/globals/patch/ {$ patch_name }" ;
172+ } else {
173+ $ patch_file = $ patch_name ;
174+ }
175+ if (!file_exists ($ patch_file )) {
176176 return false ;
177177 }
178178
179- $ patch_file = ROOT_DIR . "/src/globals/patch/ {$ patch_name }" ;
180- $ patch_str = str_replace ('/ ' , DIRECTORY_SEPARATOR , $ patch_file );
179+ $ patch_str = FileSystem::convertPath ($ patch_file );
181180
182181 // Copy patch from phar
183- if (\Phar::running () !== '' ) {
184- file_put_contents (SOURCE_PATH . '/ ' . $ patch_name , file_get_contents ($ patch_file ));
185- $ patch_str = str_replace ('/ ' , DIRECTORY_SEPARATOR , SOURCE_PATH . '/ ' . $ patch_name );
182+ if (str_starts_with ($ patch_str , 'phar:// ' )) {
183+ $ filename = pathinfo ($ patch_file , PATHINFO_BASENAME );
184+ file_put_contents (SOURCE_PATH . "{$ filename }" , file_get_contents ($ patch_file ));
185+ $ patch_str = FileSystem::convertPath (SOURCE_PATH . "/ {$ filename }" );
186186 }
187187
188188 // detect
0 commit comments