-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model hooks #945
Model hooks #945
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel angsty opening up ModelsCommand
suddenly being so public
because it's so much spaghetti in there, but I like how non-obtrusive your approach is so I wouldn't see a reason why not.
Pretty great PR IMHO!
ac9704f
to
c536db6
Compare
Context: While working on https://github.com/psalm/psalm-plugin-laravel, I've desired the ability to "change the template that gets rendered" (akin to #942). I understand that would require a lot of refactoring, so I haven't gotten around to do it yet. Feedback: The verbiage Sidenote Do we consider the API of |
@mfn this PR doesn't add functionality to the IDE helper. It only opens up some of the existing functionality so you can add information from sources the IDE helper doesn't know about on its own. So this could solve #930 if there is already functionality in the IDE helper to write/define custom tags (which I didn't look into). If not, then this PR won't help with that. |
I thought about this again…
It matches my sentiment from #945 (review)
But currently it's a catch-22. No one came forward with a clear plan to clean this up and I can imagine such a refactoring could be quite intrusive. For example what I described in #756 is kind of critical to my current use of ide-helper (I do use ide-helper within a real Laravel project but also in one were individual components are used) and I had to jump through quite hacky hoops to get it working. Was like 80% duck typing and 20% relying on extending code.
That's kinda a point also, because I can surely come forward with a nice PR I feel is the "clean code of 2020" but what problem would it solve? Enabling things not possible before should be part of that vision. Although the PR is quite unobtrusive technically, it could open can of worms in the current state hard to close, once the hooks "catch on". I'd err on the side of @mr-feek and question if it's the right to go ahead of this. Apologies for all the meta babbling… |
What's the status on this? Would really appreciate this change. |
The technical implementation here I think is nice and unobtrusive, except for the fact it opens up everything But the more I think about the implications, the more I'm worried. I think the high level idea is great (providing a way of extending / intercepting ide-helpers functionality). But as I already mentioned, there are so many smaller issues with the code base and then guaranteeing them all as part of the model hooks to work that way what previously was rather "internal details" worries me the most. Alone the fact we've passing a full Symfony Command into the hook and thus making it the primary point of contract IMHO feels absolutely wrong: interface ModelHookInterface
{
public function run(ModelsCommand $command, Model $model): void;
} I'm aware not every project on earth must fulfill the "clean architecture 2020 guidelines", let's be realistic. But open things up that way right now can cause a lot of issues for users of hooks when we want to improve / refactor the code base. That's why accepting the whole I think more water should flow down the river first before agreeing on an implementation for such a topic. @barryvdh how do you feel about this? |
@barryvdh there was a similar PR opened recently which achieves the same as this one -> #1157 I gave technical arguments in the other PR why I prefer this would but seems we lost track of it, my last comment went unanswered :) My TL;DR: If you are fine with opening the ide-helper for this, I'm fine too (and ppl really want to have this feature…) |
f45b1d4
to
7aa4a45
Compare
@mfn I've rebased and fixed my branch and added an entry in the change log, so it's ready to go if you are 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do it, 👍 from my side
Rolling over the ⚽ to @barryvdh 😏
Would love to use this 👍 |
@barryvdh would you be fine with this hook? |
This MR looks great to me :) |
7249004
to
4d4a9e2
Compare
FYI @wimski @barryvdh This was a breaking change for |
@barryvdh I guess it should've been released under Maybe remove the following from the [Next release](https://github.com/barryvdh/laravel-ide-helper/compare/vX.X.X...master) You won't know the version number until you're ready to do a release, because it depends on the changes since the last release. |
@caugner thanks for bringing this to attention!
This line is fine IMHO, it always shows the diff from the last release to current master (it was Breaking changes: unfortunate, I guess. No one thought about that. I mean, hardly anyone would assume the use ide-helper as an actual library though it's of course a valid use case. In this case it's slightly different. Or actually not. We probably shouldn't roll back now, likely not worth it? And going forward, being more concise about this. Personally I don't have a problem pumping out more major versions in case we see a break somewhere, I'm not attached to version numbers or how they look. |
Next breaking change incoming, see https://github.com/barryvdh/laravel-ide-helper/pull/1198/files#r606697817 |
I think it's a bit of an edge case and indeed not the intended/expected usage. But we could agree to bump minor versions for this, so plugins can specify minor versions. |
I'm not sure how other comparable projects handle this, but one could argue that Since specifying minor versions is rather unusual (afaik, as only major versions are expected to contain breaking changes) What would be reasons against a major version bump (and reverting the change in PS: |
That all end-users need to upgrade their dependencies. |
Making a public class method visibility change in a minor version will still have the potential to leave lots of users in a broken state. We released versions of The only real, backwards compatible solution here is to make a hotfix release reverting the changes, and then re-releasing the breaking changes in a major version. IMO "model hooks" brings a ton of new functionality and increases the public interface of this package which in itself could warrant a major version upgrade. That being said, I understand 100% that it was not expected for this class to be used outside the codebase. But we did because it brought great functionality to statically analyzing laravel projects and it wasn't marked as final 😄 My push is for a major version change, but I understand the rationale of being a bit reluctant to do so. |
In the last couple of Laravel projects I did, I needed extra IDE help for models (translated properties, attachments, etc.). There currently is no way to generate custom information so I wrote a model hook system. Everyone can then easily extend the generation of model information. In order to make it actually useful, I changed some methods in the models command from protected to public.