Jump to content

PHPStorm for ProcessWire Developers


Recommended Posts

PHPStorm for PW Devs

This thread is a place for ProcessWire developers who use PHPStorm to share their experience, tips, frustrations, solutions, code snippets and generally discuss all things PHPStorm.

From Wikipedia:

JetBrains PhpStorm is a commercial, cross-platform IDE for PHP[1] built on JetBrains' IntelliJ IDEA platform.

PhpStorm provides an editor for PHP, HTML and JavaScript with on-the-fly code analysis, error prevention and automated refactorings for PHP and JavaScript code


Thanks @kongondo for the Visual Studio Code post earlier.

  • Like 5
Link to comment
Share on other sites

  • 4 weeks later...

Does anyone know if it's possible to do something to "tell" PhpStorm how PW uses a template file and what variables are in scope there? For the purposes of code completion and to avoid erroneous undeclared variable warnings.

Currently I manually list all API variables and variables declared in the auto-prepended _init.php inside a DocBlock at the top of every template file. This works but gets pretty tiresome, especially when you need to make a change globally.

What would be cool is if PhpStorm could "know" that all API variables are available in every template file and that _init.php is prepended and so all the variables declared there are in scope. Anyone know a way to achieve this?

BTW, for API variables the Functions API is a no-go for me because I dislike all the string concatenation that goes with it. 

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Does anyone know if it's possible to do something to "tell" PhpStorm how PW uses a template file and what variables are in scope there?

+1 for that!

Still waiting for a ProcessWire Plugin for PhpStorm.

All those lints are horrible :o

  • Like 1
Link to comment
Share on other sites

Just sharing a tip...

PhpStorm had slowed down to a crawl, disk usage was regularly at 100% and the interface was sluggish to the point it was almost unusable. After some googling I found a suggestion to try restarting using the Invalidate Caches option and it has made a huge difference. Now everything is snappy and fast again. 

More info here, and be sure to read and understand the warnings, especially the fact that your local history will be erased.

  • Like 2
Link to comment
Share on other sites

Awesome tip, @Robin S

Local history is something I use quite regularly but I suppose I should be committing more often as per the Git mantra :)

Perhaps users who rely on local history can make a backup of the System Cache first before invalidating the cache and seeing what sort of performance gains they get. 

The locations are :

	<User home>\.PhpStormXX\system that stores PhpStorm data caches.

	~/.PhpStormXX/system that stores PhpStorm data caches.

	~/Library/Caches/PhpStormXX contains data caches, logs, local history, etc. These files can be quite significant in size.

Source : https://www.jetbrains.com/help/phpstorm/project-and-ide-settings.html

  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...

Hi All,

Wonder if anybody can offer any advice on using PHPStorm and auto completion?

I'm in a standard template file and if I type say $page-> and ask for some suggestions via Control-Space I get a 'no suggestions' tooltip.  I've just learn't about the functions API which seem to autocomplete just fine.  Just can't seem to get the variables based API working.  Am I doing something wrong?

I see Ryans .phpstorm.meta.php file in /wire/core and am thinking the 2nd section being noted about not working might be causing the problem?

I'm still a little new to PHPStorm but the project all seems setup and working fine just not this part.  I've attached mini screenshots what I see when trying to auto complete with both the functions API and the variables one.

All the examples I come across seem to use the variables API and not the functions one, any big reason not to use it?  I'm no PHP expert so I might not be understanding an obvious 'don't use scenario', be gentle lol :)

Cheers All.

** A little addition, whilst the functions API is autocompleting for functions like children() and the template field 'title'  If I add a custom field I don't see it in the autocomplete list?  I'm not quite sure how PHPStorm can pull in those fields in the right context so I'm thinking my understanding is wrong on how this all works!  Seems a shame to use an IDE with such strong code inspection etc for PHP and not be able to use it as much as possible in the template files **


Screen Shot 2018-02-10 at 11.39.26.png

  • Like 1
Link to comment
Share on other sites

19 hours ago, geekpete said:

Just can't seem to get the variables based API working.

