I'm trying to generate a namespace through PhpStorm's templating system (File and Code Templates), I can't see any helpers / means of getting this through PhpStorm's documentation.
I was wondering if there was a way to automatically define the namespace based on the directory:
<?php
// I'm wanting to apply to $namespace
namespace $namespace;
class ${NAME} implements
\Zend\Mail\Mailable
{
/** \Zend\Mail\Factory */
private $factory;
...
}#set( $factory = "factory" ) #set( $this- = "this-" ) #set( $directory = ?)
If my directory/filename is zend/mail/model/notice/send.php I'd like this to generate a namespace of Zend\Mail\Model\Notice; I can get the class name through the ${NAME} variable.
I'm aware I can have the template request the namespace through a dialog when the file is being created, however I was wondering if it's possible to automate this?
if you want , you can use groovyScript.
for example, you can create a variable $FOLDER_OF_FILE$ and set this groovyScript to take the folder of file.
groovyScript("String[] p=_editor.getVirtualFile().getPath().split('/');String prevLast = p[p.length-2];")
you can change and adapt my example for your needs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With