File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace MicroPHP \Framework \Commands ;
6+
7+ use InvalidArgumentException ;
8+ use MicroPHP \Framework \Attribute \Attributes \CMD ;
9+ use MicroPHP \Framework \Config \Config ;
10+ use Symfony \Component \Console \Command \Command ;
11+ use Symfony \Component \Console \Input \InputArgument ;
12+ use Symfony \Component \Console \Input \InputInterface ;
13+ use Symfony \Component \Console \Output \OutputInterface ;
14+
15+ #[CMD ]
16+ class PublishConfigCommand extends Command
17+ {
18+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
19+ {
20+ $ name = $ input ->getArgument ('name ' );
21+ $ config = Config::get ('publish. ' . $ name );
22+ if (empty ($ config )) {
23+ throw new InvalidArgumentException ('config is not found: ' . $ name );
24+ }
25+ copy ($ config ['from ' ], $ config ['to ' ]);
26+ $ output ->writeln ('<info>Config is published at: ' . realpath ($ config ['to ' ]) . '</info> ' );
27+
28+ return Command::SUCCESS ;
29+ }
30+
31+ protected function configure (): void
32+ {
33+ $ this ->setName ('config:publish ' )->setDescription ('Publish the package config ' )
34+ ->addArgument ('name ' , InputArgument::REQUIRED , 'package config name ' );
35+ }
36+ }
Original file line number Diff line number Diff line change 44
55namespace MicroPHP \Framework ;
66
7+ use MicroPHP \Framework \Commands \PublishConfigCommand ;
78use MicroPHP \Framework \Commands \StartCommand ;
89use MicroPHP \Framework \Config \ConfigProviderInterface ;
910
@@ -14,6 +15,7 @@ public function config(): array
1415 return [
1516 'commands ' => [
1617 StartCommand::class,
18+ PublishConfigCommand::class,
1719 ],
1820 ];
1921 }
You can’t perform that action at this time.
0 commit comments