PhpStorm doesn't know what API variables PW makes available to template files. So you need to add variable types hints in a DocBlock at the top of your template files. I use...

 * @var Config $config
 * @var Fieldgroups $fieldgroups
 * @var Fields $fields
 * @var Languages $languages
 * @var Modules $modules
 * @var Page $page
 * @var Pages $pages
 * @var Paths $urls
 * @var Permissions $permissions
 * @var ProcessWire $wire
 * @var Roles $roles
 * @var Sanitizer $sanitizer
 * @var Session $session
 * @var Templates $templates
 * @var User $user
 * @var Users $users
 * @var WireCache $cache
 * @var WireDatabasePDO $database
 * @var WireDateTime $datetime
 * @var WireFileTools $files
 * @var WireInput $input
 * @var WireLog $log
 * @var WireMail $mail
 * @var \ProCache $procache
 * @var \FormBuilder $forms


19 hours ago, geekpete said:

If I add a custom field I don't see it in the autocomplete list?

Your field names are not a part of the PW API (field names don't exist in the file system but only in the database). But I believe you can get code completion for field names using the Template Stubs module.

  • Like 3
  • Thanks 1
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Robin S
      This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
      Auto Template Stubs
      Automatically creates stub files for templates when fields or fieldgroups are saved.
      Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
      Install the Auto Template Stubs module.
      You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
      The directory path used to store the stub files is configurable.
      There is a checkbox to manually trigger the regeneration of all stub files if needed.
      Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
      /** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.

      Adding data types for non-core Fieldtype modules
      The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
      // Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
      Inspired by and much credit to the Template Stubs module by mindplay.dk.
    • By kongondo
      Visual Studio Code for PW Devs
      This thread is a place for ProcessWire developers who use Visual Studio Code (aka VSC or Code)  to share their experience, tips, frustrations , solutions, code snippets and generally discuss all things VSC.
      From Wikipedia:
    • By szabesz
      CodeRunner 2 is on sale at MacUpdate: https://www.macupdate.com/app/mac/38362/coderunner
      Mostly I use it for writing shell scripts, mocking up algorithms in PHP, JavaScript/jQuery. But is also supports other programming languages as well.
      "An advanced, highly flexible, and easy-to-use programming editor for your Mac. CodeRunner supports a large number of languages, and delivers big IDE features while remaining lightweight and clutter-free."
    • By pwFoo
      I moved from netbeans to atom. Tested lighttable, brackets and visual studio code, but at the moment I take a look into web based IDEs. Most are based on ACE editor (alternative could be codemirror) like chrome apps caret or super neutron drive (both with chrome dependency at the moment). 
      Recently I looked into cloud9, codetasty, ... and codiad.
      Codiad is open source. php / js based and works fine. Autocomplete feature and suggestions should be improved, but it's ok. Because it's open source you can download it from github repo or test it as a docker container (wernight/codiad image for example). 
      Codytasty is a cloud hosted solution with a really awesome autocomplete / suggestions for php, js and html! But it isn't open source (there is a free to use hosted version with limited workspaces and features).
      At the moment I testing codiad@docker, but use still atom for coding and searching for the best IDE out there *g*
      What do you think about IDEs and the new trend to web based IDEs?
    • By FrancisChung
      I'm writing this to give back something to the community that has given so much up front over the past year.
      I noticed there's hardly any discussion about testing in these forums so I decided to write this quick primer to get some discussion going.
      I'm by no means an expert on phpunit or selenium but I had to jump through a few hoops to get it working (especially with PHPStorm), so I thought I figured I should share my experiences with the community. 

      Also, I'm hoping non Phpstorm users can still  pick something up useful in this post.

      Prerequisites : It is assumed Phpunit (https://phpunit.de/) is installed via Composer,   Selenium (http://www.seleniumhq.org/) and Php-webdriver for Selenium (https://github.com/facebook/php-webdriver) is preinstalled.
      For Phpstorm users, there's a fairly detailed installation and unit testing instructions here (https://www.jetbrains.com/help/phpstorm/2016.1/testing.html)
      I found some parts of it leaving me with unanswered questions, so I'm hoping this post will supplement any questions that you might encounter.

      Rather than writing a single monolithic post, I will write several posts covering different topics.
  • Create New...