Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • DialogHelper
  • FormatterHelper
  • Helper
  • HelperSet
  • ProgressHelper

Interfaces

  • HelperInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  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: 
 16: /**
 17:  * HelperSet represents a set of helpers to be used with a command.
 18:  *
 19:  * @author Fabien Potencier <fabien@symfony.com>
 20:  */
 21: class HelperSet
 22: {
 23:     private $helpers;
 24:     private $command;
 25: 
 26:     /**
 27:      * Constructor.
 28:      *
 29:      * @param Helper[] $helpers An array of helper.
 30:      */
 31:     public function __construct(array $helpers = array())
 32:     {
 33:         $this->helpers = array();
 34:         foreach ($helpers as $alias => $helper) {
 35:             $this->set($helper, is_int($alias) ? null : $alias);
 36:         }
 37:     }
 38: 
 39:     /**
 40:      * Sets a helper.
 41:      *
 42:      * @param HelperInterface $helper The helper instance
 43:      * @param string          $alias  An alias
 44:      */
 45:     public function set(HelperInterface $helper, $alias = null)
 46:     {
 47:         $this->helpers[$helper->getName()] = $helper;
 48:         if (null !== $alias) {
 49:             $this->helpers[$alias] = $helper;
 50:         }
 51: 
 52:         $helper->setHelperSet($this);
 53:     }
 54: 
 55:     /**
 56:      * Returns true if the helper if defined.
 57:      *
 58:      * @param string $name The helper name
 59:      *
 60:      * @return Boolean true if the helper is defined, false otherwise
 61:      */
 62:     public function has($name)
 63:     {
 64:         return isset($this->helpers[$name]);
 65:     }
 66: 
 67:     /**
 68:      * Gets a helper value.
 69:      *
 70:      * @param string $name The helper name
 71:      *
 72:      * @return HelperInterface The helper instance
 73:      *
 74:      * @throws \InvalidArgumentException if the helper is not defined
 75:      */
 76:     public function get($name)
 77:     {
 78:         if (!$this->has($name)) {
 79:             throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
 80:         }
 81: 
 82:         return $this->helpers[$name];
 83:     }
 84: 
 85:     /**
 86:      * Sets the command associated with this helper set.
 87:      *
 88:      * @param Command $command A Command instance
 89:      */
 90:     public function setCommand(Command $command = null)
 91:     {
 92:         $this->command = $command;
 93:     }
 94: 
 95:     /**
 96:      * Gets the command associated with this helper set.
 97:      *
 98:      * @return Command A Command instance
 99:      */
100:     public function getCommand()
101:     {
102:         return $this->command;
103:     }
104: }
105: 
php-coveralls API documentation generated by ApiGen 2.8.0