├── LICENSE ├── README.md ├── UltiSnips ├── php.snippets ├── php_arrays.snippets ├── php_classes.snippets ├── php_enums.snippets ├── php_exceptions.snippets ├── php_interfaces.snippets ├── php_predefined_interfaces.snippets ├── php_properties_and_methods.snippets └── php_traits.snippets └── plugin └── sniphpets_common.vim /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Oleg Voronkovich 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sniphpets-common 2 | 3 | This repository contains common php snippets for Vim. 4 | 5 | ## Installation 6 | 7 | This plugin requires [Ultisnips](https://github.com/SirVer/ultisnips) and [sniphpets](https://github.com/sniphpets/sniphpets) 8 | 9 | ### Using [pathogen](https://github.com/tpope/vim-pathogen) 10 | 11 | ```sh 12 | git clone https://github.com/sniphpets/sniphpets-common.git ~/.vim/bundle/sniphpets-common 13 | ``` 14 | 15 | ### Using [vundle](https://github.com/gmarik/vundle) 16 | 17 | Add to your vimrc: 18 | 19 | ```vim 20 | Plugin 'sniphpets/sniphpets-common' 21 | ``` 22 | 23 | ## License 24 | 25 | Copyright (c) Voronkovich Oleg. Distributed under the MIT. 26 | -------------------------------------------------------------------------------- /UltiSnips/php.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet st "declare(strict_types=1)" b 4 | declare(strict_types=1); 5 | endsnippet 6 | 7 | snippet $ "Assign variable with docblock @var" b 8 | /** @var ${3:${1/^./\u$0/}} $$1 */ 9 | $${1} = ${2}; 10 | endsnippet 11 | 12 | snippet do "do while" 13 | do { 14 | ${VISUAL}${2} 15 | } while (${1}); 16 | endsnippet 17 | 18 | snippet if "if" 19 | if (${1}) { 20 | ${VISUAL}${2} 21 | } 22 | endsnippet 23 | 24 | snippet ifnull "if null" 25 | if (null === ${1}) { 26 | ${VISUAL}${2} 27 | } 28 | endsnippet 29 | 30 | snippet else "else" 31 | else { 32 | ${VISUAL}${1} 33 | } 34 | endsnippet 35 | 36 | snippet elif "elseif" 37 | elseif (${1}) { 38 | ${VISUAL}${2} 39 | } 40 | endsnippet 41 | 42 | snippet try "try/catch" b 43 | try { 44 | ${VISUAL}${0} 45 | } catch (${1:\Exception} $e) { 46 | } 47 | endsnippet 48 | 49 | snippet tryf "try/catch/finally" b 50 | try { 51 | ${VISUAL}${0} 52 | } catch (${1:\Exception} $e) { 53 | } finally { 54 | } 55 | endsnippet 56 | 57 | snippet "(^|[^\w])fn" "Arrow function" r 58 | `!p snip.rv = match.group(1)`fn(${1}) => ${2} 59 | endsnippet 60 | 61 | snippet match "match" 62 | match (${1}) { 63 | ${VISUAL}${0} 64 | }; 65 | endsnippet 66 | 67 | snippet use "use" b 68 | use `!v matchstr(sniphpets#fqn(), '\v^([^\\]+\\){1}')`${1}; 69 | endsnippet 70 | 71 | snippet use2 "use" b 72 | use `!v matchstr(sniphpets#fqn(), '\v^([^\\]+\\){2}')`${1}; 73 | endsnippet 74 | 75 | snippet use3 "use" b 76 | use `!v matchstr(sniphpets#fqn(), '\v^([^\\]+\\){3}')`${1}; 77 | endsnippet 78 | 79 | snippet use4 "use" b 80 | use `!v matchstr(sniphpets#fqn(), '\v^([^\\]+\\){4}')`${1}; 81 | endsnippet 82 | 83 | snippet use5 "use" b 84 | use `!v matchstr(sniphpets#fqn(), '\v^([^\\]+\\){5}')`${1}; 85 | endsnippet 86 | -------------------------------------------------------------------------------- /UltiSnips/php_arrays.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet list "list()" 4 | list($${1}, $${2}) 5 | endsnippet 6 | 7 | snippet list3 "list()" 8 | list($${1}, $${2}, $${3}) 9 | endsnippet 10 | 11 | snippet list4 "list()" 12 | list($${1}, $${2}, $${3}, $${4}) 13 | endsnippet 14 | 15 | snippet list5 "list()" 16 | list($${1}, $${2}, $${3}, $${4}, $${5}) 17 | endsnippet 18 | 19 | snippet amap "array_map" 20 | array_map(${1:function($item) { ${2} }}, ${3:$items})${0} 21 | endsnippet 22 | 23 | snippet areduce "array_reduce" 24 | array_reduce(${1:$items}${2:, function($carry, $item) { ${3} }${4:, ${5:$initial}}})${0} 25 | endsnippet 26 | 27 | snippet afilter "array_filter" 28 | array_filter(${1:$items}${2:, function($item) { ${3} }})${0} 29 | endsnippet 30 | -------------------------------------------------------------------------------- /UltiSnips/php_classes.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet "class(a|f)?" "Class" br 4 | ${1/^./\l$0/}; 31 | } 32 | endsnippet 33 | 34 | snippet set "Method / Setter" b 35 | public function set${1}(${2:$1 }$${1/^./\l$0/})${3:: void} 36 | { 37 | \$this->${1/^./\l$0/} = \$${1/^./\l$0/}; 38 | } 39 | endsnippet 40 | 41 | snippet getset "Method / Getter and setter" bm 42 | public function get$1()${3:: ${4:${2/\s//}}} 43 | { 44 | return \$this->${1/^./\l$0/}; 45 | } 46 | 47 | public function set${1}(${2:$1 }\$${1/^./\l$0/})${5:: void} 48 | { 49 | \$this->${1/^./\l$0/} = \$${1/^./\l$0/}; 50 | } 51 | endsnippet 52 | 53 | snippet "m(u|o|i)?(s)?" "Method" br 54 | `!p snip.rv = method_visibility(match.group(1))` `!p snip.rv = 'static ' if match.group(2) else ''`function ${1:methodName}(${2})${3:: ${4:string}} 55 | { 56 | ${VISUAL}${5} 57 | } 58 | endsnippet 59 | 60 | snippet "m(a|;)(u|o)?(s)?" "Abstract or empty method" br 61 | `!p snip.rv = 'abstract ' if match.group(1) == 'a' else ''``!p snip.rv = method_visibility(match.group(2))` `!p snip.rv = 'static ' if match.group(3) else ''`function ${1:methodName}(${2})${3:: ${4:string}}; 62 | endsnippet 63 | 64 | snippet clone "Magic method: __clone" b 65 | public function __clone() 66 | { 67 | ${VISUAL}${1} 68 | } 69 | endsnippet 70 | 71 | snippet sleep "Magic method: __sleep" b 72 | public function __sleep() 73 | { 74 | ${VISUAL}${1} 75 | } 76 | endsnippet 77 | 78 | snippet wakeup "Magic method: __wakeup" b 79 | public function __wakeup() 80 | { 81 | ${VISUAL}${1} 82 | } 83 | endsnippet 84 | 85 | snippet invoke "Magic method: __invoke" b 86 | public function __invoke(${1}) 87 | { 88 | ${VISUAL}${2} 89 | } 90 | endsnippet 91 | -------------------------------------------------------------------------------- /UltiSnips/php_traits.snippets: -------------------------------------------------------------------------------- 1 | priority -40 2 | 3 | snippet trait "Trait" b 4 | 10 | au FileType php inoremap ,t $this-> 11 | au FileType php inoremap ,r return ;i 12 | au FileType php inoremap ,< 13 | au FileType php inoremap ,> hhha 14 | au FileType php inoremap ;a A; 15 | endif 16 | --------------------------------------------------------------------------------