Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| VendorPublishCommand | |
100.00% |
23 / 23 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| handle | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| promptForProviderOrTag | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| status | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| normalizePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Hyde\Console\Commands; |
| 6 | |
| 7 | use Hyde\Hyde; |
| 8 | use Illuminate\Foundation\Console\VendorPublishCommand as BaseCommand; |
| 9 | use Illuminate\Support\ServiceProvider; |
| 10 | use NunoMaduro\LaravelConsoleSummary\LaravelConsoleSummaryServiceProvider; |
| 11 | |
| 12 | use function ltrim; |
| 13 | use function realpath; |
| 14 | use function sprintf; |
| 15 | use function str_replace; |
| 16 | use function Laravel\Prompts\select; |
| 17 | |
| 18 | /** |
| 19 | * Publish any publishable assets from vendor packages. |
| 20 | */ |
| 21 | class VendorPublishCommand extends BaseCommand |
| 22 | { |
| 23 | /** |
| 24 | * Our child method filters the options available to the parent method. |
| 25 | */ |
| 26 | public function handle(): void |
| 27 | { |
| 28 | $originalPublishers = ServiceProvider::$publishes; |
| 29 | $originalGroups = ServiceProvider::$publishGroups; |
| 30 | |
| 31 | // This provider's publisher is not needed as it's covered by Laravel Zero |
| 32 | unset(ServiceProvider::$publishes[LaravelConsoleSummaryServiceProvider::class]); |
| 33 | |
| 34 | // Rename the config group to be more helpful |
| 35 | if (isset(ServiceProvider::$publishGroups['config'])) { |
| 36 | ServiceProvider::$publishGroups['vendor-configs'] = (array) ServiceProvider::$publishGroups['config']; |
| 37 | unset(ServiceProvider::$publishGroups['config']); |
| 38 | } |
| 39 | |
| 40 | parent::handle(); |
| 41 | |
| 42 | ServiceProvider::$publishes = $originalPublishers; |
| 43 | ServiceProvider::$publishGroups = $originalGroups; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Our child method only uses the select function, instead of the search one. |
| 48 | */ |
| 49 | protected function promptForProviderOrTag(): void |
| 50 | { |
| 51 | $choices = $this->publishableChoices(); |
| 52 | |
| 53 | $choice = select( |
| 54 | "Which provider or tag's files would you like to publish?", |
| 55 | $choices, |
| 56 | scroll: 15, |
| 57 | ); |
| 58 | |
| 59 | if ($choice == $choices[0]) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | $this->parseChoice($choice); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Write a status message to the console. |
| 68 | * |
| 69 | * @param string $from |
| 70 | * @param string $to |
| 71 | * @param string $type |
| 72 | */ |
| 73 | protected function status($from, $to, $type): void |
| 74 | { |
| 75 | $this->components->task(sprintf('Copying %s [%s] to [%s]', $type, |
| 76 | $this->normalizePath($from), |
| 77 | $this->normalizePath($to) |
| 78 | )); |
| 79 | } |
| 80 | |
| 81 | protected function normalizePath(string $path): string |
| 82 | { |
| 83 | return ltrim(str_replace('\\', '/', Hyde::pathToRelative(realpath($path))), '/\\'); |
| 84 | } |
| 85 | } |