---
title: PHP Open API
---
## Using php-openapi
```xml
com.jetbrains.php
```
## PHP PSI
`com.jetbrains.php.lang.psi.elements.*;`
## Utility Classes
## PHP Extension Points
### PhpTypeProvider
Here is a code fragment that makes [generic Factory Method support](https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata#PhpStormAdvancedMetadata-Factorymethods) work
```xml
```
Interface:
```java
/**
* Extension point to implement to provide Type information on various PhpPsiElements
*/
public interface PhpTypeProvider2 {
ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.php.typeProvider2");
/**
* @return Your custom signature key, i.e. "?". Do not use any of PhpTypeSignatureKey.XXX constants though!
*/
char getKey();
/**
* @param element to deduce type for - using only LOCAL info. THIS IS MOST CRUCIAL ASPECT TO FOLLOW
* @return type for element, null if no insight. You can return a custom signature here to be later decoded by method below.
*/
@Nullable
String getType(PsiElement element);
/**
* @param expression Signature expression to decode. You can use PhpIndex.getBySignature() to look up expression internals.
* @param project well so you can reach the PhpIndex
* @return null if no match
*/
Collection extends PhpNamedElement> getBySignature(String expression, Project project);
}
```
Our implementation: includes a Completion contributor for the parameter values too.
```java
/**
*/
public class PhpStaticFactoryTypeProvider extends CompletionContributor implements PhpTypeProvider2 {
private static final Key>>> STATIC_FACTORY_TYPE_MAP =
new Key>>>("STATIC_FACTORY_TYPE_MAP");
@Override
public char getKey() {
return 'S';
}
@Nullable
@Override
public String getType(PsiElement e) {
if (e instanceof MethodReference && ((MethodReference)e).isStatic()) {
Map> methods = getStaticMethodTypesMap(e.getProject());
String refSignature = ((MethodReference)e).getSignature();
if (methods.containsKey(refSignature)) {
PsiElement[] parameters = ((MethodReference)e).getParameters();
if (parameters.length > 0) {
PsiElement parameter = parameters[0];
if (parameter instanceof StringLiteralExpression) {
String param = ((StringLiteralExpression)parameter).getContents();
if (StringUtil.isNotEmpty(param)) return refSignature + "." + param;
}
}
}
}
return null;
}
@Override
public Collection extends PhpNamedElement> getBySignature(String expression, Project project) {
Map> methods = getStaticMethodTypesMap(project);
int dot = expression.lastIndexOf('.');
String refSignature = expression.substring(0, dot);
Map types = methods.get(refSignature);
if (types != null) {
String type = types.get(expression.substring(dot + 1));
if (type != null) return PhpIndex.getInstance(project).getAnyByFQN(type);
}
return Collections.emptySet();
}
synchronized Map> getStaticMethodTypesMap(final Project project) {
CachedValue