1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ae\FeatureBundle\Command; |
4
|
|
|
|
5
|
|
|
use Ae\FeatureBundle\Entity\FeatureManager; |
6
|
|
|
use Doctrine\ORM\EntityManager; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Command used to create a feature. |
15
|
|
|
* |
16
|
|
|
* @author Emanuele Minotto <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class CreateFeatureCommand extends Command |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var FeatureManager |
22
|
|
|
*/ |
23
|
|
|
private $featureManager; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var EntityManager |
27
|
|
|
*/ |
28
|
|
|
private $entityManager; |
29
|
|
|
|
30
|
2 |
|
public function __construct( |
31
|
|
|
FeatureManager $featureManager, |
32
|
|
|
EntityManager $entityManager |
33
|
|
|
) { |
34
|
2 |
|
parent::__construct(); |
35
|
|
|
|
36
|
2 |
|
$this->featureManager = $featureManager; |
37
|
2 |
|
$this->entityManager = $entityManager; |
38
|
2 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
2 |
|
protected function configure() |
44
|
|
|
{ |
45
|
|
|
$this |
46
|
2 |
|
->setName('features:create') |
47
|
2 |
|
->setDescription('Create a new feature') |
48
|
2 |
|
->addArgument('parent', InputArgument::REQUIRED, 'Parent feature') |
49
|
2 |
|
->addArgument('name', InputArgument::REQUIRED, 'Feature name') |
50
|
2 |
|
->addOption( |
51
|
2 |
|
'enabled', |
52
|
2 |
|
null, |
53
|
2 |
|
InputOption::VALUE_NONE, |
54
|
2 |
|
'The feature will be created as enabled' |
55
|
|
|
) |
56
|
2 |
|
->addOption( |
57
|
2 |
|
'role', |
58
|
2 |
|
null, |
59
|
2 |
|
InputOption::VALUE_REQUIRED, |
60
|
2 |
|
'The feature will be only for a role' |
61
|
|
|
); |
62
|
2 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
2 |
|
public function execute(InputInterface $input, OutputInterface $output) |
68
|
|
|
{ |
69
|
2 |
|
$name = $input->getArgument('name'); |
70
|
2 |
|
$parent = $input->getArgument('parent'); |
71
|
|
|
|
72
|
2 |
|
$output->write(sprintf( |
73
|
2 |
|
'Creating <info>%s</info>.<info>%s</info>... ', |
74
|
2 |
|
$parent, |
|
|
|
|
75
|
2 |
|
$name |
76
|
|
|
)); |
77
|
|
|
|
78
|
2 |
|
$feature = $this->featureManager->findOrCreate($name, $parent); |
|
|
|
|
79
|
|
|
|
80
|
2 |
|
$feature->setEnabled($input->getOption('enabled')); |
81
|
2 |
|
$feature->setRole($input->getOption('role')); |
|
|
|
|
82
|
|
|
|
83
|
2 |
|
$this->entityManager->persist($feature); |
84
|
2 |
|
$this->entityManager->flush(); |
85
|
|
|
|
86
|
2 |
|
$this->featureManager->emptyCache($name, $parent); |
|
|
|
|
87
|
|
|
|
88
|
2 |
|
$output->writeln('OK'); |
89
|
|
|
|
90
|
2 |
|
return 0; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|