Webmozart\Console\Api\Config\CommandConfig::addAlias PHP Method

addAlias() public method

An alias is an alternative name that can be used when calling the command. Aliases are a useful way for migrating a command from one name to another. Existing alias names are preserved.
public addAlias ( string $alias ) : static
$alias string The alias name to add.
return static The current instance.
    public function addAlias($alias)
    {
        Assert::string($alias, 'The command alias must be a string. Got: %s');
        Assert::notEmpty($alias, 'The command alias must not be empty.');
        Assert::regex($alias, '~^[a-zA-Z0-9\\-]+$~', 'The command alias should contain letters, digits and hyphens only. Got: %s');
        $this->aliases[] = $alias;
        return $this;
    }

Usage Example

示例#1
0
 public function testSetAliases()
 {
     $this->config->addAlias('alias1');
     $this->config->setAliases(array('alias2', 'alias3'));
     $this->assertSame(array('alias2', 'alias3'), $this->config->getAliases());
 }