Overview

Namespaces

  • Webmozart
    • Console
      • Adapter
      • Api
        • Application
        • Args
          • Format
        • Command
        • Config
        • Event
        • Formatter
        • IO
        • Resolver
      • Args
      • Config
      • Formatter
      • Handler
        • Help
      • IO
        • InputStream
        • OutputStream
      • Process
      • Resolver
      • UI
        • Alignment
        • Component
        • Help
        • Layout
        • Style
      • Util

Classes

  • Command
  • CommandCollection

Exceptions

  • CannotAddCommandException
  • NoSuchCommandException
  • Overview
  • Namespace
  • Class

Class CommandCollection

A collection of named commands.

Webmozart\Console\Api\Command\CommandCollection implements ArrayAccess, IteratorAggregate, Countable
Namespace: Webmozart\Console\Api\Command
Author: Bernhard Schussek bschussek@gmail.com
Since: 1.0
Located at Api/Command/CommandCollection.php
Methods summary
public
# __construct( array $commands = array() )

Creates a new command collection.

Creates a new command collection.

Parameters

$commands

The commands to initially add to the collection.

public
# add( Webmozart\Console\Api\Command\Command $command )

Adds a command to the collection.

Adds a command to the collection.

If a command exists with the same name in the collection, that command is overwritten.

Parameters

$command
The command to add.

See

Webmozart\Console\Api\Command\CommandCollection::merge(), Webmozart\Console\Api\Command\CommandCollection::replace()
public
# merge( array $commands )

Adds multiple commands to the collection.

Adds multiple commands to the collection.

Existing commands are preserved. Commands with the same names as the passed commands are overwritten.

Parameters

$commands
The commands to add.

See

Webmozart\Console\Api\Command\CommandCollection::add(), Webmozart\Console\Api\Command\CommandCollection::replace()
public
# replace( array $commands )

Sets the commands in the collection.

Sets the commands in the collection.

Existing commands are replaced.

Parameters

$commands
The commands to set.

See

Webmozart\Console\Api\Command\CommandCollection::add(), Webmozart\Console\Api\Command\CommandCollection::merge()
public Webmozart\Console\Api\Command\Command
# get( string $name )

Returns a command by its name.

Returns a command by its name.

Parameters

$name
The name of the command.

Returns

Webmozart\Console\Api\Command\Command
The command.

Throws

Webmozart\Console\Api\Command\NoSuchCommandException

If no command with that name exists in the collection.

public
# remove( string $name )

Removes the command with the given name from the collection.

Removes the command with the given name from the collection.

If no such command can be found, the method does nothing.

Parameters

$name
The name of the command.
public boolean
# contains( string $name )

Returns whether the collection contains a command with the given name.

Returns whether the collection contains a command with the given name.

Parameters

$name
The name of the command.

Returns

boolean

Returns true if the collection contains a command with that name and false otherwise.

public
# clear( )

Removes all commands from the collection.

Removes all commands from the collection.

public boolean
# isEmpty( )

Returns whether the collection is empty.

Returns whether the collection is empty.

Returns

boolean

Returns true if the collection is empty and false otherwise.

public Webmozart\Console\Api\Command\Command[]
# toArray( )

Returns the contents of the collection as array.

Returns the contents of the collection as array.

The commands in the collection are returned indexed by their names. The result is sorted in the order in which the commands were added to the collection.

Returns

Webmozart\Console\Api\Command\Command[]
The commands indexed by their names.
public
# filterDefault( )
public
# filterNonDefault( )
public
# filterAnonymous( )
public
# filterNonAnonymous( )
public string[]
# getNames( boolean $includeAliases = false )

Returns the names of all commands in the collection.

Returns the names of all commands in the collection.

The names are sorted alphabetically in ascending order. If you set $includeAliases to true, the alias names are included in the result.

Parameters

$includeAliases
Whether to include alias names in the result.

Returns

string[]
The sorted command names.
public string[]
# getAliases( )

Returns the aliases of all commands in the collection.

Returns the aliases of all commands in the collection.

The aliases are sorted alphabetically in ascending order.

Returns

string[]
The command names indexed and sorted by their aliases.
public
# offsetExists( $name )

Implementation of

ArrayAccess::offsetExists()
public
# offsetGet( $name )

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( $offset, $command )

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( $name )

Implementation of

ArrayAccess::offsetUnset()
public
# getIterator( )

Implementation of

IteratorAggregate::getIterator()
public
# count( )

Implementation of

Countable::count()
Webmozart Console API API documentation generated by ApiGen