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 hidden or 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 hidden or 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" | |
| } | |
| } |
Author
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 templateHow to use
templates/home/hello-world.twigextendsslim4 skeleton Twig templatefrom autocomplete dropdownGenerated file should look like:
{% extends "layout/layout-empty.twig" %} {% block css %} {% webpack_entry_css 'home/hello-world' %} {% endblock %} {% block js %} {% webpack_entry_js 'home/hello-world' %} {% endblock %} {% block content %} <div class="container"> </div> {% endblock %}slim4 skeleton routeHow to use
$appor$groupinconfig/routes.phpslim4 skeleton routefrom autocomplete dropdownGenerated code should look like:
slim4 skeleton action classHow to use
src/Action/Home/HelloWordAction.php<?phpand add empty line so VSCode can understand that we want to call PHP related snippetclassslim4 skeleton action classfrom autocomplete dropdownGenerated file should look like: