-
-
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
Automatically generate helpers #842
Conversation
I think this pull request is complete from my side. Of course suggestions are welcomed. |
This competes with #797 |
After comparing the two solution my opinion is:
Now the other side of the coin:
The best of the two would be in my opinion:
I considered dropping the helper update part in favor of the post update section but it looks quite hacky to me. If the script runs in a non dev environment it fails with an error code to hide the error massage and make composer not fail one needs to use the following:
While this solves the problem I'm not sure that this command does anything usable under windows. @mfn and anyone else: Please share your thoughts about this. |
I didn't share this information yet but when I found the two PRs doing the same, my initial gut feeling was (and still is) from a technical approach I prefer this PR. But I also agree with your assessment regarding the config options 😄 However before putting more work into this, IMHO @barryvdh should voice his preference here (this PR, other PR or no PR) |
I'm the author of the other PR, and I agree with everything you've both said. The reason I decided to only update the affected models was that I was having a weird issue with git at the time. After running So yeah, that complicated workaround wasn't necessary after all. Just update everything on |
@mortenscheel thanks for your feedback! Would you then mind closing your PR in favour of this one? |
$this->generate('meta', $event->output); | ||
break; | ||
case "migrate": | ||
case "migrate:rollback": |
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.
Models should also be updated for "migrate:fresh," "migrate:refresh," and "migrate:reset" commands.
case "migrate:rollback": | |
case "migrate:fresh": | |
case "migrate:refresh": | |
case "migrate:reset": | |
case "migrate:rollback": |
*/ | ||
public function handle(CommandFinished $event) | ||
{ | ||
switch ($event->command) { |
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.
If a command fails, or has any of the --help
, --version
, or --pretend
flags, then "ide-helper" commands should not be run.
switch ($event->command) { | |
if ($this->eventIsInvalid($event)) { | |
return; | |
} | |
switch ($event->command) { |
See following comment for implementation of eventIsInvalid
method.
break; | ||
} | ||
} | ||
|
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.
/** | |
* @param \Illuminate\Console\Events\CommandFinished $event | |
* | |
* @return bool | |
*/ | |
protected function eventIsInvalid(CommandFinished $event): bool | |
{ | |
/* | |
* The event is invalid if any of the following are true: | |
* 1. exitCode is not zero (0); i.e., the command failed | |
* 2. input does not have a "command" argument; this happens when the | |
* -V/--version flag is used | |
* 3. input has "help" option (-h/--help) | |
* 4. input has "pretend" option (--pretend) | |
*/ | |
return $event->exitCode !== 0 || | |
!$event->input->hasArgument("command") || | |
$this->hasOption($event, "help") || | |
$this->hasOption($event, "pretend"); | |
} | |
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.
You have a point, this should be mostly solved by using MigrationsEnded event as a trigger as mentioned above, nut it can be definitely used on the package discover command, because as far as I know there is no PackageDiscovered event. Thanks for the suggestions.
Looking forward to having this feature added. Any progress? |
I'm still waiting response from the project maintainers about this pull request. |
:/ ping @barryvdh 🤗 |
I will try to make a pull request to the framework with a PackagesDiscovered event so we could use that. |
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.
@netpok be aware that this library supports 5.5 and your new event would only be in L7+ I guess
I'm also not 110% sure it's really worth to have this but
@barryvdh what's your take? See #842 (comment)
@@ -26,6 +26,9 @@ | |||
"scrutinizer/ocular": "~1.1", | |||
"squizlabs/php_codesniffer": "^3" | |||
}, | |||
"suggest": { | |||
"illuminate/events": "Required for automatic helper generation (^5.5|^6)." |
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.
This should also have |^7
in the meantime
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.
Time has passed:
^5.5
can be removed^7
and^8
added 😄
@@ -37,6 +39,10 @@ class IdeHelperServiceProvider extends ServiceProvider | |||
*/ | |||
public function boot() | |||
{ | |||
if ($this->app['config']->get('ide-helper.listen_on_commands')) { |
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.
the default for get()
(2nd parameter) should be false
for clarity sake
(it will work anyway because it's null
, but…)
I like the idea, but not sure if this is the best way. For Composer commands you can just add it to composer.json, but for migrations I see the benefit. I think it would be enough to just have a config option |
I side with @barryvdh last comment, this would combine the "established way" (composer) but allows a way into the migration (with the flexibility of providing how) |
I will update the PR for the changes, I found out that: |
Sorry, I forgot this, I will have some time this week to update this |
Is this PR dead? |
Sorry for not handling this, I'm closing it in favor of #1163 which is an updated version for this. |
This pull request allows automatic helper generation. This is achieved by listening on the command finished event of
migrate
,migrate:rollback
andpackage:discover
commands.I added this feature disabled by default, but it could be default on in the next major version.
Feel free to rename the config variable, this was my first idea.