diff --git a/UltiSnips/php.snippets b/UltiSnips/php.snippets index 7ba51c7..c7344a5 100644 --- a/UltiSnips/php.snippets +++ b/UltiSnips/php.snippets @@ -1,5 +1,14 @@ priority -50 +global !p +import vim + +# Set g:ultisnips_php_scalar_types to 1 if you'd like to enable PHP 7's scalar types for return values +def isPHPScalarTypesEnabled(): + isEnabled = vim.eval("get(g:, 'ultisnips_php_scalar_types', 0)") == "1" + return isEnabled or re.match('<\?php\s+declare\(strict_types=[01]\);', '\n'.join(vim.current.window.buffer)) +endglobal + ## Snippets from SnipMate, taken from ## https://github.com/scrooloose/snipmate-snippets.git @@ -9,7 +18,7 @@ snippet gm "PHP Class Getter" b * * @return ${2:string} */ -public function get${1/\w+\s*/\u$0/}() +public function get${1/\w+\s*/\u$0/}()`!p snip.rv = ': '+t[2] if isPHPScalarTypesEnabled() else ''` { return $this->$1; } @@ -36,7 +45,7 @@ snippet gs "PHP Class Getter Setter" b * * @return ${2:string} */ -public function get${1/\w+\s*/\u$0/}() +public function get${1/\w+\s*/\u$0/}()`!p snip.rv = ': '+t[2] if isPHPScalarTypesEnabled() else ''` { return $this->$1; } diff --git a/snippets/php.snippets b/snippets/php.snippets index 4faa167..0644859 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -2,6 +2,8 @@ snippet