-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor console commands to delegates
- Loading branch information
1 parent
b6944c3
commit 5ce1e1b
Showing
15 changed files
with
364 additions
and
377 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,85 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Kdyby (http://www.kdyby.org) | ||
* | ||
* Copyright (c) 2008 Filip Procházka ([email protected]) | ||
* | ||
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kdyby\Doctrine\Console; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command Delegate. | ||
* | ||
* @author Fabio B. Silva <[email protected]> | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
abstract class DbalDelegateCommand extends Command | ||
{ | ||
/** | ||
* @var \Symfony\Component\Console\Command\Command | ||
*/ | ||
protected $command; | ||
|
||
/** | ||
* @return \Symfony\Component\Console\Command\Command | ||
*/ | ||
abstract protected function createCommand(); | ||
|
||
/** | ||
* @param string $connectionName | ||
* @return \Symfony\Component\Console\Command\Command | ||
*/ | ||
protected function wrapCommand($connectionName) | ||
{ | ||
CommandHelper::setApplicationConnection($this->getHelper('container'), $connectionName); | ||
$this->command->setApplication($this->getApplication()); | ||
return $this->command; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->command = $this->createCommand(); | ||
|
||
$this->setName($this->command->getName()); | ||
$this->setHelp($this->command->getHelp()); | ||
$this->setDefinition($this->command->getDefinition()); | ||
$this->setDescription($this->command->getDescription()); | ||
|
||
$this->addOption('connection', NULL, InputOption::VALUE_OPTIONAL, 'The connection to use for this command'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
return $this->wrapCommand($input->getOption('connection'))->execute($input, $output); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->wrapCommand($input->getOption('connection'))->interact($input, $output); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->wrapCommand($input->getOption('connection'))->initialize($input, $output); | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Kdyby (http://www.kdyby.org) | ||
* | ||
* Copyright (c) 2008 Filip Procházka ([email protected]) | ||
* | ||
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kdyby\Doctrine\Console; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command Delegate. | ||
* | ||
* @author Fabio B. Silva <[email protected]> | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
abstract class OrmDelegateCommand extends Command | ||
{ | ||
/** | ||
* @var \Symfony\Component\Console\Command\Command | ||
*/ | ||
protected $command; | ||
|
||
/** | ||
* @return \Symfony\Component\Console\Command\Command | ||
*/ | ||
abstract protected function createCommand(); | ||
|
||
/** | ||
* @param string $entityManagerName | ||
* @return \Symfony\Component\Console\Command\Command | ||
*/ | ||
protected function wrapCommand($entityManagerName) | ||
{ | ||
CommandHelper::setApplicationEntityManager($this->getHelper('container'), $entityManagerName); | ||
$this->command->setApplication($this->getApplication()); | ||
return $this->command; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->command = $this->createCommand(); | ||
|
||
$this->setName($this->command->getName()); | ||
$this->setHelp($this->command->getHelp()); | ||
$this->setDefinition($this->command->getDefinition()); | ||
$this->setDescription($this->command->getDescription()); | ||
|
||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
return $this->wrapCommand($input->getOption('em'))->execute($input, $output); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->wrapCommand($input->getOption('em'))->interact($input, $output); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->wrapCommand($input->getOption('em'))->initialize($input, $output); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,19 +8,16 @@ | |
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kdyby\Doctrine\Console; | ||
namespace Kdyby\Doctrine\Console\Proxy; | ||
|
||
use Doctrine; | ||
use Kdyby\Doctrine\Console\OrmDelegateCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
|
||
|
||
/** | ||
* @author Tomas Jacik <[email protected]> | ||
*/ | ||
class ConvertMappingCommand extends Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand | ||
class ConvertMappingCommand extends OrmDelegateCommand | ||
{ | ||
|
||
/** | ||
|
@@ -29,35 +26,21 @@ class ConvertMappingCommand extends Doctrine\ORM\Tools\Console\Command\ConvertMa | |
*/ | ||
public $cacheCleaner; | ||
|
||
|
||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this->addOption('em', NULL, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); | ||
} | ||
|
||
|
||
|
||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
parent::initialize($input, $output); | ||
|
||
if ($input->getOption('em')) { | ||
CommandHelper::setApplicationEntityManager($this->getHelper('container'), $input->getOption('em')); | ||
} | ||
|
||
$this->cacheCleaner->invalidate(); | ||
} | ||
|
||
protected function createCommand() | ||
{ | ||
return new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -8,19 +8,16 @@ | |
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kdyby\Doctrine\Console; | ||
namespace Kdyby\Doctrine\Console\Proxy; | ||
|
||
use Doctrine; | ||
use Kdyby\Doctrine\Console\OrmDelegateCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
|
||
|
||
/** | ||
* @author Tomas Jacik <[email protected]> | ||
*/ | ||
class GenerateEntitiesCommand extends Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand | ||
class GenerateEntitiesCommand extends OrmDelegateCommand | ||
{ | ||
|
||
/** | ||
|
@@ -29,38 +26,21 @@ class GenerateEntitiesCommand extends Doctrine\ORM\Tools\Console\Command\Generat | |
*/ | ||
public $cacheCleaner; | ||
|
||
|
||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this->addOption('em', NULL, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); | ||
} | ||
|
||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
parent::initialize($input, $output); | ||
|
||
if ($input->getOption('em')) { | ||
CommandHelper::setApplicationEntityManager($this->getHelper('container'), $input->getOption('em')); | ||
} | ||
|
||
$this->cacheCleaner->invalidate(); | ||
} | ||
|
||
protected function createCommand() | ||
{ | ||
return new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -8,19 +8,16 @@ | |
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kdyby\Doctrine\Console; | ||
namespace Kdyby\Doctrine\Console\Proxy; | ||
|
||
use Doctrine; | ||
use Kdyby\Doctrine\Console\OrmDelegateCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
|
||
|
||
/** | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
class GenerateProxiesCommand extends Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand | ||
class GenerateProxiesCommand extends OrmDelegateCommand | ||
{ | ||
|
||
/** | ||
|
@@ -29,38 +26,21 @@ class GenerateProxiesCommand extends Doctrine\ORM\Tools\Console\Command\Generate | |
*/ | ||
public $cacheCleaner; | ||
|
||
|
||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this->addOption('em', NULL, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); | ||
} | ||
|
||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
parent::initialize($input, $output); | ||
|
||
if ($input->getOption('em')) { | ||
CommandHelper::setApplicationEntityManager($this->getHelper('container'), $input->getOption('em')); | ||
} | ||
|
||
$this->cacheCleaner->invalidate(); | ||
} | ||
|
||
protected function createCommand() | ||
{ | ||
return new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(); | ||
} | ||
|
||
} |
Oops, something went wrong.