Cake\Console\ShellDispatcher::alias PHP Method

alias() public static method

Aliases allow you to call shells by alternate names. This is most useful when dealing with plugin shells that you want to have shorter names for. If you re-use an alias the last alias set will be the one available. ### Usage Aliasing a shell named ClassName: $this->alias('alias', 'ClassName'); Getting the original name for a given alias: $this->alias('alias');
public static alias ( string $short, string | null $original = null ) : string | false
$short string The new short name for the shell.
$original string | null The original full name for the shell.
return string | false The aliased class name, or false if the alias does not exist
    public static function alias($short, $original = null)
    {
        $short = Inflector::camelize($short);
        if ($original) {
            static::$_aliases[$short] = $original;
        }
        return isset(static::$_aliases[$short]) ? static::$_aliases[$short] : false;
    }

Usage Example

Example #1
0
 /**
  * Test finding a shell that has a matching alias.
  *
  * Aliases should not overload concrete shells.
  *
  * @return void
  */
 public function testFindShellAliasedAppShadow()
 {
     ShellDispatcher::alias('sample', 'test_plugin.example');
     $result = $this->dispatcher->findShell('sample');
     $this->assertInstanceOf('TestApp\\Shell\\SampleShell', $result);
     $this->assertEmpty($result->plugin);
     $this->assertEquals('Sample', $result->name);
 }