Created
June 21, 2021 20:58
-
-
Save kmuenkel/41e0b7fb39bd845b66605bea7d8c1a3a to your computer and use it in GitHub Desktop.
Artisan command for Composer packages
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
| #!/usr/bin/env php | |
| <?php | |
| use Illuminate\Config\Repository;use Illuminate\Encryption\Encrypter;define('LARAVEL_START', microtime(true)); | |
| /* | |
| |-------------------------------------------------------------------------- | |
| | Register The Auto Loader | |
| |-------------------------------------------------------------------------- | |
| | | |
| | Composer provides a convenient, automatically generated class loader | |
| | for our application. We just need to utilize it! We'll require it | |
| | into the script here so that we do not have to worry about the | |
| | loading of any our classes "manually". Feels great to relax. | |
| | | |
| */ | |
| require __DIR__.'/vendor/autoload.php'; | |
| $app = (new class { | |
| use \Orchestra\Testbench\Concerns\CreatesApplication; | |
| /** | |
| * @param $app | |
| */ | |
| protected function getEnvironmentSetUp($app) | |
| { | |
| // | |
| } | |
| /** | |
| * @return \Illuminate\Foundation\Application | |
| */ | |
| public function make(): \Illuminate\Foundation\Application | |
| { | |
| $app = $this->createApplication(); | |
| $this->generateAppKey($app); | |
| return $app; | |
| } | |
| /** | |
| * @param $app | |
| * @return string[] | |
| */ | |
| protected function getPackageProviders($app) | |
| { | |
| return [\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class]; | |
| } | |
| /** | |
| * @param \Illuminate\Foundation\Application $app | |
| */ | |
| protected function generateAppKey(\Illuminate\Foundation\Application $app) | |
| { | |
| /** @var Repository $config singleton */ | |
| $config = $app->make('config'); | |
| if ($key = !$config->get('app.key')) { | |
| $key = 'base64:' . base64_encode(Encrypter::generateKey($config->get('app.cipher'))); | |
| $config->set('app.key', $key); | |
| } | |
| } | |
| })->make(); | |
| /* | |
| |-------------------------------------------------------------------------- | |
| | Run The Artisan Application | |
| |-------------------------------------------------------------------------- | |
| | | |
| | When we run the console application, the current CLI command will be | |
| | executed in this console and the response sent back to a terminal | |
| | or another output device for the developers. Here goes nothing! | |
| | | |
| */ | |
| $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class); | |
| $status = $kernel->handle( | |
| $input = new Symfony\Component\Console\Input\ArgvInput, | |
| new Symfony\Component\Console\Output\ConsoleOutput | |
| ); | |
| /* | |
| |-------------------------------------------------------------------------- | |
| | Shutdown The Application | |
| |-------------------------------------------------------------------------- | |
| | | |
| | Once Artisan has finished running, we will fire off the shutdown events | |
| | so that any final work may be done by the application before we shut | |
| | down the process. This is the last thing to happen to the request. | |
| | | |
| */ | |
| $kernel->terminate($input, $status); | |
| exit($status); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment