summaryrefslogtreecommitdiff
path: root/.config/vim/UltiSnips/php.snippets
blob: 8de1d1dbe571c8a3a1402b1d97953187dae2059c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
snippet ns "namespace declaration" b
namespace ${1:`!p
abspath = os.path.abspath(path)
m = re.search(r'([^/]+)/Classes/(.+(?=/))', abspath)
if m:
	snip.rv = 'Qbus\\' + \
		re.sub(r'(^|_)([a-zA-Z])', lambda m: m.group(2).upper(), m.group(1)) + \
		'\\' + m.group(2).replace('/', '\\')
else:
	m = re.search(r'[A-Z].+(?=/)', abspath)
	if m:
		snip.rv = m.group().replace('/', '\\')

`};
endsnippet


snippet class "Class declaration template" b
<?php
namespace ${1:`!p
abspath = os.path.abspath(path)
m = re.search(r'([^/]+)/Classes/(.+(?=/))', abspath)
if m:
	snip.rv = 'Qbus\\' + \
		re.sub(r'(^|_)([a-zA-Z])', lambda m: m.group(2).upper(), m.group(1)) + \
		'\\' + m.group(2).replace('/', '\\')
else:
	m = re.search(r'[A-Z].+(?=/)', abspath)
	if m:
		snip.rv = m.group().replace('/', '\\')

`};

/**
 * $1
 *
 * @author ${2:`!v g:snips_author`}
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
 */
class ${1:`!p snip.rv=snip.basename`}`!p
abspath = os.path.abspath(path)
if 'Classes/Controller/' in abspath:
	snip.rv = ' extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController'
elif 'Classes/Domain/Repository/' in abspath:
	snip.rv = ' extends \TYPO3\CMS\Extbase\Persistence\Repository'
elif 'Classes/Domain/Model/' in abspath:
	snip.rv = ' extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity'
elif 'Classes/ViewHelpers/' in abspath:
	snip.rv = ' extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper'
elif 'Classes/Command/' in abspath:
	snip.rv = ' extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController'
`
{
    ${VISUAL}${4}
}
endsnippet

snippet inject "inject a Class"
/**
 * @var ${1:\\Vendor\\Extension\\Namespace\\ClassName}
 */
protected $${2:${1/.*(^|\\)([^\\]+)$/\l$2/}};

/**
 * @param  $1 $$2
 * @return void
 */
public function inject${2/\w+\s*/\u$0/}($1 $$2)
{
    $this->$2 = $$2;
}
$0
endsnippet

snippet setter "PHP Class Setter" b
/**
 * Setter for $1
 *
 * @param ${2:string} $$1
 * @return void
 */
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)
{
    $this->$1 = $$1;$5
}
$0
endsnippet

snippet getobj "ObjectManager->get" b
/* @var \$$2 $1 */
\$${2:${1/.*(?:^|\\)([^\\]+)$/\l$1/}} = $this->objectManager->get(${1:\Vendor\Extension\ClassName}::class);
endsnippet

snippet inst "TYPO3 makeInstance" b
/* @var \$${3:$2} $1 */
\$${2:${1/.*(?:^|\\)([^\\]+)$/\l$1/}} = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(${1:\Vendor\Extension\ClassName}::class);
endsnippet

snippet dump "TYPO3 var_dump" b
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($1);
endsnippet

snippet dpb "debug_print_backtrace " b
debug_print_backtrace(${1:DEBUG_BACKTRACE_IGNORE_ARGS});
endsnippet

snippet action "Extbase Controller action" b
/**
 * action $1
 *
 * @return void
 */
public function ${1:index}Action(${2})
{
    ${VISUAL}${3}
}
$0
endsnippet

snippet ifqbus "ifqbus" b
if ($_SERVER['REMOTE_ADDR'] == '217.92.160.135') {
    ${1}
}
endsnippet

snippet exc "exc" b
throw new \\${2}Exception("$1", `!p
import time
snip.rv = int(time.time())
`);
endsnippet

snippet pl "configure TYPO3 Plugin" b
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'Qbus.' . $_EXTKEY,
    '${1:PluginName}',
    [
        '${2:ControllerName}' => '${3:list,show}',
    ],
    [
        '$2' => '${4}',
    ]
);
endsnippet

snippet pt "Add TYPO3 plugin in ext_tables.php" b
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
    $_EXTKEY,
    '${1:PluginName}',
    '${2:Description}'
);
endsnippet


snippet gs "PHP Class Getter Setter" b
/**
 * Getter for $1
 *
 * @return ${2:string}
 */
public function get${1/\w+\s*/\u$0/}()
{
    return $this->$1;$3
}

/**
 * Setter for $1
 *
 * @param  $2 $$1
 * @return ${4:`!p snip.rv=snip.basename`}
 */
public function set${1/\w+\s*/\u$0/}(${5:${2/(void|string|int|integer|double|float|object|boolean|bool|null|mixed|number|resource)|(.*)/(?1::$2 )/}}$$1)
{
    $this->$1 = $$1;$6

    ${7:return $this;}
}
$0
endsnippet