11package com.github.xepozz.php_dump.services
22
3- import com.github.xepozz.php_dump.StringBufferProcessAdapter
3+ import com.github.xepozz.php_dump.SeparateStringBufferProcessAdapter
44import com.github.xepozz.php_dump.command.PathMapper
55import com.github.xepozz.php_dump.command.PhpCommandExecutor
66import com.github.xepozz.php_dump.configuration.PhpDumpSettingsService
77import com.intellij.execution.configurations.GeneralCommandLine
88import com.intellij.openapi.components.Service
99import com.intellij.openapi.project.Project
10- import com.jetbrains.php.config.PhpProjectConfigurationFacade
11- import com.jetbrains.php.config.interpreters.PhpInterpretersManagerImpl
1210import kotlinx.coroutines.Dispatchers
1311import kotlinx.coroutines.withContext
1412
1513@Service(Service .Level .PROJECT )
1614class OpcodesDumperService (var project : Project ) : DumperServiceInterface {
1715 val state = PhpDumpSettingsService .getInstance(project)
18- val interpreter = PhpProjectConfigurationFacade .getInstance(project).interpreter
19- ? : PhpInterpretersManagerImpl .getInstance(project).interpreters.firstOrNull()
2016
21- override suspend fun dump (file : String ): Any? {
22- val interpreterPath = interpreter?.pathToPhpExecutable ? : return null
17+ override suspend fun dump (file : String ): Any {
2318 val debugLevel = state.debugLevel.value
2419 val preloadFile = state.preloadFile
2520
2621 val localFile = PathMapper .map(project, file)
2722 val command = GeneralCommandLine (buildList {
28- add(interpreterPath)
2923 add(" -l" )
30- add (" -ddisplay_errors =0" )
31- add (" -derror_reporting =0" )
24+ addAll (" -d display_errors =0" .split( " " ) )
25+ addAll (" -d error_reporting =0" .split( " " ) )
3226
33- add (" -dopcache .enable_cli=1" )
34- add (" -dopcache .save_comments=1" )
35- add (" -dopcache .opt_debug_level=${debugLevel} " )
27+ addAll (" -d opcache .enable_cli=1" .split( " " ) )
28+ addAll (" -d opcache .save_comments=1" .split( " " ) )
29+ addAll (" -d opcache .opt_debug_level=${debugLevel} " .split( " " ) )
3630 if (preloadFile != null ) {
37- add (" -dopcache .preload=${preloadFile} " )
31+ addAll (" -d opcache .preload=${preloadFile} " .split( " " ) )
3832 }
39-
40- add(" 1>/dev/null" )
4133 add(localFile)
4234 }).commandLineString
4335
4436 // language=injectablephp
4537 val phpSnippet = $$"""
46- opcache_compile_file($argv [1]);
47- passthru('$$command ');
38+ opcache_compile_file($argv [1]); passthru(PHP_BINARY . ' $$command ');
4839 """ .trimIndent()
4940
41+ // println("command: $command")
42+ // println("phpSnippet: $phpSnippet")
5043 return withContext(Dispatchers .IO ) {
51- val output = StringBuilder ()
44+ val opcodes = StringBuilder ()
45+ val errors = StringBuilder ()
5246
5347 PhpCommandExecutor .execute(
5448 localFile,
5549 phpSnippet,
5650 project,
57- StringBufferProcessAdapter (output ),
58- listOf (" -dopcache .enable_cli=1" ),
51+ SeparateStringBufferProcessAdapter (stderr = opcodes, stdout = errors ),
52+ (" -d opcache .enable_cli=1" .split( " " ) ),
5953 )
6054
61-
62- output.toString()
55+ if (opcodes.isEmpty()) {
56+ errors.toString()
57+ } else {
58+ opcodes.toString()
59+ }
6360 }
6461 }
6562}
0 commit comments