From dccf69d17a4e47861adf277429adbdd278f87d2b Mon Sep 17 00:00:00 2001 From: chrisyue Date: Wed, 25 Jul 2012 03:02:30 +0800 Subject: [PATCH 1/9] create my own php snippet --- snippets/php.snippets | 60 ++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/snippets/php.snippets b/snippets/php.snippets index b93eaa0..f610ce3 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -1,13 +1,13 @@ -snippet php +snippet ph -snippet phpil - snippet ec - echo "${1:string}"${2}; -snippet ethis - ${1:something}; ?> + echo ${1}; +snippet ecil + +snippet th + $this->${1:something} snippet inc include '${1:file}';${2} snippet inc1 @@ -16,26 +16,21 @@ snippet req require '${1:file}';${2} snippet req1 require_once '${1:file}';${2} -# $GLOBALS['...'] -snippet globals - $GLOBALS['${1:variable}']${2: = }${3:something}${4:;}${5} -snippet G - $GLOBALS['${1:variable}'] -snippet $_ COOKIE['...'] +snippet C $_COOKIE['${1:variable}']${2} -snippet $_ ENV['...'] +snippet E $_ENV['${1:variable}']${2} -snippet $_ FILES['...'] +snippet F $_FILES['${1:variable}']${2} -snippet $_ Get['...'] +snippet G $_GET['${1:variable}']${2} -snippet $_ POST['...'] +snippet P $_POST['${1:variable}']${2} -snippet $_ REQUEST['...'] +snippet R $_REQUEST['${1:variable}']${2} -snippet $_ SERVER['...'] +snippet S $_SERVER['${1:variable}']${2} -snippet $_ SESSION['...'] +snippet SS $_SESSION['${1:variable}']${2} # Start Docblock snippet /* @@ -138,8 +133,9 @@ snippet doc_i * @author ${4:`g:snips_author`} */ interface ${1:} - {${5} - } // END interface $1 + { + ${5} + }$1 # class ... snippet class /** @@ -148,7 +144,7 @@ snippet class class ${2:ClassName} { ${3} - function ${4:__construct}(${5:argument}) + ${7:public} function ${4:__construct}(${5:argument}) { ${6:// code...} } @@ -236,10 +232,15 @@ snippet foreachkil ${4:} snippet fun - ${1:public }function ${2:FunctionName}(${3}) + function ${1:FunctionName}(${2}) + { + ${3:// code...} + }${4} +snippet p + ${1:protected} function ${2:FunctionName}(${3}) { ${4:// code...} - } + }${5} # $... = array (...) snippet array $${1:arrayName} = array('${2}' => ${3});${4} @@ -274,9 +275,9 @@ snippet getset * * @return ${2} */ - function get$1() + public function get$1() { - return $this->_$1; + return $this->$1; } /** @@ -284,9 +285,10 @@ snippet getset * * @param mixed $$1 ${3} */ - function set$1($$1) + public function set$1($$1) { - $this->_$1 = $$1; + $this->$1 = $$1; + return $this; } snippet rett return true; From 183a430ff03183e60a24baa0d11fcae0aae4c163 Mon Sep 17 00:00:00 2001 From: chrisyue Date: Wed, 25 Jul 2012 03:06:32 +0800 Subject: [PATCH 2/9] update README.md and AUTHORS --- AUTHORS | 1 + README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index e985d7e..30c65d9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -35,3 +35,4 @@ msanders Povilas Balzaravičius Pawka Dmitry Dementev Travis Holton +Chrisyue diff --git a/README.md b/README.md index 6a7b970..f1f8bac 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ to maintain snippets for a language, please get in touch. * HTML Django - [honza](http://github.com/honza) * Markdown - [honza](http://github.com/honza) * Ruby - [taq](http://github.com/taq) +* PHP - [chrisyue](http://github.com/chrisyue) Contributing notes ------------------ From d8c5318448fe78ab0719dddf1f7c6a9f8a08114f Mon Sep 17 00:00:00 2001 From: chrisyue Date: Wed, 25 Jul 2012 12:09:06 +0800 Subject: [PATCH 3/9] change 'ph' to ' +# this is for php5.4 +snippet snippet th $this->${1:something} snippet inc @@ -125,7 +128,7 @@ snippet doc_h */ # Interface -snippet doc_i +snippet interface /** * ${2:undocumented class} * @@ -135,7 +138,7 @@ snippet doc_i interface ${1:} { ${5} - }$1 + } # class ... snippet class /** @@ -144,10 +147,13 @@ snippet class class ${2:ClassName} { ${3} - ${7:public} function ${4:__construct}(${5:argument}) + /** + * ${4} + */ + ${5:public} function ${6:__construct}(${7:argument}) { - ${6:// code...} - } + ${8:// code...} + }${9} } # define(...) snippet def From 4a8ba6ff5bf684a2ae33904f8b3ff830745c5808 Mon Sep 17 00:00:00 2001 From: chrisyue Date: Fri, 27 Jul 2012 19:40:14 +0800 Subject: [PATCH 4/9] add new class and interface snippet, and some other improvement --- snippets/php.snippets | 63 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/snippets/php.snippets b/snippets/php.snippets index e231da5..a7ee9a7 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -6,11 +6,58 @@ snippet ec echo ${1}; snippet -# this is for php5.4 +# this one is for php5.4 snippet -snippet th - $this->${1:something} +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:foo} +snippet f + function ${1:foo}(${2}) + { + ${3:echo 'hello world';} + } +# method +snippet m + ${1:abstract }${2:protected}${3: static} function ${4:foo}(${5}) + { + ${6} + } +# 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}; + } + +# the following are old ones snippet inc include '${1:file}';${2} snippet inc1 @@ -237,16 +284,6 @@ snippet foreachkil $${3:value}): ?> ${4:} -snippet fun - function ${1:FunctionName}(${2}) - { - ${3:// code...} - }${4} -snippet p - ${1:protected} function ${2:FunctionName}(${3}) - { - ${4:// code...} - }${5} # $... = array (...) snippet array $${1:arrayName} = array('${2}' => ${3});${4} From 4d13e42868cb121745a8ee8c0d20c3c64515a6a4 Mon Sep 17 00:00:00 2001 From: chrisyue Date: Fri, 27 Jul 2012 20:04:48 +0800 Subject: [PATCH 5/9] add typehint to function --- snippets/php.snippets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/php.snippets b/snippets/php.snippets index a7ee9a7..270b4a6 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -28,9 +28,9 @@ snippet i snippet $t $this->${1:foo} snippet f - function ${1:foo}(${2}) + function ${1:foo}(${2:array }$${3:bar}) { - ${3:echo 'hello world';} + ${4} } # method snippet m From fff374a6f7a479727e878c7b5f35a320cf76a896 Mon Sep 17 00:00:00 2001 From: chrisyue Date: Fri, 27 Jul 2012 20:34:02 +0800 Subject: [PATCH 6/9] add typehint to --- snippets/php.snippets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/php.snippets b/snippets/php.snippets index 270b4a6..b44569f 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -28,15 +28,15 @@ snippet i snippet $t $this->${1:foo} snippet f - function ${1:foo}(${2:array }$${3:bar}) + function ${1:foo}(${2:array }${3:$bar}) { ${4} } # method snippet m - ${1:abstract }${2:protected}${3: static} function ${4:foo}(${5}) + ${1:abstract }${2:protected}${3: static} function ${4:foo}(${5:array }${6:$bar}) { - ${6} + ${7} } # setter method # I think vim's functions will not be called at the snipMate's runtime From 3508130a2111d69614675263107982a34661d7aa Mon Sep 17 00:00:00 2001 From: chrisyue Date: Sat, 28 Jul 2012 14:16:41 +0800 Subject: [PATCH 7/9] move GLOBAL var to 'new snippet section' --- snippets/php.snippets | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/snippets/php.snippets b/snippets/php.snippets index b44569f..e49065f 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -26,7 +26,7 @@ snippet i ${2} } snippet $t - $this->${1:foo} + $this->${1:foo}${2} snippet f function ${1:foo}(${2:array }${3:$bar}) { @@ -56,16 +56,6 @@ snippet gm { return $this->${3:$2}; } - -# the following are old ones -snippet inc - include '${1:file}';${2} -snippet inc1 - include_once '${1:file}';${2} -snippet req - require '${1:file}';${2} -snippet req1 - require_once '${1:file}';${2} snippet C $_COOKIE['${1:variable}']${2} snippet E @@ -82,6 +72,16 @@ snippet S $_SERVER['${1:variable}']${2} snippet SS $_SESSION['${1:variable}']${2} + +# the following are old ones +snippet inc + include '${1:file}';${2} +snippet inc1 + include_once '${1:file}';${2} +snippet req + require '${1:file}';${2} +snippet req1 + require_once '${1:file}';${2} # Start Docblock snippet /* /** @@ -200,7 +200,7 @@ snippet class ${5:public} function ${6:__construct}(${7:argument}) { ${8:// code...} - }${9} + } } # define(...) snippet def From faa4bb490e5723cc236c8984beea51b94bcefc08 Mon Sep 17 00:00:00 2001 From: chrisyue Date: Mon, 30 Jul 2012 16:19:03 +0800 Subject: [PATCH 8/9] add setter and getter --- snippets/php.snippets | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/snippets/php.snippets b/snippets/php.snippets index e49065f..d6d6bae 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -26,7 +26,7 @@ snippet i ${2} } snippet $t - $this->${1:foo}${2} + $this->${1} snippet f function ${1:foo}(${2:array }${3:$bar}) { @@ -56,6 +56,12 @@ snippet gm { return $this->${3:$2}; } +#setter +snippet $s + ${1:$foo}->set${2:Bar}(${3}); +#getter +snippet $g + ${1:$foo}->get${2:Bar}(); snippet C $_COOKIE['${1:variable}']${2} snippet E From a6a10c815017c9357f02e3deae0a8e44f8004838 Mon Sep 17 00:00:00 2001 From: chrisyue Date: Mon, 30 Jul 2012 23:09:36 +0800 Subject: [PATCH 9/9] new ternary snippet --- snippets/php.snippets | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/snippets/php.snippets b/snippets/php.snippets index d6d6bae..9ce93d4 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -25,7 +25,7 @@ snippet i { ${2} } -snippet $t +snippet t. $this->${1} snippet f function ${1:foo}(${2:array }${3:$bar}) @@ -62,6 +62,13 @@ snippet $s #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 @@ -253,9 +260,6 @@ snippet elseif elseif (${1:/* condition */}) { ${2:// code...} } -# Tertiary conditional -snippet t - $${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};${5} snippet switch switch ($${1:variable}) { case '${2:value}':