1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\CoreBundle\Command; |
15
|
|
|
|
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
18
|
|
|
use Symfony\Component\Console\Command\Command; |
19
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Command that performs setup tasks for a given bundle implementing InitializableBundleInterface. |
26
|
|
|
*/ |
27
|
|
|
#[AsCommand(name: 'zikula:init-bundle', description: 'Performs setup tasks for a given initializable bundle.')] |
28
|
|
|
class InitBundleCommand extends Command |
29
|
|
|
{ |
30
|
|
|
public function __construct(private readonly KernelInterface $kernel) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function configure() |
36
|
|
|
{ |
37
|
|
|
$this |
38
|
|
|
->addArgument('bundle', InputArgument::REQUIRED, 'The bundle name') |
39
|
|
|
->setHelp( |
40
|
|
|
<<<'EOT' |
41
|
|
|
The <info>%command.name%</info> command performs setup tasks for a given bundle implementing <info>InitializableBundleInterface</info>. |
42
|
|
|
|
43
|
|
|
<info>php %command.full_name% AcmeFooBundle</info> |
44
|
|
|
|
45
|
|
|
EOT |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @throws InvalidArgumentException When the bundle is not an initializable bundle |
51
|
|
|
*/ |
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
53
|
|
|
{ |
54
|
|
|
$bundleName = $input->getArgument('bundle'); |
55
|
|
|
$bundle = $kernel->getBundle($bundleName); |
|
|
|
|
56
|
|
|
if (!($bundle instanceof InitializableBundleInterface)) { |
|
|
|
|
57
|
|
|
throw new InvalidArgumentException(sprintf('"%s" is not an initializable bundle.', $bundleName)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$bundle->getInitializer()->init(); |
61
|
|
|
|
62
|
|
|
return Command::SUCCESS; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|