Hello,
I’ve been studying the starterkit and also working my way through the YouTube videos from the beginning.
Overall, I’m really impressed with how well designed Kirby is! However, I am a bit bummed that static analysis and typing seems to be quite difficult.
The custom page models feature (with DefaultPage
) seems super powerful, and it is also much easier for an IDE to understand.
Have there been any discussions of doing something similar for snippets/slots, controllers, or collections?
For example, with snippets you can pass custom variables or slots and then use them inside the snippet! However, when you are calling a snippet, there is no immediate way for you or the IDE to know if you are passing variables to the snippet correctly . It seems like you would have to manually read the snippet code and decipher what it does, or keep a bunch of
/** @var */
annotations perfectly up do date and then reference those. Also, the code inside the snippet won’t have any type information, so writing what the snippet does is either up to you or again dependent on proper /** @var */
annotations.
My initial concept is that if snippets were class based, then rather than calling <?php snippet('note', ['note' => $note]) ?>
you would do something like <?php new NoteSnippet($note) ?>
. All of the parameters you need for that snippet could be defined and typed, and now your IDE can automatically find usages, refactor parameters, statically analyze types, navigate to definition, etc.
This is as far as I’ve gotten so far with this concept. But in short, the goal would be change how things work as little as possible but make it so IDEs can fully analyze all of the code as automatically as possible to enable automatic refactoring, typing, better code navigation, etc.
I know some work is going into better typing for v5. However, as far as I can tell those changes won’t do what I am thinking about here.
- Type hinting for collections by distantnative · Pull Request #6391 · getkirby/kirby · GitHub
- [v5] Support psalm templates for typing · Issue #2312 · getkirby/getkirby.com · GitHub
It also looks like people have had some similar ideas/discussions before:
- Kirby Ink - PHP Class-based Blueprints
- Getting better code completion in your editor with Kirby
- GitHub - lukaskleinschmidt/kirby-types: IDE Helper for Kirby
- Visual Studio Code Snippets for the Kirby Cheat Sheet
- GitHub - bnomei/kirby3-schema: JSON Schema file for Kirby CMS blueprints
I haven’t seen any discussions along these lines, so I wanted to put this out there to see (1) if others agree and (2) to see if the Kirby core team has any thoughts/insights. Has anything like this been discussed before? Is this something that could eventually live in core, or would this be too many breaking changes?