Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HelperSet.php

class HelperSet

HelperSet represents a set of helpers to be used with a command.

@author Fabien Potencier <fabien@symfony.com>

@implements \IteratorAggregate<string, HelperInterface>

Hierarchy

  • class \Symfony\Component\Console\Helper\HelperSet implements \Symfony\Component\Console\Helper\IteratorAggregate

Expanded class hierarchy of HelperSet

7 files declare their use of HelperSet
Application.php in vendor/composer/composer/src/Composer/Console/Application.php
Application.php in vendor/symfony/console/Application.php
BufferIO.php in vendor/composer/composer/src/Composer/IO/BufferIO.php
Command.php in vendor/symfony/console/Command/Command.php
ConsoleIO.php in vendor/composer/composer/src/Composer/IO/ConsoleIO.php

... See full list

File

vendor/symfony/console/Helper/HelperSet.php, line 23

Namespace

Symfony\Component\Console\Helper
View source
class HelperSet implements \IteratorAggregate {
    
    /** @var array<string, HelperInterface> */
    private array $helpers = [];
    
    /**
     * @param HelperInterface[] $helpers
     */
    public function __construct(array $helpers = []) {
        foreach ($helpers as $alias => $helper) {
            $this->set($helper, \is_int($alias) ? null : $alias);
        }
    }
    public function set(HelperInterface $helper, ?string $alias = null) : void {
        $this->helpers[$helper->getName()] = $helper;
        if (null !== $alias) {
            $this->helpers[$alias] = $helper;
        }
        $helper->setHelperSet($this);
    }
    
    /**
     * Returns true if the helper if defined.
     */
    public function has(string $name) : bool {
        return isset($this->helpers[$name]);
    }
    
    /**
     * Gets a helper value.
     *
     * @throws InvalidArgumentException if the helper is not defined
     */
    public function get(string $name) : HelperInterface {
        if (!$this->has($name)) {
            throw new InvalidArgumentException(\sprintf('The helper "%s" is not defined.', $name));
        }
        return $this->helpers[$name];
    }
    public function getIterator() : \Traversable {
        return new \ArrayIterator($this->helpers);
    }

}

Members

Title Sort descending Modifiers Object type Summary
HelperSet::$helpers private property @var array&lt;string, HelperInterface&gt;
HelperSet::get public function Gets a helper value.
HelperSet::getIterator public function
HelperSet::has public function Returns true if the helper if defined.
HelperSet::set public function
HelperSet::__construct public function
RSS feed
Powered by Drupal