| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Illuminate\Foundation\Console;
|
|
|
4 |
|
|
|
5 |
use Illuminate\Console\Command;
|
|
|
6 |
use Illuminate\Filesystem\Filesystem;
|
| 150 |
lars |
7 |
use Illuminate\Foundation\Events\PublishingStubs;
|
| 148 |
lars |
8 |
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
9 |
|
|
|
10 |
#[AsCommand(name: 'stub:publish')]
|
|
|
11 |
class StubPublishCommand extends Command
|
|
|
12 |
{
|
|
|
13 |
/**
|
|
|
14 |
* The name and signature of the console command.
|
|
|
15 |
*
|
|
|
16 |
* @var string
|
|
|
17 |
*/
|
|
|
18 |
protected $signature = 'stub:publish
|
|
|
19 |
{--existing : Publish and overwrite only the files that have already been published}
|
|
|
20 |
{--force : Overwrite any existing files}';
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* The name of the console command.
|
|
|
24 |
*
|
|
|
25 |
* This name is used to identify the command during lazy loading.
|
|
|
26 |
*
|
|
|
27 |
* @var string|null
|
|
|
28 |
*
|
|
|
29 |
* @deprecated
|
|
|
30 |
*/
|
|
|
31 |
protected static $defaultName = 'stub:publish';
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* The console command description.
|
|
|
35 |
*
|
|
|
36 |
* @var string
|
|
|
37 |
*/
|
|
|
38 |
protected $description = 'Publish all stubs that are available for customization';
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Execute the console command.
|
|
|
42 |
*
|
|
|
43 |
* @return void
|
|
|
44 |
*/
|
|
|
45 |
public function handle()
|
|
|
46 |
{
|
|
|
47 |
if (! is_dir($stubsPath = $this->laravel->basePath('stubs'))) {
|
|
|
48 |
(new Filesystem)->makeDirectory($stubsPath);
|
|
|
49 |
}
|
|
|
50 |
|
| 150 |
lars |
51 |
$stubs = [
|
|
|
52 |
__DIR__.'/stubs/cast.inbound.stub' => 'cast.inbound.stub',
|
|
|
53 |
__DIR__.'/stubs/cast.stub' => 'cast.stub',
|
|
|
54 |
__DIR__.'/stubs/console.stub' => 'console.stub',
|
|
|
55 |
__DIR__.'/stubs/event.stub' => 'event.stub',
|
|
|
56 |
__DIR__.'/stubs/job.queued.stub' => 'job.queued.stub',
|
|
|
57 |
__DIR__.'/stubs/job.stub' => 'job.stub',
|
|
|
58 |
__DIR__.'/stubs/mail.stub' => 'mail.stub',
|
|
|
59 |
__DIR__.'/stubs/markdown-mail.stub' => 'markdown-mail.stub',
|
|
|
60 |
__DIR__.'/stubs/markdown-notification.stub' => 'markdown-notification.stub',
|
|
|
61 |
__DIR__.'/stubs/model.pivot.stub' => 'model.pivot.stub',
|
|
|
62 |
__DIR__.'/stubs/model.stub' => 'model.stub',
|
|
|
63 |
__DIR__.'/stubs/notification.stub' => 'notification.stub',
|
|
|
64 |
__DIR__.'/stubs/observer.plain.stub' => 'observer.plain.stub',
|
|
|
65 |
__DIR__.'/stubs/observer.stub' => 'observer.stub',
|
|
|
66 |
__DIR__.'/stubs/policy.plain.stub' => 'policy.plain.stub',
|
|
|
67 |
__DIR__.'/stubs/policy.stub' => 'policy.stub',
|
|
|
68 |
__DIR__.'/stubs/provider.stub' => 'provider.stub',
|
|
|
69 |
__DIR__.'/stubs/request.stub' => 'request.stub',
|
|
|
70 |
__DIR__.'/stubs/resource.stub' => 'resource.stub',
|
|
|
71 |
__DIR__.'/stubs/resource-collection.stub' => 'resource-collection.stub',
|
|
|
72 |
__DIR__.'/stubs/rule.stub' => 'rule.stub',
|
|
|
73 |
__DIR__.'/stubs/scope.stub' => 'scope.stub',
|
|
|
74 |
__DIR__.'/stubs/test.stub' => 'test.stub',
|
|
|
75 |
__DIR__.'/stubs/test.unit.stub' => 'test.unit.stub',
|
|
|
76 |
__DIR__.'/stubs/view-component.stub' => 'view-component.stub',
|
|
|
77 |
realpath(__DIR__.'/../../Database/Console/Factories/stubs/factory.stub') => 'factory.stub',
|
|
|
78 |
realpath(__DIR__.'/../../Database/Console/Seeds/stubs/seeder.stub') => 'seeder.stub',
|
|
|
79 |
realpath(__DIR__.'/../../Database/Migrations/stubs/migration.create.stub') => 'migration.create.stub',
|
|
|
80 |
realpath(__DIR__.'/../../Database/Migrations/stubs/migration.stub') => 'migration.stub',
|
|
|
81 |
realpath(__DIR__.'/../../Database/Migrations/stubs/migration.update.stub') => 'migration.update.stub',
|
|
|
82 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.api.stub') => 'controller.api.stub',
|
|
|
83 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.invokable.stub') => 'controller.invokable.stub',
|
|
|
84 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.model.api.stub') => 'controller.model.api.stub',
|
|
|
85 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.model.stub') => 'controller.model.stub',
|
|
|
86 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.nested.api.stub') => 'controller.nested.api.stub',
|
|
|
87 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.nested.singleton.api.stub') => 'controller.stub',
|
|
|
88 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.nested.singleton.stub') => 'controller.stub',
|
|
|
89 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.nested.stub') => 'controller.nested.stub',
|
|
|
90 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.plain.stub') => 'controller.plain.stub',
|
|
|
91 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.singleton.api.stub') => 'controller.stub',
|
|
|
92 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.singleton.stub') => 'controller.stub',
|
|
|
93 |
realpath(__DIR__.'/../../Routing/Console/stubs/controller.stub') => 'controller.stub',
|
|
|
94 |
realpath(__DIR__.'/../../Routing/Console/stubs/middleware.stub') => 'middleware.stub',
|
| 148 |
lars |
95 |
];
|
|
|
96 |
|
| 150 |
lars |
97 |
$this->laravel['events']->dispatch($event = new PublishingStubs($stubs));
|
|
|
98 |
|
|
|
99 |
foreach ($event->stubs as $from => $to) {
|
|
|
100 |
$to = $stubsPath.DIRECTORY_SEPARATOR.ltrim($to, DIRECTORY_SEPARATOR);
|
|
|
101 |
|
| 148 |
lars |
102 |
if ((! $this->option('existing') && (! file_exists($to) || $this->option('force')))
|
|
|
103 |
|| ($this->option('existing') && file_exists($to))) {
|
|
|
104 |
file_put_contents($to, file_get_contents($from));
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
$this->components->info('Stubs published successfully.');
|
|
|
109 |
}
|
|
|
110 |
}
|