-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c463820
commit 7c10d8a
Showing
8 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Ae\FeatureBundle\Command; | ||
|
||
use Ae\FeatureBundle\Entity\FeatureManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command used to create a feature. | ||
* | ||
* @author Emanuele Minotto <emanuele@adespresso.com> | ||
*/ | ||
class CreateFeatureCommand extends Command | ||
{ | ||
/** | ||
* @var FeatureManager | ||
*/ | ||
private $featureManager; | ||
|
||
/** | ||
* @var EntityManager | ||
*/ | ||
private $entityManager; | ||
|
||
/** | ||
* @param FeatureManager $featureManager | ||
* @param EntityManager $entityManager | ||
*/ | ||
public function __construct( | ||
FeatureManager $featureManager, | ||
EntityManager $entityManager | ||
) { | ||
parent::__construct(); | ||
|
||
$this->featureManager = $featureManager; | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('features:create') | ||
->setDescription('Create a new feature') | ||
->addArgument('parent', InputArgument::REQUIRED, 'Parent feature') | ||
->addArgument('name', InputArgument::REQUIRED, 'Feature name') | ||
->addOption( | ||
'enabled', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'The feature will be created as enabled' | ||
) | ||
->addOption( | ||
'role', | ||
null, | ||
InputOption::VALUE_REQUIRED, | ||
'The feature will be only for a role' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$name = $input->getArgument('name'); | ||
$parent = $input->getArgument('parent'); | ||
|
||
$output->write(sprintf( | ||
'Creating <info>%s</info>.<info>%s</info>... ', | ||
$parent, | ||
$name | ||
)); | ||
|
||
$feature = $this->featureManager->findOrCreate($name, $parent); | ||
|
||
$feature->setEnabled($input->getOption('enabled')); | ||
$feature->setRole($input->getOption('role')); | ||
|
||
$this->entityManager->persist($feature); | ||
$this->entityManager->flush(); | ||
|
||
$this->featureManager->emptyCache($name, $parent); | ||
|
||
$output->writeln('OK'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Ae\FeatureBundle\Command; | ||
|
||
use Ae\FeatureBundle\Entity\FeatureManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command used to disable an existing feature. | ||
* | ||
* @author Emanuele Minotto <emanuele@adespresso.com> | ||
*/ | ||
class DisableFeatureCommand extends Command | ||
{ | ||
/** | ||
* @var FeatureManager | ||
*/ | ||
private $featureManager; | ||
|
||
/** | ||
* @var EntityManager | ||
*/ | ||
private $entityManager; | ||
|
||
/** | ||
* @param FeatureManager $featureManager | ||
* @param EntityManager $entityManager | ||
*/ | ||
public function __construct( | ||
FeatureManager $featureManager, | ||
EntityManager $entityManager | ||
) { | ||
parent::__construct(); | ||
|
||
$this->featureManager = $featureManager; | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('features:disable') | ||
->setDescription('Disable an existing feature') | ||
->addArgument('parent', InputArgument::REQUIRED, 'Parent feature') | ||
->addArgument('name', InputArgument::REQUIRED, 'Feature name'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$name = $input->getArgument('name'); | ||
$parent = $input->getArgument('parent'); | ||
|
||
$output->write(sprintf( | ||
'Disabling <info>%s</info>.<info>%s</info>... ', | ||
$parent, | ||
$name | ||
)); | ||
|
||
$feature = $this->featureManager->find($name, $parent); | ||
|
||
$feature->setEnabled(false); | ||
|
||
$this->entityManager->persist($feature); | ||
$this->entityManager->flush(); | ||
|
||
$this->featureManager->emptyCache($name, $parent); | ||
|
||
$output->writeln('OK'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Ae\FeatureBundle\Command; | ||
|
||
use Ae\FeatureBundle\Entity\FeatureManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command used to enable an existing feature. | ||
* | ||
* @author Emanuele Minotto <emanuele@adespresso.com> | ||
*/ | ||
class EnableFeatureCommand extends Command | ||
{ | ||
/** | ||
* @var FeatureManager | ||
*/ | ||
private $featureManager; | ||
|
||
/** | ||
* @var EntityManager | ||
*/ | ||
private $entityManager; | ||
|
||
/** | ||
* @param FeatureManager $featureManager | ||
* @param EntityManager $entityManager | ||
*/ | ||
public function __construct( | ||
FeatureManager $featureManager, | ||
EntityManager $entityManager | ||
) { | ||
parent::__construct(); | ||
|
||
$this->featureManager = $featureManager; | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('features:enable') | ||
->setDescription('Enable an existing feature') | ||
->addArgument('parent', InputArgument::REQUIRED, 'Parent feature') | ||
->addArgument('name', InputArgument::REQUIRED, 'Feature name') | ||
->addOption( | ||
'role', | ||
null, | ||
InputOption::VALUE_REQUIRED, | ||
'The feature will be only for a role' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$name = $input->getArgument('name'); | ||
$parent = $input->getArgument('parent'); | ||
|
||
$output->write(sprintf( | ||
'Enabling <info>%s</info>.<info>%s</info>... ', | ||
$parent, | ||
$name | ||
)); | ||
|
||
$feature = $this->featureManager->find($name, $parent); | ||
|
||
$feature->setEnabled(true); | ||
|
||
if (null !== $input->getOption('role')) { | ||
$feature->setRole($input->getOption('role')); | ||
} | ||
|
||
$this->entityManager->persist($feature); | ||
$this->entityManager->flush(); | ||
|
||
$this->featureManager->emptyCache($name, $parent); | ||
|
||
$output->writeln('OK'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.