Last active
April 13, 2018 04:09
-
-
Save ahuggins/d2d3997628df6f89285bf40dae0f819f to your computer and use it in GitHub Desktop.
`artisan make:?` command would auto-open new file (Controller/Model/etc) in editor.
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
| <?php | |
| namespace App\Events; | |
| class ClassWasGenerated | |
| { | |
| public $path; | |
| public function __construct($path) | |
| { | |
| $this->path = $path; | |
| } | |
| } |
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
| <?php | |
| namespace App\Providers; | |
| use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; | |
| class EventServiceProvider extends ServiceProvider | |
| { | |
| protected $listen = [ | |
| // truncated for brevity | |
| // Connect the listener to the event. | |
| 'App\Events\ClassWasGenerated' => [ | |
| 'App\Listeners\OpenInSublime', | |
| ], | |
| ]; | |
| // truncated for brevity | |
| } |
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
| <?php | |
| namespace Illuminate\Console; | |
| use Illuminate\Support\Str; | |
| use App\Events\ClassWasGenerated; | |
| use Illuminate\Filesystem\Filesystem; | |
| use Symfony\Component\Console\Input\InputArgument; | |
| abstract class GeneratorCommand extends Command | |
| { | |
| // removed because not important to point of Gist | |
| public function handle() | |
| { | |
| // removed because not important to point of Gist | |
| $this->files->put($path, $this->buildClass($name)); | |
| // only new line of code in this class (as well as "use") | |
| event(new ClassWasGenerated($path)); | |
| // removed because not important to point of Gist | |
| } |
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
| <?php | |
| namespace App\Listeners; | |
| use Illuminate\Queue\InteractsWithQueue; | |
| use Illuminate\Contracts\Queue\ShouldQueue; | |
| class OpenInSublime | |
| { | |
| public function handle($event) | |
| { | |
| // might be `subl` for some people. But this class would be entirely opt-in and fully customizable. | |
| exec('sublime -a ' . $event->path); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment