PHP Open API
Dependency in plugin.xml
PHP PSI
com.jetbrains.php.lang.psi.elements.*;
Utility Classes
PhpFilePathUtils
com.jetbrains.php.lang.psi.elements.impl.PhpFilePathUtils contains helper methods for working with paths from PSI elements.
getFileName()returns a constant string representation of the path from the PSI element.For example, for the expression:
// in file: /bin/folder/file.php __DIR__ . "/file2.php";it returns
"/bin/folder/file2.php".Note that the element passed as an argument can contain any expression that can be statically evaluated to a constant.
getReferences()returns all path references from the PSI element.Using this method in conjunction with PsiReferenceContributor you can add autocompletion for string literals in the specific contexts. For example, if certain PHP functions accept paths, the plugin can autocomplete paths when the user writes their arguments.
Note that PhpStorm automatically adds references for concatenation expressions with
__DIR__ordirname(__FILE__)function call.