Merge pull request #123 from chrisyue/master

new php snippets
This commit is contained in:
Honza Pokorny 2012-07-31 02:57:16 -07:00
commit 220bc3e883
3 changed files with 102 additions and 45 deletions

View File

@ -35,3 +35,4 @@ msanders
Povilas Balzaravičius Pawka Povilas Balzaravičius Pawka
Dmitry Dementev Dmitry Dementev
Travis Holton Travis Holton
Chrisyue

View File

@ -21,6 +21,7 @@ to maintain snippets for a language, please get in touch.
* HTML Django - [honza](http://github.com/honza) * HTML Django - [honza](http://github.com/honza)
* Markdown - [honza](http://github.com/honza) * Markdown - [honza](http://github.com/honza)
* Ruby - [taq](http://github.com/taq) * Ruby - [taq](http://github.com/taq)
* PHP - [chrisyue](http://github.com/chrisyue)
Contributing notes Contributing notes
------------------ ------------------

View File

@ -1,13 +1,92 @@
snippet php snippet <?
<?php <?php
${1} ${1}
?>
snippet phpil
<?php ${1} ?>
snippet ec snippet ec
echo "${1:string}"${2}; echo ${1};
snippet ethis snippet <?e
<?php echo $this->${1:something}; ?> <?php echo ${1} ?>
# this one is for php5.4
snippet <?=
<?=${1}?>
snippet ns
namespace ${1:Foo\Bar\Baz};
${2}
snippet use
use ${1:Foo\Bar\Baz};
${2}
snippet c
${1:abstract }class ${2:`Filename()`}
{
${3}
}
snippet i
interface ${1:`Filename()`}
{
${2}
}
snippet t.
$this->${1}
snippet f
function ${1:foo}(${2:array }${3:$bar})
{
${4}
}
# method
snippet m
${1:abstract }${2:protected}${3: static} function ${4:foo}(${5:array }${6:$bar})
{
${7}
}
# setter method
# I think vim's functions will not be called at the snipMate's runtime
# but `compile` time
# so `tolower` here won't work
# but it would be wonderful if we could make the property and parameter to lower case
snippet sm
${1:public} function set${2:Foo}(${3:$2 }$${4:`tolower('$2')`})
{
$this->${5:$4} = $$4;
${6}
return $this;
}
# getter method
snippet gm
${1:public} function get${2:Foo}()
{
return $this->${3:$2};
}
#setter
snippet $s
${1:$foo}->set${2:Bar}(${3});
#getter
snippet $g
${1:$foo}->get${2:Bar}();
# Tertiary conditional
snippet =?:
$${1:foo} = ${2:true} ? ${3:a} : ${4};
snippet ?:
${1:true} ? ${2:a} : ${3}
snippet C
$_COOKIE['${1:variable}']${2}
snippet E
$_ENV['${1:variable}']${2}
snippet F
$_FILES['${1:variable}']${2}
snippet G
$_GET['${1:variable}']${2}
snippet P
$_POST['${1:variable}']${2}
snippet R
$_REQUEST['${1:variable}']${2}
snippet S
$_SERVER['${1:variable}']${2}
snippet SS
$_SESSION['${1:variable}']${2}
# the following are old ones
snippet inc snippet inc
include '${1:file}';${2} include '${1:file}';${2}
snippet inc1 snippet inc1
@ -16,27 +95,6 @@ snippet req
require '${1:file}';${2} require '${1:file}';${2}
snippet req1 snippet req1
require_once '${1:file}';${2} require_once '${1:file}';${2}
# $GLOBALS['...']
snippet globals
$GLOBALS['${1:variable}']${2: = }${3:something}${4:;}${5}
snippet G
$GLOBALS['${1:variable}']
snippet $_ COOKIE['...']
$_COOKIE['${1:variable}']${2}
snippet $_ ENV['...']
$_ENV['${1:variable}']${2}
snippet $_ FILES['...']
$_FILES['${1:variable}']${2}
snippet $_ Get['...']
$_GET['${1:variable}']${2}
snippet $_ POST['...']
$_POST['${1:variable}']${2}
snippet $_ REQUEST['...']
$_REQUEST['${1:variable}']${2}
snippet $_ SERVER['...']
$_SERVER['${1:variable}']${2}
snippet $_ SESSION['...']
$_SESSION['${1:variable}']${2}
# Start Docblock # Start Docblock
snippet /* snippet /*
/** /**
@ -130,7 +188,7 @@ snippet doc_h
*/ */
# Interface # Interface
snippet doc_i snippet interface
/** /**
* ${2:undocumented class} * ${2:undocumented class}
* *
@ -138,8 +196,9 @@ snippet doc_i
* @author ${4:`g:snips_author`} * @author ${4:`g:snips_author`}
*/ */
interface ${1:} interface ${1:}
{${5} {
} // END interface $1 ${5}
}
# class ... # class ...
snippet class snippet class
/** /**
@ -148,9 +207,12 @@ snippet class
class ${2:ClassName} class ${2:ClassName}
{ {
${3} ${3}
function ${4:__construct}(${5:argument}) /**
* ${4}
*/
${5:public} function ${6:__construct}(${7:argument})
{ {
${6:// code...} ${8:// code...}
} }
} }
# define(...) # define(...)
@ -198,9 +260,6 @@ snippet elseif
elseif (${1:/* condition */}) { elseif (${1:/* condition */}) {
${2:// code...} ${2:// code...}
} }
# Tertiary conditional
snippet t
$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};${5}
snippet switch snippet switch
switch ($${1:variable}) { switch ($${1:variable}) {
case '${2:value}': case '${2:value}':
@ -235,11 +294,6 @@ snippet foreachkil
<?php foreach ($${1:variable} as $${2:key} => $${3:value}): ?> <?php foreach ($${1:variable} as $${2:key} => $${3:value}): ?>
${4:<!-- html... -->} ${4:<!-- html... -->}
<?php endforeach; ?> <?php endforeach; ?>
snippet fun
${1:public }function ${2:FunctionName}(${3})
{
${4:// code...}
}
# $... = array (...) # $... = array (...)
snippet array snippet array
$${1:arrayName} = array('${2}' => ${3});${4} $${1:arrayName} = array('${2}' => ${3});${4}
@ -274,9 +328,9 @@ snippet getset
* *
* @return ${2} * @return ${2}
*/ */
function get$1() public function get$1()
{ {
return $this->_$1; return $this->$1;
} }
/** /**
@ -284,9 +338,10 @@ snippet getset
* *
* @param mixed $$1 ${3} * @param mixed $$1 ${3}
*/ */
function set$1($$1) public function set$1($$1)
{ {
$this->_$1 = $$1; $this->$1 = $$1;
return $this;
} }
snippet rett snippet rett
return true; return true;