laravel / tinker

Powerful REPL for the Laravel framework.
https://laravel.com/docs/artisan#tinker
MIT License
7.32k stars 130 forks source link

Add `--file` option #154

Closed innocenzi closed 1 year ago

innocenzi commented 1 year ago

This pull request adds support for a --file option that takes the code from the given file and executes it, similar to --execute.

My use case for this was setting up Code Runner and wanting to be able to run it in my Laravel application context, instead of just PHP. For this, the following configuration is required:

"code-runner.executorMap": {
  "php": "php artisan tinker --file"
},

CleanShot 2022-11-07 at 15 34 35

innocenzi commented 1 year ago

@huangdijia feel free to tell me what you think is wrong with this pull request 👍

EDIT: this comment was because the PR had a thumb down, but they removed it.

taylorotwell commented 1 year ago

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

innocenzi commented 1 year ago

I think having the ability to pass a file to Tinker has a useful potential, not only for my use case (which is pretty niche — my screenshot is also not the best example, since I could run the test directly, but I'd rather press F5 in my IDE to execute code than open Tinkerwell or a terminal).

I'll just use php artisan tinker --execute $(sed 's/<?php//g' <$fullFileName) then.