Skip to content

Commit a25a24f

Browse files
committed
add config publish command
1 parent c1c64c5 commit a25a24f

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

src/ConfigProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MicroPHP\Framework;
66

7+
use MicroPHP\Framework\Commands\PublishConfigCommand;
78
use MicroPHP\Framework\Commands\StartCommand;
89
use 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
}

0 commit comments

Comments
 (0)