TYPO3  7.6
HelperSet.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Helper;
13 
15 
21 class HelperSet implements \IteratorAggregate
22 {
23  private $helpers = array();
24  private $command;
25 
31  public function __construct(array $helpers = array())
32  {
33  foreach ($helpers as $alias => $helper) {
34  $this->set($helper, is_int($alias) ? null : $alias);
35  }
36  }
37 
44  public function set(HelperInterface $helper, $alias = null)
45  {
46  $this->helpers[$helper->getName()] = $helper;
47  if (null !== $alias) {
48  $this->helpers[$alias] = $helper;
49  }
50 
51  $helper->setHelperSet($this);
52  }
53 
61  public function has($name)
62  {
63  return isset($this->helpers[$name]);
64  }
65 
75  public function get($name)
76  {
77  if (!$this->has($name)) {
78  throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
79  }
80 
81  if ('dialog' === $name && $this->helpers[$name] instanceof DialogHelper) {
82  @trigger_error('"Symfony\Component\Console\Helper\DialogHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\QuestionHelper" instead.', E_USER_DEPRECATED);
83  } elseif ('progress' === $name && $this->helpers[$name] instanceof ProgressHelper) {
84  @trigger_error('"Symfony\Component\Console\Helper\ProgressHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\ProgressBar" instead.', E_USER_DEPRECATED);
85  } elseif ('table' === $name && $this->helpers[$name] instanceof TableHelper) {
86  @trigger_error('"Symfony\Component\Console\Helper\TableHelper" is deprecated since version 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\Table" instead.', E_USER_DEPRECATED);
87  }
88 
89  return $this->helpers[$name];
90  }
91 
97  public function setCommand(Command $command = null)
98  {
99  $this->command = $command;
100  }
101 
107  public function getCommand()
108  {
109  return $this->command;
110  }
111 
112  public function getIterator()
113  {
114  return new \ArrayIterator($this->helpers);
115  }
116 }