vim-snippets/UltiSnips/php.snippets

252 lines
4.1 KiB
Plaintext
Raw Normal View History

priority -50
## Snippets from SnipMate, taken from
## https://github.com/scrooloose/snipmate-snippets.git
snippet gm "PHP Class Getter" b
/**
* Getter for $1
*
* @return ${2:string}
*/
public function get${1/\w+\s*/\u$0/}()
{
return $this->$1;
}
endsnippet
snippet sm "PHP Class Setter" b
/**
* Setter for $1
*
* @param ${2:string} $$1
* @return ${3:`!p snip.rv=snip.basename`}
*/
public function set${1/\w+\s*/\u$0/}(${4:${2/(void|string|int|integer|double|float|object|boolear|null|mixed|number|resource)|(.*)/(?1::$2 )/}}$$1)
{
$this->$1 = $$1;
2015-02-24 11:23:50 -05:00
${5:return $this;}
}
endsnippet
snippet gs "PHP Class Getter Setter" b
/**
* Getter for $1
*
* @return ${2:string}
*/
public function get${1/\w+\s*/\u$0/}()
{
return $this->$1;
}
/**
* Setter for $1
*
* @param $2 $$1
* @return ${3:`!p snip.rv=snip.basename`}
*/
public function set${1/\w+\s*/\u$0/}(${4:${2/(void|string|int|integer|double|float|object|boolear|null|mixed|number|resource)|(.*)/(?1::$2 )/}}$$1)
{
$this->$1 = $$1;
2015-02-24 11:23:50 -05:00
${5:return $this;}
}
endsnippet
snippet pub "Public function" b
/**
* ${3:undocumented function}
*
* @return ${4:void}
*/
public function ${1:name}(${2:$param})
{
${VISUAL}${5:return null;}
}
$0
endsnippet
snippet pro "Protected function" b
/**
* ${3:undocumented function}
*
* @return ${4:void}
*/
protected function ${1:name}(${2:$param})
{
${VISUAL}${5:return null;}
}
$0
endsnippet
snippet pri "Private function" b
/**
* ${3:undocumented function}
*
* @return ${4:void}
*/
private function ${1:name}(${2:$param})
{
${VISUAL}${5:return null;}
}
$0
endsnippet
snippet pubs "Public static function" b
/**
* ${3:undocumented function}
*
* @return ${4:void}
*/
public static function ${1:name}(${2:$param})
{
${VISUAL}${5:return null;}
}
$0
endsnippet
snippet pros "Protected static function" b
/**
* ${3:undocumented function}
*
* @return ${4:void}
*/
protected static function ${1:name}(${2:$param})
{
${VISUAL}${5:return null;}
}
$0
endsnippet
snippet pris "Private static function" b
/**
* ${3:undocumented function}
*
* @return ${4:void}
*/
private static function ${1:name}(${2:$param})
{
${VISUAL}${5:return null;}
}
$0
endsnippet
2013-08-02 10:12:04 -04:00
snippet fu "Function snip" b
function ${1:name}(${2:$param})
2013-08-02 10:12:04 -04:00
{
${VISUAL}${3:return null;}
2013-08-02 10:12:04 -04:00
}
$0
2013-08-02 10:12:04 -04:00
endsnippet
snippet new "New class instance" b
2015-03-02 10:30:48 -05:00
$${1:variableName} = new ${2:${1/\w+\s*/\u$0/}}($3);
$0
endsnippet
snippet ns "namespace declaration" b
namespace ${1:`!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
2015-02-12 05:07:46 -05:00
snip.rv = m.group().replace('/', '\\')
`};
endsnippet
snippet class "Class declaration template" b
<?php
namespace ${1:`!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
2015-02-12 05:07:46 -05:00
snip.rv = m.group().replace('/', '\\')
`};
/**
* Class ${1:`!p snip.rv=snip.basename`}
* @author ${2:`!v g:snips_author`}
*/
class $1
{
2013-08-26 09:11:23 -04:00
}
endsnippet
snippet interface "Interface declaration template" b
<?php
namespace ${1:`!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
2015-02-12 05:07:46 -05:00
snip.rv = m.group().replace('/', '\\')
`};
/**
* Interface ${1:`!p snip.rv=snip.basename`}
* @author ${2:`!v g:snips_author`}
*/
interface $1
{
public function ${3:someFunction}();$4
}
endsnippet
2016-04-30 08:17:26 -04:00
snippet trait "Trait declaration template" b
<?php
namespace ${1:`!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
snip.rv = m.group().replace('/', '\\')
`};
/**
2016-04-30 08:57:11 -04:00
* Trait ${1:`!p snip.rv=snip.basename`}
2016-04-30 08:17:26 -04:00
* @author ${2:`!v g:snips_author`}
*/
trait $1
{
}
endsnippet
snippet construct "__construct()" b
/**
* @param $2mixed ${1/, /\n * \@param mixed /g}
*/
public function __construct(${1:$dependencies})
{${1/\$(\w+)(, )*/\n $this->$1 = $$1;/g}
}
$0
endsnippet
# PHPUnit snippets
snippet testcase "class XYZTest extends \PHPUnit_Framework_TestCase { ... }"
<?php
namespace `!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
snip.rv = m.group().replace('/', '\\')
`;
/**
* @author `!v g:snips_author`
*/
class `!p
snip.rv = re.match(r'.*(?=\.)', fn).group()
` extends \PHPUnit_Framework_TestCase
{
public function test${1}()
{
${0:${VISUAL}}
}
}
endsnippet
# :vim:ft=snippets: