Completed
Push — master ( 3a90ba...c1951e )
by Filip
02:11
created

OrmDelegateCommand::createCommand()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1
nc 1
1
<?php
2
3
/**
4
 * This file is part of the Kdyby (http://www.kdyby.org)
5
 *
6
 * Copyright (c) 2008 Filip Procházka ([email protected])
7
 *
8
 * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
9
 */
10
11
namespace Kdyby\Doctrine\Console;
12
13
use Symfony\Component\Console\Command\Command;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Command Delegate.
20
 *
21
 * @author Fabio B. Silva <[email protected]>
22
 * @author Filip Procházka <[email protected]>
23
 */
24
abstract class OrmDelegateCommand extends Command
25
{
26
	/**
27
	 * @var \Symfony\Component\Console\Command\Command
28
	 */
29
	protected $command;
30
31
	/**
32
	 * @return \Symfony\Component\Console\Command\Command
33
	 */
34
	abstract protected function createCommand();
35
36
	/**
37
	 * @param string $entityManagerName
38
	 * @return \Symfony\Component\Console\Command\Command
39
	 */
40
	protected function wrapCommand($entityManagerName)
41
	{
42
		CommandHelper::setApplicationEntityManager($this->getHelper('container'), $entityManagerName);
43
		$this->command->setApplication($this->getApplication());
44
		return $this->command;
45
	}
46
47
	/**
48
	 * {@inheritDoc}
49
	 */
50
	protected function configure()
51
	{
52
		$this->command = $this->createCommand();
53
54
		$this->setName($this->command->getName());
55
		$this->setHelp($this->command->getHelp());
56
		$this->setDefinition($this->command->getDefinition());
57
		$this->setDescription($this->command->getDescription());
58
59
		$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
60
	}
61
62
	/**
63
	 * {@inheritDoc}
64
	 */
65
	protected function execute(InputInterface $input, OutputInterface $output)
66
	{
67
		return $this->wrapCommand($input->getOption('em'))->execute($input, $output);
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	protected function interact(InputInterface $input, OutputInterface $output)
74
	{
75
		$this->wrapCommand($input->getOption('em'))->interact($input, $output);
76
	}
77
78
	/**
79
	 * {@inheritDoc}
80
	 */
81
	protected function initialize(InputInterface $input, OutputInterface $output)
82
	{
83
		$this->wrapCommand($input->getOption('em'))->initialize($input, $output);
84
	}
85
}
86