Merge pull request #745 from codeinabox/php-tidy
Consolidated PHP snippets and removed UltiSnips duplicates
This commit is contained in:
commit
49b72d0872
@ -3,114 +3,6 @@ priority -50
|
|||||||
## Snippets from SnipMate, taken from
|
## Snippets from SnipMate, taken from
|
||||||
## https://github.com/scrooloose/snipmate-snippets.git
|
## https://github.com/scrooloose/snipmate-snippets.git
|
||||||
|
|
||||||
snippet array "array"
|
|
||||||
$${1:arrayName} = array('${2}' => ${3});${4}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet def "def"
|
|
||||||
define('${1:VARIABLE_NAME}', ${2:'definition'});${3}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet wh "while"
|
|
||||||
while (${1}) {
|
|
||||||
${0:${VISUAL}}
|
|
||||||
}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet do "do"
|
|
||||||
do {
|
|
||||||
${2:// code... }
|
|
||||||
} while (${1:/* condition */});
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet doc_f "doc_f"
|
|
||||||
/**
|
|
||||||
* $2
|
|
||||||
* @return ${4:void}
|
|
||||||
* @author ${5:`!v g:snips_author`}
|
|
||||||
**/
|
|
||||||
${1:public }function ${2:someFunc}(${3})
|
|
||||||
{${6}
|
|
||||||
}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet doc_i "doc_i"
|
|
||||||
/**
|
|
||||||
* $1
|
|
||||||
* @package ${2:default}
|
|
||||||
* @author ${3:`!v g:snips_author`}
|
|
||||||
**/
|
|
||||||
interface ${1:someClass}
|
|
||||||
{${4}
|
|
||||||
} // END interface $1"
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet el "else"
|
|
||||||
else {
|
|
||||||
${0:${VISUAL}}
|
|
||||||
}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet for "for"
|
|
||||||
for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) {
|
|
||||||
${4:// code...}
|
|
||||||
}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet foreachk "foreachk"
|
|
||||||
foreach ($${1:variable} as $${2:key} => $${3:value}) {
|
|
||||||
${4:// code...}
|
|
||||||
}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet get "get"
|
|
||||||
$_GET['${1}']${2}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet if "if"
|
|
||||||
if (${1}) {
|
|
||||||
${0:${VISUAL}}
|
|
||||||
}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet eif "elseif"
|
|
||||||
elseif (${1}) {
|
|
||||||
${0:${VISUAL}}
|
|
||||||
}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet inc "inc"
|
|
||||||
include '${1:file}';${2}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet log "log"
|
|
||||||
error_log(var_export(${1}, true));${2}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet post "post"
|
|
||||||
$_POST['${1}']${2}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet req "req1"
|
|
||||||
require_once '${1:file}';${2}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet req1 "req1"
|
|
||||||
require_once '${1:file}';${2}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet session "session"
|
|
||||||
$_SESSION['${1}']${2}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet t "t"
|
|
||||||
$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};${5}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet var "var"
|
|
||||||
var_export(${1});${2}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet getter "PHP Class Getter" b
|
snippet getter "PHP Class Getter" b
|
||||||
/**
|
/**
|
||||||
* Getter for $1
|
* Getter for $1
|
||||||
@ -251,27 +143,11 @@ function ${1:name}(${2:$param})
|
|||||||
$0
|
$0
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet fore "Foreach loop"
|
|
||||||
foreach ($${1:variable} as $${3:value}) {
|
|
||||||
${VISUAL}${4}
|
|
||||||
}
|
|
||||||
$0
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet new "New class instance" b
|
snippet new "New class instance" b
|
||||||
$${1:variableName} = new ${2:${1/\w+\s*/\u$0/}}($3);
|
$${1:variableName} = new ${2:${1/\w+\s*/\u$0/}}($3);
|
||||||
$0
|
$0
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet ife "if else"
|
|
||||||
if (${1:/* condition */}) {
|
|
||||||
${2:// code...}
|
|
||||||
} else {
|
|
||||||
${3:// code...}
|
|
||||||
}
|
|
||||||
$0
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet ns "namespace declaration" b
|
snippet ns "namespace declaration" b
|
||||||
namespace ${1:`!p
|
namespace ${1:`!p
|
||||||
relpath = os.path.relpath(path)
|
relpath = os.path.relpath(path)
|
||||||
@ -349,20 +225,6 @@ public function __construct(${1:$dependencies})
|
|||||||
$0
|
$0
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet ve "Dumb debug helper in HTML"
|
|
||||||
echo '<pre>' . var_export($1, 1) . '</pre>';$0
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet pc "Dumb debug helper in cli"
|
|
||||||
var_export($1);$0
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
snippet inheritdoc "@inheritdoc docblock"
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
# PHPUnit snippets
|
# PHPUnit snippets
|
||||||
snippet testcase "class XYZTest extends \PHPUnit_Framework_TestCase { ... }"
|
snippet testcase "class XYZTest extends \PHPUnit_Framework_TestCase { ... }"
|
||||||
<?php
|
<?php
|
||||||
|
@ -24,9 +24,6 @@ snippet ?i
|
|||||||
snippet ns
|
snippet ns
|
||||||
namespace ${1:Foo\Bar\Baz};
|
namespace ${1:Foo\Bar\Baz};
|
||||||
${0}
|
${0}
|
||||||
snippet use
|
|
||||||
use ${1:Foo\Bar\Baz};
|
|
||||||
${0}
|
|
||||||
snippet c
|
snippet c
|
||||||
class ${1:`vim_snippets#Filename()`}
|
class ${1:`vim_snippets#Filename()`}
|
||||||
{
|
{
|
||||||
@ -81,13 +78,14 @@ snippet $s
|
|||||||
#getter
|
#getter
|
||||||
snippet $g
|
snippet $g
|
||||||
${1:$foo}->get${0:Bar}();
|
${1:$foo}->get${0:Bar}();
|
||||||
|
|
||||||
# Tertiary conditional
|
# Tertiary conditional
|
||||||
snippet =?:
|
snippet =?:
|
||||||
$${1:foo} = ${2:true} ? ${3:a} : ${0};
|
$${1:foo} = ${2:true} ? ${3:a} : ${0};
|
||||||
snippet ?:
|
snippet ?:
|
||||||
${1:true} ? ${2:a} : ${0}
|
${1:true} ? ${2:a} : ${0}
|
||||||
|
snippet t "$retVal = (condition) ? a : b"
|
||||||
|
$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};
|
||||||
|
# Predefined variables
|
||||||
snippet C
|
snippet C
|
||||||
$_COOKIE['${1:variable}']
|
$_COOKIE['${1:variable}']
|
||||||
snippet E
|
snippet E
|
||||||
@ -104,7 +102,12 @@ snippet S
|
|||||||
$_SERVER['${1:variable}']
|
$_SERVER['${1:variable}']
|
||||||
snippet SS
|
snippet SS
|
||||||
$_SESSION['${1:variable}']
|
$_SESSION['${1:variable}']
|
||||||
|
snippet get "get"
|
||||||
|
$_GET['${1}']
|
||||||
|
snippet post "post"
|
||||||
|
$_POST['${1}']
|
||||||
|
snippet session "session"
|
||||||
|
$_SESSION['${1}']
|
||||||
# the following are old ones
|
# the following are old ones
|
||||||
snippet inc
|
snippet inc
|
||||||
include '${1:file}';
|
include '${1:file}';
|
||||||
@ -205,7 +208,19 @@ snippet doc_h
|
|||||||
* @copyright ${4:$2}, `strftime('%d %B, %Y')`
|
* @copyright ${4:$2}, `strftime('%d %B, %Y')`
|
||||||
* @package ${0:default}
|
* @package ${0:default}
|
||||||
*/
|
*/
|
||||||
|
snippet doc_i "interface someClass {}"
|
||||||
|
/**
|
||||||
|
* $1
|
||||||
|
* @package ${2:default}
|
||||||
|
* @author ${3:`!v g:snips_author`}
|
||||||
|
**/
|
||||||
|
interface ${1:someClass}
|
||||||
|
{${4}
|
||||||
|
}
|
||||||
|
snippet inheritdoc "@inheritdoc docblock"
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
# Interface
|
# Interface
|
||||||
snippet interface
|
snippet interface
|
||||||
/**
|
/**
|
||||||
@ -254,55 +269,54 @@ snippet nc
|
|||||||
${0}
|
${0}
|
||||||
}
|
}
|
||||||
# define(...)
|
# define(...)
|
||||||
snippet def
|
snippet def "define('VARIABLE_NAME', 'definition')"
|
||||||
define('${1}'${2});
|
define('${1:VARIABLE_NAME}', ${2:'definition'});
|
||||||
# defined(...)
|
# defined(...)
|
||||||
snippet def?
|
snippet def?
|
||||||
${1}defined('${2}')
|
${1}defined('${2}')
|
||||||
snippet wh
|
snippet wh "while (condition) { ... }"
|
||||||
while (${1:/* condition */}) {
|
while (${1:/* condition */}) {
|
||||||
${0}
|
${0}
|
||||||
}
|
}
|
||||||
# do ... while
|
snippet do "do { ... } while (condition)"
|
||||||
snippet do
|
|
||||||
do {
|
do {
|
||||||
${0}
|
${0}
|
||||||
} while (${1:/* condition */});
|
} while (${1});
|
||||||
snippet if
|
snippet if "if (condition) { ... }"
|
||||||
if (${1:/* condition */}) {
|
if (${1}) {
|
||||||
${0}
|
${0}
|
||||||
}
|
}
|
||||||
snippet ifn
|
snippet ifn "if (!condition) { ... }"
|
||||||
if (!${1:/* condition */}) {
|
if (!${1}) {
|
||||||
${2}
|
${2}
|
||||||
}
|
}
|
||||||
snippet ifil
|
snippet ifil "<?php if (condition): ?> ... <?php endif; ?>"
|
||||||
<?php if (${1:/* condition */}): ?>
|
<?php if (${1}): ?>
|
||||||
${0}
|
${0}
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
snippet ife
|
snippet ife "if (cond) { ... } else { ... }"
|
||||||
if (${1:/* condition */}) {
|
if (${1}) {
|
||||||
${2}
|
${2}
|
||||||
} else {
|
} else {
|
||||||
${3}
|
${3}
|
||||||
}
|
}
|
||||||
${0}
|
${0}
|
||||||
snippet ifeil
|
snippet ifeil "<?php if (condition): ?> ... <?php else: ?> ... <?php endif; ?>"
|
||||||
<?php if (${1:/* condition */}): ?>
|
<?php if (${1}): ?>
|
||||||
${2:<!-- html... -->}
|
${2}
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
${3:<!-- html... -->}
|
${3}
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
${0}
|
${0}
|
||||||
snippet el
|
snippet el "else { ... }"
|
||||||
else {
|
else {
|
||||||
${0}
|
${0}
|
||||||
}
|
}
|
||||||
snippet eif
|
snippet eif "elseif(condition) { ... }"
|
||||||
elseif (${1}) {
|
elseif (${1}) {
|
||||||
${0}
|
${0}
|
||||||
}
|
}
|
||||||
snippet switch
|
snippet switch "switch($var) { case 'xyz': ... default: .... }"
|
||||||
switch ($${1:variable}) {
|
switch ($${1:variable}) {
|
||||||
case '${2:value}':
|
case '${2:value}':
|
||||||
${3}
|
${3}
|
||||||
@ -312,34 +326,33 @@ snippet switch
|
|||||||
${4}
|
${4}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snippet case
|
snippet case "case 'value': ... break"
|
||||||
case '${1:value}':
|
case '${1:value}':
|
||||||
${2}
|
${2}
|
||||||
break;
|
break;
|
||||||
snippet for
|
snippet for "for ($i = 0; $i < $count; $i++) { ... }"
|
||||||
for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) {
|
for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) {
|
||||||
${0}
|
${0}
|
||||||
}
|
}
|
||||||
snippet foreach
|
snippet foreach "foreach ($var as $value) { .. }"
|
||||||
foreach ($${1:variable} as $${2:value}) {
|
foreach ($${1:variable} as $${2:value}) {
|
||||||
${0}
|
${0}
|
||||||
}
|
}
|
||||||
snippet foreachil
|
snippet foreachil "<?php foreach ($var as $value): ?> ... <?php endforeach; ?>"
|
||||||
<?php foreach ($${1:variable} as $${2:value}): ?>
|
<?php foreach ($${1:variable} as $${2:value}): ?>
|
||||||
${0:<!-- html... -->}
|
${0}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
snippet foreachk
|
snippet foreachk "foreach ($var as $key => $value) { .. }"
|
||||||
foreach ($${1:variable} as $${2:key} => $${3:value}) {
|
foreach ($${1:variable} as $${2:key} => $${3:value}) {
|
||||||
${0}
|
${0}
|
||||||
}
|
}
|
||||||
snippet foreachkil
|
snippet foreachkil "<?php foreach ($var as $key => $value): ?> ... <?php endforeach; ?>"
|
||||||
<?php foreach ($${1:variable} as $${2:key} => $${3:value}): ?>
|
<?php foreach ($${1:variable} as $${2:key} => $${3:value}): ?>
|
||||||
${0:<!-- html... -->}
|
${0:<!-- html... -->}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
# $... = array (...)
|
snippet array "$... = array(...)"
|
||||||
snippet array b
|
|
||||||
$${1:arrayName} = array('${2}' => ${3});
|
$${1:arrayName} = array('${2}' => ${3});
|
||||||
snippet try
|
snippet try "try { ... } catch (Exception $e) { ... }"
|
||||||
try {
|
try {
|
||||||
${0}
|
${0}
|
||||||
} catch (${1:Exception} $e) {
|
} catch (${1:Exception} $e) {
|
||||||
@ -369,6 +382,14 @@ snippet http_redirect
|
|||||||
header ("HTTP/1.1 301 Moved Permanently");
|
header ("HTTP/1.1 301 Moved Permanently");
|
||||||
header ("Location: ".URL);
|
header ("Location: ".URL);
|
||||||
exit();
|
exit();
|
||||||
|
snippet log "error_log(var_export($var, true));"
|
||||||
|
error_log(var_export(${1}, true));
|
||||||
|
snippet var "var_export($var)"
|
||||||
|
var_export(${1});
|
||||||
|
snippet ve "Dumb debug helper in HTML"
|
||||||
|
echo '<pre>' . var_export(${1}, 1) . '</pre>';
|
||||||
|
snippet pc "Dumb debug helper in cli"
|
||||||
|
var_export($1);$0
|
||||||
# Getters & Setters
|
# Getters & Setters
|
||||||
snippet gs
|
snippet gs
|
||||||
/**
|
/**
|
||||||
@ -425,14 +446,12 @@ snippet aw
|
|||||||
array_walk($${1:foo}, function(&$${2:v}, $${3:k}) {
|
array_walk($${1:foo}, function(&$${2:v}, $${3:k}) {
|
||||||
$$2 = ${0};
|
$$2 = ${0};
|
||||||
});
|
});
|
||||||
|
|
||||||
# static var assign once
|
# static var assign once
|
||||||
snippet static_var
|
snippet static_var
|
||||||
static $${1} = null;
|
static $${1} = null;
|
||||||
if (is_null($$1)){
|
if (is_null($$1)){
|
||||||
$$1 = ${2};
|
$$1 = ${2};
|
||||||
}
|
}
|
||||||
|
|
||||||
snippet CSVWriter
|
snippet CSVWriter
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
@ -467,7 +486,6 @@ snippet CSVWriter
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snippet CSVIterator
|
snippet CSVIterator
|
||||||
|
|
||||||
// http://snipplr.com/view.php?codeview&id=1986 // modified
|
// http://snipplr.com/view.php?codeview&id=1986 // modified
|
||||||
@ -570,9 +588,6 @@ snippet CSVIterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // end class
|
} // end class
|
||||||
|
|
||||||
snippet is "isset()"
|
|
||||||
isset($1{VISUAL})
|
|
||||||
# phpunit
|
# phpunit
|
||||||
snippet ase "$this->assertEquals()"
|
snippet ase "$this->assertEquals()"
|
||||||
$this->assertEquals(${1:expected}, ${2:actual});
|
$this->assertEquals(${1:expected}, ${2:actual});
|
||||||
|
Loading…
Reference in New Issue
Block a user