[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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 14 use Symfony\Component\Console\Command\Command; 15 use Symfony\Component\Console\Exception\InvalidArgumentException; 16 17 /** 18 * HelperSet represents a set of helpers to be used with a command. 19 * 20 * @author Fabien Potencier <fabien@symfony.com> 21 */ 22 class HelperSet implements \IteratorAggregate 23 { 24 /** 25 * @var Helper[] 26 */ 27 private $helpers = array(); 28 private $command; 29 30 /** 31 * @param Helper[] $helpers An array of helper 32 */ 33 public function __construct(array $helpers = array()) 34 { 35 foreach ($helpers as $alias => $helper) { 36 $this->set($helper, \is_int($alias) ? null : $alias); 37 } 38 } 39 40 /** 41 * Sets a helper. 42 * 43 * @param HelperInterface $helper The helper instance 44 * @param string $alias An alias 45 */ 46 public function set(HelperInterface $helper, $alias = null) 47 { 48 $this->helpers[$helper->getName()] = $helper; 49 if (null !== $alias) { 50 $this->helpers[$alias] = $helper; 51 } 52 53 $helper->setHelperSet($this); 54 } 55 56 /** 57 * Returns true if the helper if defined. 58 * 59 * @param string $name The helper name 60 * 61 * @return bool true if the helper is defined, false otherwise 62 */ 63 public function has($name) 64 { 65 return isset($this->helpers[$name]); 66 } 67 68 /** 69 * Gets a helper value. 70 * 71 * @param string $name The helper name 72 * 73 * @return HelperInterface The helper instance 74 * 75 * @throws InvalidArgumentException if the helper is not defined 76 */ 77 public function get($name) 78 { 79 if (!$this->has($name)) { 80 throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name)); 81 } 82 83 if ('dialog' === $name && $this->helpers[$name] instanceof DialogHelper) { 84 @trigger_error('"Symfony\Component\Console\Helper\DialogHelper" is deprecated since Symfony 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\QuestionHelper" instead.', E_USER_DEPRECATED); 85 } elseif ('progress' === $name && $this->helpers[$name] instanceof ProgressHelper) { 86 @trigger_error('"Symfony\Component\Console\Helper\ProgressHelper" is deprecated since Symfony 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\ProgressBar" instead.', E_USER_DEPRECATED); 87 } elseif ('table' === $name && $this->helpers[$name] instanceof TableHelper) { 88 @trigger_error('"Symfony\Component\Console\Helper\TableHelper" is deprecated since Symfony 2.5 and will be removed in 3.0. Use "Symfony\Component\Console\Helper\Table" instead.', E_USER_DEPRECATED); 89 } 90 91 return $this->helpers[$name]; 92 } 93 94 public function setCommand(Command $command = null) 95 { 96 $this->command = $command; 97 } 98 99 /** 100 * Gets the command associated with this helper set. 101 * 102 * @return Command A Command instance 103 */ 104 public function getCommand() 105 { 106 return $this->command; 107 } 108 109 /** 110 * @return Helper[] 111 */ 112 public function getIterator() 113 { 114 return new \ArrayIterator($this->helpers); 115 } 116 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |