Reading PHP Remote Interpreter Path
Hello,
I'm working on a plugin that is auto configuring a docker compose based remote php interpreter. Registering the Interpreter works quite well now. But I would like to improve the performance and user experience by first checking wether the interpreter is already configured correctly. Therefore I need to read the php interpreter path of a given interpreter. Find some example code below.
PhpInterpretersManagerImpl interpretersManager = PhpInterpretersManagerImpl.getInstance(this.project); PhpInterpreter interpreter = interpretersManager.findInterpreter(NAME); PhpSdkAdditionalData additionalData = interpreter.getPhpSdkAdditionalData(); if (!(additionalData instanceof PhpRemoteSdkAdditionalData)) { System.out.println("Wrong instance!"); }
Even the PHP Remote Interpreter was saved as a remote interpreter, this code will always run the "wrong instance" part, as getPhpSdkAdditionalData of the loaded instance of the interpreter will always return an instance of PhpSdkAdditionalData.
Is this behavior intended? Do I miss something? How can I compare the configured php version of the interpreter?
Thanks in advance!
Edit:
Of course I already tried to access the path directly on the interpreter:
phpInterpreter.getPathToPhpExecutable()
But this just seems to be a wrapper for the additionalData and always returns an empty string.
Please sign in to leave a comment.
Hello! To fetch all configured interpreters you can try to use this code:
If configured remote interpreter exists, one of the return interpreters should match provided predicate.
Hello Kirill Smelov, thank you for your answer!
Sadly this does not solve my problem.
I do get the instacne of the PHP Interpreter, but I can not accesss the path of its configured binary.
The following code snipped
will generate the following output:
but I would expect
as this is the configured binary as you can see in the GUI:
As I already stated above I think the wrong instance of PhpSdkAdditionalData might be the reason, as I would expect an instance of PhpRemoteSdkAdditionalData and the interpreter path seems to be saved in RemoteSdkPropertiesHolder.
I hope I explained my issue more precise now.
Thanks in advance for any help on this!
Okay, I just noticed, this behavior just seems to occur on automatically configured interpreters, not on those created via the GUI.
I guess I miss something when creating the interpreter?
Sorry, I should have noted before, that I did create that interpreter not via the GUI.
This should normally work. Can you please provide complete example with setup code and the code that doesn't work?
Hi Kirill Smelov,
I prepared the following startup activity to reproduce the problem.
1. Adapt the package name of the class and register the startup action in PHPStorm
2. Run the IDE with this code executed. You should see a new valid and working PHP Interpreter is added.
3. Restart your IDE
Result:
You will see the output "DDEV" without any interpreter path on your terminal (See System.out.println in lines 29, 31)
Also the php interpreter looks broken now if you open it in settings dialog.
Expected Result:
I would expect to see the interpreter name DDEV and its interpreter path php8.0 in the output.
The interpreter is found but all the settings are gone. When opening this issue I thought the problem would be accessing the data but now I think I did some mistake persisting them. Do you have any idea on how to fix this? Thanks!
Code
Kirill Smelov do you have any news on this? I still couldn't find my mistake.
Can you please try to explicitly set interpreter home path? It's used during deserialization of interpreters on IDE startup to decide on type of SDK
after setting sdk additional data?
This did the trick, it finally works!
Thank you so much, Kirill Smelov!