Skip to content

Commit 769fc67

Browse files
authored
Merge pull request #219 from cedricziel/globals-typo3-request
[T3CMS] Resolve value of $GLOBALS['TYPO3_REQUEST']
2 parents 745d152 + 0f6195c commit 769fc67

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

typo3-cms/src/main/java/com/cedricziel/idea/typo3/provider/PhpGlobalsTypeProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import com.intellij.psi.PsiElement;
55
import com.intellij.psi.util.PsiTreeUtil;
66
import com.jetbrains.php.PhpIndex;
7-
import com.jetbrains.php.lang.psi.elements.*;
7+
import com.jetbrains.php.lang.psi.elements.ArrayAccessExpression;
8+
import com.jetbrains.php.lang.psi.elements.ArrayIndex;
9+
import com.jetbrains.php.lang.psi.elements.PhpNamedElement;
10+
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
811
import com.jetbrains.php.lang.psi.elements.impl.StringLiteralExpressionImpl;
912
import com.jetbrains.php.lang.psi.elements.impl.VariableImpl;
1013
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
@@ -56,6 +59,8 @@ public PhpType getType(PsiElement psiElement) {
5659
return new PhpType().add("#C\\TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication");
5760
case "LANG":
5861
return new PhpType().add("#C\\TYPO3\\CMS\\Lang\\LanguageService");
62+
case "TYPO3_REQUEST":
63+
return new PhpType().add("#C\\Psr\\Http\\Message\\ServerRequestInterface");
5964
default:
6065
return null;
6166
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.cedricziel.idea.typo3.provider;
2+
3+
import com.cedricziel.idea.typo3.AbstractTestCase;
4+
import com.intellij.psi.PsiElement;
5+
import com.intellij.psi.PsiFile;
6+
import com.jetbrains.php.lang.PhpFileType;
7+
import com.jetbrains.php.lang.psi.elements.MethodReference;
8+
9+
public class PhpGlobalsTypeProviderTest extends AbstractTestCase {
10+
@Override
11+
protected String getTestDataPath() {
12+
return "testData/com/cedricziel/idea/typo3/provider";
13+
}
14+
15+
public void testGlobalTypesAreResolved() {
16+
assertCanResolveGlobalsValue(
17+
"TYPO3_REQUEST",
18+
"#M#C\\Psr\\Http\\Message\\ServerRequestInterface.getServerParams",
19+
"getServer<caret>Params"
20+
);
21+
assertCanResolveGlobalsValue(
22+
"LANG",
23+
"#M#C\\TYPO3\\CMS\\Lang\\LanguageService.getLL",
24+
"get<caret>LL"
25+
);
26+
assertCanResolveGlobalsValue(
27+
"TYPO3_DB",
28+
"#M#C\\TYPO3\\CMS\\Core\\Database\\DatabaseConnection.exec_SELECTgetRows",
29+
"exec_<caret>SELECTgetRows"
30+
);
31+
assertCanResolveGlobalsValue(
32+
"BE_USER",
33+
"#M#C\\TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication.getPagePermsClause",
34+
"getPagePerms<caret>Clause"
35+
);
36+
assertCanResolveGlobalsValue(
37+
"TSFE",
38+
"#M#C\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController.getPageAndRootlineWithDomain",
39+
"getPageAndRootlineWith<caret>Domain"
40+
);
41+
}
42+
43+
private void assertCanResolveGlobalsValue(String index, String expectedType, String method) {
44+
PsiFile psiFile = myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
45+
"$foo = $GLOBALS['" + index + "'];\n" +
46+
"$foo->" + method + "();");
47+
48+
PsiElement elementAtCaret = psiFile.findElementAt(myFixture.getCaretOffset());
49+
assertNotNull(elementAtCaret);
50+
assertInstanceOf(elementAtCaret.getParent(), MethodReference.class);
51+
52+
MethodReference methodReference = (MethodReference) elementAtCaret.getParent();
53+
assertTrue(methodReference.getType().getTypes().contains(expectedType));
54+
}
55+
}

typo3-cms/testData/com/cedricziel/idea/typo3/provider/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)