Automating Tasks in PhpStorm

PhpStorm has a very rich set of options for automating things - at the moment I'm trying to work out which options work best in which circumstances.

File and Code Templates vs Live Templates:

I want an automated file generator to create the following file:
-----

<?php

namespace vendor/package;

/** External Variables

/*

/* @var $app \JapplicationSite

/*     The application currently being executed

/* @var $params \JRegistry

/*     The currently loaded configuration for the currently executing extension

**/

?>

Your html here

<php
----


This template can be broken down into some repetivie items.  For example,
----
/* @var $app \JapplicationSite
/*     The application currently being executed
----

Will be placed exactly the same way in a Component View, a Module Template, or any other type of template.  So I can move that code section out to an include snippet for easy re-use.

That works great for creating a complete file.  But there are also times when I want to insert a section of code into an existing file.

Live Templates work create for that.  I created a live template and gave it the abbreviation: jdoc::Module->var(app)
A slight modification to the snippet, and it works well for the live template.


This works wonderfully, now from the editory I type 'jdoc::M' and code completion pops up a list of snippets matching my need.   The only problem here is that I am storing the same snippets in 2 places.   It would be much easier if I could either include a live template in a Code Template, or parse an Include file from a Live Template...   So my first question on automation is if it is possible to link these two sections?

0
7 comments
So my first question on automation is if it is possible to link these two sections?

Nope.

If you do not want to have duplicate snippets then I may only suggest to have it as Live Template (basic File Template and then finish with necessary parts by invoking necessary Live Templates manually)

0

Thanks for the update.

For my purposes, once I have a dozen 'templates' setup for the framework, I plan on moving their definitions to json and writing a quick composer plugin to generate the XML for them - so whenever I want a new snippet I can maintain it outside of PHPStorm and simply generate a new xml definition file to import.

I just wanted to make sure I wasn't missing some obvious feature of PHPStorm.

0

My second question has to do with Emmet/Zen Coding.


Is it possible to enable emmet for the PHP code?  IE if I want to generate
/* @var var1 string */
/* @var var2 string */
/* @var var3 string */
/* @var var4 string */
/* @var var5 string */


It is easy to do setup a live template as /* @var $varLabel$ string */ and then invoke it with jdoc::var[assuming I have assigned jdoc::var as the abbreviation]

It would be really great if I could set it up as /* @var $varLabel$$NUM$ string */ and then invoke it with jdoc::var*5 to have it generate all 5 blocks.

0

Another question I have is if there is any problem with using the colon, dash, and arrow sign in live template abbreviations. I've noticed whenever I save a new live template, PHPStorm will not allow me to enter any new text for half a minute or so, presumably as it updates the typeahead index.

I really like using abbreviations which are structured as static method invocations, for example jdoc::Module->var(app)
I'm using that abbrevitaion to mean:
jdoc:: Create a php doc comment block for a Joomla element
Module : The element being documented comes from the Joomla Module package
var: I am documenting a variable that exists in the current scope, but was set from another file
app: I want the documentation for the $app variable

By adding that to my html template file, PHPStorm is then able to provide me with method completion information for $app


Even more cool is that the live template lookup is EXTREMELY proactive.   At the moment I only have a handful of these templates,  so as soon as I type  jdoc:: and hit tab, I get easily pick the one I need.  However, eventually I may have hundreds of these.  One thing I discovered accidentally is that: jdmv[tab] will ALSO provide my live template as an option.  It seems to do some sort of word matching for initials, so it matches the jd in jdoc, the M in module, and the v in var.   

About the only thing that would be MORE convenient for me would be if I could use the colon and dash charectors to trigger the lookup.  Ie instead of jdoc[tab] giving me all jdocs, jdoc: would be enough to trigger the lookup of all jdocs.

0
Is it possible to enable emmet for the PHP code?

No

You can file new Feature Request at Issue Tracker but at the moment I do not see that it will be implemented any time soon.

P.S.
In v8 (currently in EAP stage) you can use multi-cursor editing (like in Sublime) which may speed things up a bit for you here. You can also use Shifter plugin to increment numbers.

0

Too much text ... I'm confused.

Anyway: instead of using ordinary code completion popup .. try invoking Live Templates completion popup instead (Ctrl+J -- Code | Insert Live Template...) -- it may behave better for you.

0

Sorry for the verbosity.

my main goal is to minimize the number of things I have to remember.  So I don't want to use [tab] for one thing and CTR-J for the other[but it is great that it is an option!]

So far, I am finding that using the ordinary code completion popup works extremely well for me.
I just found it interesting how smart it is.  My live template abbreviation is jdoc::Module->Var(app) and "jdma"[tab] is enough to filter down the live template as the most likely option, and a few other options.   By the end of this week, I will have all the externally declared variables defined for Module templates, so I will have:
jdoc::Module->Var(app)
jdoc::Module->Var(params)
jdoc::Module->Var(content)
jdoc::Module->Var(scope)
jdoc::Module->Var(template)
jdoc::Module->Var(menu)

While I expect that jdmva will also display jdoc::Module->Var(params), jdoc::Module->Var(app) will be first in the list..  I always like it when the first item in the list is the one I want, saves me a TON of time.

0

Please sign in to leave a comment.