Skip to content

Instantly share code, notes, and snippets.

@simpleadm
Last active February 15, 2019 06:39
Show Gist options
  • Save simpleadm/0707a0997b478fecd728ba67200f7bd1 to your computer and use it in GitHub Desktop.
Save simpleadm/0707a0997b478fecd728ba67200f7bd1 to your computer and use it in GitHub Desktop.
PhpStorm File and code templates for Magento 2
<?php
#parse("PHP File Header.php")
#set($current = "")
#set($MODULE_NAMESPACE = "")
#foreach($current in $MODULE_NAME.split("_"))
#set($MODULE_NAMESPACE = $MODULE_NAMESPACE + "\" + $current)
#end
namespace $MODULE_NAMESPACE.substring(1)\Api\Data;
/**
* ${NAME} data interface.
* @api
*/
interface ${NAME}
{
/**#@+
* Constants for keys of data array. Identical to the name of the getter in snake case
*/
#foreach($current in $PROPERTIES.split(","))
#set($current = $current.trim())
const $current.toUpperCase() = '$current';
#end
/**#@-*/
#foreach($current in $PROPERTIES.split(","))
#set($current = $current.trim())
#set($method = $current.substring(0,1).toUpperCase() + $current.substring(1))
/**
* Get $current
*
* @return #TYPE
*/
public function get$method();
/**
* Set $current
*
* @param #TYPE ${DS}$current
* @return ${DS}this
*/
public function set$method(${DS}$current);
#end
}
<?php
#parse("PHP File Header.php")
#set($current = "")
#set($MODULE_NAMESPACE = "")
#foreach($current in $MODULE_NAME.split("_"))
#set($MODULE_NAMESPACE = $MODULE_NAMESPACE + '\' + $current)
#end
namespace $MODULE_NAMESPACE.substring(1)\Model;
use Magento\Framework\Model\AbstractModel;
/**
* ${NAME} model
*/
class ${NAME} extends AbstractModel implements ${MODULE_NAMESPACE}\Api\Data\\${NAME}Interface
{
#foreach($current in $PROPERTIES.split(","))
#set($current = $current.trim())
#set($method = $current.substring(0,1).toUpperCase() + $current.substring(1))
/**
* {@inheritdoc}
*/
public function get$method()
{
return ${DS}this->getData(self::$current.toUpperCase());
}
/**
* {@inheritdoc}
*/
public function set$method(${DS}$current)
{
${DS}this->setData(self::$current.toUpperCase(), ${DS}$current);
return ${DS}this;
}
#end
}
@simpleadm
Copy link
Author

simpleadm commented Feb 14, 2019

Docs: https://www.jetbrains.com/help/phpstorm/using-file-and-code-templates.html

How create new file template:

How use it:

Result:
https://prnt.sc/mlc4xm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment