Last active
October 28, 2023 11:21
-
-
Save ybelenko/3b0b9d99404393dbd9bf1a474726c0b4 to your computer and use it in GitHub Desktop.
VSCode snippets for https://odan.github.io/slim4-skeleton/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and | |
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
// same ids are connected. | |
"slim4 skeleton Twig template": { | |
"prefix": "extends", | |
"body": [ | |
"{% extends \"layout/${1|layout-empty,layout|}.twig\" %}", | |
"", | |
"{% block css %}", | |
" {% webpack_entry_css '${TM_DIRECTORY/^.+\\/(.*)$/$1/}/$TM_FILENAME_BASE' %}", | |
"{% endblock %}", | |
"", | |
"{% block js %}", | |
" {% webpack_entry_js '${TM_DIRECTORY/^.+\\/(.*)$/$1/}/$TM_FILENAME_BASE' %}", | |
"{% endblock %}", | |
"", | |
"{% block content %}", | |
"", | |
" <div class=\"container\">", | |
" $0", | |
" </div>", | |
"", | |
"{% endblock %}", | |
"" | |
], | |
"description": "slim4 skeleton Twig template" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Place your snippets for php here. Each snippet is defined under a snippet name and has a prefix, body and | |
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
// same ids are connected. | |
"slim4 skeleton route": { | |
"prefix": [ | |
"$app->get", | |
"$group->get" | |
], | |
"body": [ | |
"// Route for /$1", | |
"\\$${2|app,group|}->${3|get,post,put,patch,delete|}('/$1', \\App\\Action\\\\$4::class)->setName('${1/[^A-z^0-9^-]/:downcase/g}');" | |
], | |
"description": "Route declaration for Slim4 skeleton" | |
}, | |
"slim4 skeleton action class": { | |
"prefix": "class", | |
"body": [ | |
"namespace App\\Action\\\\${TM_DIRECTORY/^.+\\/(.*)$/$1/};", | |
"", | |
"use App\\Responder\\Responder;", | |
"use Psr\\Http\\Message\\ResponseInterface;", | |
"use Psr\\Http\\Message\\ServerRequestInterface;", | |
"", | |
"/**", | |
" * Action.", | |
" */", | |
"final class $TM_FILENAME_BASE", | |
"{", | |
" /**", | |
" * @var Responder", | |
" */", | |
" private \\$responder;", | |
"", | |
" /**", | |
" * The constructor.", | |
" *", | |
" * @param Responder \\$responder The responder", | |
" */", | |
" public function __construct(Responder \\$responder)", | |
" {", | |
" \\$this->responder = \\$responder;", | |
" }", | |
"", | |
" /**", | |
" * Action.", | |
" *", | |
" * @param ServerRequestInterface \\$request The request", | |
" * @param ResponseInterface \\$response The response", | |
" *", | |
" * @return ResponseInterface The response", | |
" */", | |
" public function __invoke(ServerRequestInterface \\$request, ResponseInterface \\$response): ResponseInterface", | |
" {", | |
" return \\$this->responder->withTemplate(\\$response, '${TM_DIRECTORY/^.+\\/(.*)$/${1:/downcase}/}/$0.twig');", | |
" }", | |
"}", | |
"" | |
], | |
"description": "Slim4 skeleton action class" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
VSCode Snippets for odan/slim4-skeleton
If you're not familiar with VSCode snippets here is official doc:
Snippets in Visual Studio Code - Create your own snippets
slim4 skeleton Twig template
How to use
templates/home/hello-world.twig
extends
slim4 skeleton Twig template
from autocomplete dropdownGenerated file should look like:
slim4 skeleton route
How to use
$app
or$group
inconfig/routes.php
slim4 skeleton route
from autocomplete dropdownGenerated code should look like:
slim4 skeleton action class
How to use
src/Action/Home/HelloWordAction.php
<?php
and add empty line so VSCode can understand that we want to call PHP related snippetclass
slim4 skeleton action class
from autocomplete dropdownGenerated file should look like: