1
0
Fork 0
mirror of synced 2024-11-04 08:28:57 -05:00
ultimate-vim/sources_non_forked/vim-snippets/UltiSnips/php.snippets

287 lines
5 KiB
Text
Raw Normal View History

priority -50
2016-07-16 14:30:35 -04:00
global !p
import vim
# Set g:ultisnips_php_scalar_types to 1 if you'd like to enable PHP 7's scalar types for return values
def isPHPScalarTypesEnabled():
isEnabled = vim.eval("get(g:, 'ultisnips_php_scalar_types', 0)") == "1"
return isEnabled or re.match('<\?php\s+declare\(strict_types=[01]\);', '\n'.join(vim.current.window.buffer))
endglobal
## Snippets from SnipMate, taken from
## https://github.com/scrooloose/snipmate-snippets.git
2016-06-26 07:12:36 -04:00
snippet gm "PHP Class Getter" b
2015-02-04 05:43:54 -05:00
/**
* Getter for $1
2015-02-04 05:43:54 -05:00
*
2016-06-11 09:56:50 -04:00
* @return ${2:string}
*/
2016-07-16 14:30:35 -04:00
public function get${1/\w+\s*/\u$0/}()`!p snip.rv = ': '+t[2] if isPHPScalarTypesEnabled() else ''`
{
2016-06-26 07:12:36 -04:00
return $this->$1;
}
endsnippet
2016-06-26 07:12:36 -04:00
snippet sm "PHP Class Setter" b
2015-02-04 05:43:54 -05:00
/**
* Setter for $1
2015-02-04 05:43:54 -05:00
*
2016-06-11 09:56:50 -04:00
* @param ${2:string} $$1
2015-02-04 05:43:54 -05:00
* @return ${3:`!p snip.rv=snip.basename`}
*/
2015-02-04 05:43:54 -05:00
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)
{
2016-06-26 07:12:36 -04:00
$this->$1 = $$1;
2015-07-13 06:22:46 -04:00
2016-06-26 07:12:36 -04:00
${5:return $this;}
}
endsnippet
snippet gs "PHP Class Getter Setter" b
2015-02-04 05:43:54 -05:00
/**
2014-04-18 08:58:02 -04:00
* Getter for $1
2015-02-04 05:43:54 -05:00
*
2016-06-11 09:56:50 -04:00
* @return ${2:string}
*/
2016-07-16 14:30:35 -04:00
public function get${1/\w+\s*/\u$0/}()`!p snip.rv = ': '+t[2] if isPHPScalarTypesEnabled() else ''`
{
2016-06-26 07:12:36 -04:00
return $this->$1;
}
2015-02-04 05:43:54 -05:00
/**
2014-04-18 08:58:02 -04:00
* Setter for $1
2015-02-04 05:43:54 -05:00
*
* @param $2 $$1
2016-06-26 07:12:36 -04:00
* @return ${3:`!p snip.rv=snip.basename`}
2013-08-03 08:50:12 -04:00
*/
2016-06-26 07:12:36 -04:00
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)
{
2016-06-26 07:12:36 -04:00
$this->$1 = $$1;
2015-07-13 06:22:46 -04:00
2016-06-26 07:12:36 -04: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
snippet fu "Function snip" b
function ${1:name}(${2:$param})
{
${VISUAL}${3:return null;}
}
$0
endsnippet
snippet new "New class instance" b
2015-07-13 06:22:46 -04:00
$${1:variableName} = new ${2:${1/\w+\s*/\u$0/}}($3);
$0
endsnippet
snippet ns "namespace declaration" b
namespace ${1:`!p
2016-05-14 07:57:54 -04:00
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
2015-02-24 05:45:22 -05:00
snip.rv = m.group().replace('/', '\\')
`};
endsnippet
snippet class "Class declaration template" b
<?php
namespace ${1:`!p
2016-05-14 07:57:54 -04:00
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
2015-02-24 05:45:22 -05:00
snip.rv = m.group().replace('/', '\\')
`};
/**
* Class ${1:`!p snip.rv=snip.basename`}
* @author ${2:`!v g:snips_author`}
*/
class $1
{
}
endsnippet
snippet interface "Interface declaration template" b
<?php
namespace ${1:`!p
2016-05-14 07:57:54 -04:00
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
2015-02-24 05:45:22 -05:00
snip.rv = m.group().replace('/', '\\')
`};
/**
* Interface ${1:`!p snip.rv=snip.basename`}
* @author ${2:`!v g:snips_author`}
*/
interface $1
{
2016-06-11 09:56:50 -04:00
public function ${3:someFunction}();$4
}
endsnippet
2016-05-14 07:57:54 -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('/', '\\')
`};
/**
* Trait ${1:`!p snip.rv=snip.basename`}
* @author ${2:`!v g:snips_author`}
*/
trait $1
{
}
endsnippet
snippet construct "__construct()" b
/**
2018-09-24 20:40:17 -04:00
* @param$2 ${1/, /\n * \@param /g}
*/
public function __construct(${1:$dependencies})
2018-09-24 20:40:17 -04:00
{${1/\w* ?\$(\w+)(, )*/\n $this->$1 = $$1;/g}
}
$0
endsnippet
2016-06-11 09:56:50 -04:00
# PHPUnit snippets
snippet testcase "class XYZTest extends \PHPUnit_Framework_TestCase { ... }"
<?php
2016-06-11 09:56:50 -04:00
namespace `!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
snip.rv = m.group().replace('/', '\\')
`;
/**
2016-06-11 09:56:50 -04:00
* @author `!v g:snips_author`
*/
2016-06-11 09:56:50 -04:00
class `!p
snip.rv = re.match(r'.*(?=\.)', fn).group()
` extends \PHPUnit_Framework_TestCase
{
2017-02-11 08:01:38 -05:00
public function test$1()
2016-06-11 09:56:50 -04:00
{
${0:${VISUAL}}
}
}
endsnippet
snippet testcase6 "class XYZTest extends TestCase { ... }"
<?php
namespace `!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
snip.rv = m.group().replace('/', '\\')
`;
use PHPUnit\Framework\TestCase;
/**
* @author `!v g:snips_author`
*/
class `!p
snip.rv = re.match(r'.*(?=\.)', fn).group()
` extends TestCase
{
public function test$1()
{
${0:${VISUAL}}
}
}
endsnippet
# :vim:ft=snippets: