summaryrefslogtreecommitdiff
path: root/.config/vim/UltiSnips/php.snippets
diff options
context:
space:
mode:
Diffstat (limited to '.config/vim/UltiSnips/php.snippets')
-rw-r--r--.config/vim/UltiSnips/php.snippets179
1 files changed, 179 insertions, 0 deletions
diff --git a/.config/vim/UltiSnips/php.snippets b/.config/vim/UltiSnips/php.snippets
new file mode 100644
index 0000000..8de1d1d
--- /dev/null
+++ b/.config/vim/UltiSnips/php.snippets
@@ -0,0 +1,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