4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Helper;
14 use Symfony\Component\Console\Command\Command;
17 * HelperSet represents a set of helpers to be used with a command.
19 * @author Fabien Potencier <fabien@symfony.com>
29 * @param Helper[] $helpers An array of helper.
31 public function __construct(array $helpers = array())
33 $this->helpers = array();
34 foreach ($helpers as $alias => $helper) {
35 $this->set($helper, is_int($alias) ? null : $alias);
42 * @param HelperInterface $helper The helper instance
43 * @param string $alias An alias
45 public function set(HelperInterface $helper, $alias = null)
47 $this->helpers[$helper->getName()] = $helper;
48 if (null !== $alias) {
49 $this->helpers[$alias] = $helper;
52 $helper->setHelperSet($this);
56 * Returns true if the helper if defined.
58 * @param string $name The helper name
60 * @return Boolean true if the helper is defined, false otherwise
62 public function has($name)
64 return isset($this->helpers[$name]);
68 * Gets a helper value.
70 * @param string $name The helper name
72 * @return HelperInterface The helper instance
74 * @throws \InvalidArgumentException if the helper is not defined
76 public function get($name)
78 if (!$this->has($name)) {
79 throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
82 return $this->helpers[$name];
86 * Sets the command associated with this helper set.
88 * @param Command $command A Command instance
90 public function setCommand(Command $command = null)
92 $this->command = $command;
96 * Gets the command associated with this helper set.
98 * @return Command A Command instance
100 public function getCommand()
102 return $this->command;