symfony helpers / sfPHP-tmbundle
New TextMate bundle for PHP
Requirements
The only & strongest requirement for sfPHP bundle is to turning of the default PHP bundle, because syntax descriptor & almost all snippets will conflct with it.
To turn off default PHP bundle in TextMate open Bundles -> Bundle Editor -> Show Bundle Editor, there click Filter List... in left bottom corner & unset checkbox near PHP, click Done & you're done :-)
Features
- correct "Go To Symbol" navigator inside classes & php code;
- full support of symfony coding style guides;
- support of symfony, Doctrine & Propel contexts;
- base class context, in which some snippets do logic things;
- moving macroses.
Contexts
Main new feature of sfPHP bundle is contexts. Contexts is a php bundle syntax extention, that allows bundle to guess in which context snippet or command was called. Basically in php bundle was 1 global context (source.php.embedded.block.html). sfPHP also knows when snippet or command called in:
- class or not;
- symfony actions or action;
- symfony components or component;
- symfony form;
- symfony configuration file (project, app or plugin);
- symfony filter;
- symfony form widget;
- doctrine table class.
So, for example, fun snippet in class will expand to
${1:public} function ${2:func}(${3:\$arg})
{
$0
}
And outside class, same fun snippet will expand to
function ${1:func}(${2:\$arg})
{
$0
}
This is the main idea of sfPHP bundle & why it's requirement for other sf* bundles.
Variables
sfPHP has some advantages in variables snippet area.
Almost all variable snippets starts with $ symbol. It's done to ease remember of them.
$inside class will expand to${1:public} \$${2:var} = ...;s$inside class will create${1:public} static \$${2:var} = ...;$iinside class will expand as\$this->${0:var}(instance variable);$i=inside class will expand to\$this->${1:var} = ...(set instance variable);$cwill expand toself::\$${0:var}(class variable);$c=will beself::\$${1:var} = ...;$=everywhere will expand to\$${1:var} = .... It's basic variable set;$arreverywhere will be\$${1:var} = array($0).
Modifiers
Modifiers is the special symbols, which ends some snippets in some contexts. Basically, modifiers is marks for special writed macroses. In sfPHP there are 2 main template snippets:
?]expands to[?php $0 ?];$>expands to[?php echo ${0:\$var} ?].
Modifiers of them is $ & ?. So, ending your snippet in text.html context with $ or ? will first wraps your snippet in [?php ?] or [?php echo ?] & only then tries to expand it.
For example (all snippets run in layouts - text.html context):
?$will expand to[?php echo (${1:\$condition}) ? ${2:'if true'} : ${0:'else'} ?]snippet;req1?will expand to[?php require_once ${0:'file'}; ?]snippet.
Moving macroses
sfPHP comes with some interesting macroses:
⌘↩moves you from any position of the current line to new line;⇧⌘↩appends;to the end of current line & moves you to the next from any position;⌥⇧↩appends->to the end of current line & moves you to the next from any position;
Also, there's some very important macroses, without which it's near impossible to use bundles, that based on sfPHP:
⌘R"Edit inner content". It will move you inside brackets, when you have selected string with them & into array definition, when you select whole empty array. All snippets in sf* bundles writed as${0:'value'}, it helps when you need to pass a variable instead of string, but when you need to edit inner content of string (or array) - just use this macros;⌥⌘↩"Go into definition". This macros moves you inside brackets ({,}), when you are before them. Many bundles in sfPHP & others sf* writed with same rules: when we have snippet forifcondition, we need possibility to use other snippets in condition brackets ((,)). Soifsnippet looks likeif (${0:true}){}. It means, that snippet ends in condition brackets, but when you finish condition editing - just call "Go into definition" macros & you're in{$0}brackets.