1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - 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\Bundle\CoreBundle\Maker; |
15
|
|
|
|
16
|
|
|
use Symfony\Bundle\MakerBundle\ConsoleStyle; |
17
|
|
|
use Symfony\Bundle\MakerBundle\DependencyBuilder; |
18
|
|
|
use Symfony\Bundle\MakerBundle\Generator; |
19
|
|
|
use Symfony\Bundle\MakerBundle\InputConfiguration; |
20
|
|
|
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker; |
21
|
|
|
use Symfony\Component\Console\Command\Command; |
22
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
23
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
24
|
|
|
use Zikula\Bundle\CoreBundle\DynamicConfigDumper; |
25
|
|
|
|
26
|
|
|
class SetNamespaceMaker extends AbstractMaker |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var DynamicConfigDumper |
30
|
|
|
*/ |
31
|
|
|
private $configDumper; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
DynamicConfigDumper $configDumper |
35
|
|
|
) { |
36
|
|
|
$this->configDumper = $configDumper; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public static function getCommandName(): string |
40
|
|
|
{ |
41
|
|
|
return 'make:set-namespace'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function configureCommand(Command $command, InputConfiguration $inputConfig) |
45
|
|
|
{ |
46
|
|
|
$command |
47
|
|
|
->setDescription('Sets the maker namespace config') |
48
|
|
|
->addArgument('namespace', InputArgument::OPTIONAL, 'Choose a namespace (e.g. <fg=yellow>Acme\\BlogModule</>)') |
49
|
|
|
->setHelp('Set the maker namespace config <info>php %command.full_name% Acme/BlogModule</info>') |
50
|
|
|
; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) |
54
|
|
|
{ |
55
|
|
|
try { |
56
|
|
|
$namespace = Validators::validateBundleNamespace($input->getArgument('namespace'), true); |
|
|
|
|
57
|
|
|
} catch (\InvalidArgumentException $exception) { |
58
|
|
|
$io->error($exception->getMessage()); |
59
|
|
|
|
60
|
|
|
return 1; |
61
|
|
|
} |
62
|
|
|
$this->configDumper->setConfiguration( |
63
|
|
|
'maker', |
64
|
|
|
[ |
65
|
|
|
'root_namespace' => $namespace, |
66
|
|
|
], |
67
|
|
|
true |
68
|
|
|
); |
69
|
|
|
$io->success(sprintf('The `config/generated_dev.yaml` file has been updated to set `maker:root_namespace` value to %s.', $namespace)); |
70
|
|
|
|
71
|
|
|
return 0; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function configureDependencies(DependencyBuilder $dependencies) |
75
|
|
|
{ |
76
|
|
|
$dependencies->addClassDependency( |
77
|
|
|
Command::class, |
78
|
|
|
'console' |
79
|
|
|
); |
80
|
|
|
$dependencies->addClassDependency( |
81
|
|
|
DynamicConfigDumper::class, |
82
|
|
|
'zikula/core-bundle' |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|