Created
August 17, 2017 07:20
-
-
Save willemnviljoen/d20ad8ad0cc365a7e80744328246610f to your computer and use it in GitHub Desktop.
SQL language injection for PHPStorm which specifically ignores the Doctrine DQL language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LanguageInjectionConfiguration> | |
<injection language="SQL" injector-id="php"> | |
<display-name>"SQL select/delete/insert/update/create" Excluding Doctrine DQL</display-name> | |
<place><![CDATA[and(not(phpLiteralMatchesBrics(".*:.*")), phpLiteralMatchesBrics(" *(((SELECT|DELETE) .*FROM)|((INSERT|REPLACE) .*INTO)|(UPDATE .* SET)|((CREATE|DROP|ALTER) +((TEMPORARY )?TABLE|(UNIQUE )?INDEX))) .*"))]]></place> | |
</injection> | |
</LanguageInjectionConfiguration> |
Cool!
Does this ensure that if I format a page with DQL it will not CAPITALIZE within the dql statement?
i.e. if I got:
$em->query("SELECT U.user from Model::User U")
it will not be converted to
$em->query("SELECT U.USER from Model::USER U")
Hi,
It should prevent that yes, since it stops the IDE from even considering that string to be SQL. I've done a quick experiment on some of my code, asking PHPStorm to format it, and it left it alone.
Hopefully it works for everyone.
this would not work if you write the class name rather than a App:User
shortcut though.
May be we can just pull this to core PhpStorm for now?.. //PS team
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use, go to Preferences (or Settings) -> Editor -> Language Injections.
This is quick and crude. It works by not matching any query expressions with a : character. This is what is normally marked as an error by PHPStorm (or more accurately IntelliLang) when it encounters DQL expressions, so it should prevent them from being marked as errors in most cases.
This can be expanded to exclude other DQL specific phrases, please link any improvements here.