Event: onConsole

This event is called when Skynet starts (before any connections) when webconsole input commands are passed. You can place here code whitch must be executed when user type defined command or parameter.
In event you have access to console object so you can get all parameters and commands.

Access to console is offered by object:

$this->console

Take a look at example:

/src/SkynetUser/MyListener.php
public function onConsole()
{
if($this->console->isConsoleCommand('foo'))
{
/* do something */
}
}

Code above checks for command foo exists in input.

Method isConsoleCommand('COMMAND_NAME'):

$this->console->isConsoleCommand('foo')

returns TRUE if there is command @foo typed in console.
Note that argument passed here is without @ prefix.
At next, you can depends your actions in EventListener from command existing.

To get command data (like its params) you must use

$this->console->getConsoleCommand('COMMAND_NAME');

This method returns SkynetCommand object.

Every SkynetCommand has two most commonly using methods:

$command->getCode()

whitch returns command string name (without @ prefix)

$command->getParams()

whitch returns array with params passed to command.

Example:

/src/SkynetUser/MyListener.php
public function onConsole()
{
if($this->console->isConsoleCommand('foo'))
{
$command = $this->console->getConsoleCommand('foo');
$name = $command->getCode(); // foo
$params = $command->getParams(); // params passed to @foo
}
}

This was about getting commands data, if you want to get parameters passed into console (like foo:bar) you must get parameters list via:

/src/SkynetUser/MyListener.php
public function onConsole()
{
$params = $this->console->getConsoleRequests();

foreach($params as $paramName => $paramValue)
{
// some code here
}
}

Example:

If parameter foo with value bar was passed into webconsole by typing:

foo:bar

then you will see this parameter in:

/src/SkynetUser/MyListener.php
public function onConsole()
{
$params = $this->console->getConsoleRequests();

foreach($params as $paramName => $paramValue)
{
// $paramName <<< foo
// $paramValue <<< bar
}
}

Returned values:
Method onConsole() can returns string.
If any string is returned it will be display in Console output window in Skynet Control Panel.

Example:

/src/SkynetUser/MyListener.php
public function onConsole()
{
if($this->console->isConsoleCommand('foo'))
{
return 'Command foo is passed';
}
}
Full API Documentation is included in Skynet packages available on GitHub.