mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-06-26 08:40:11 +02:00
Since there's already a `Cli\Command', `Command' is now named `IcingaCommand'. All concrete Icinga commands should extend `IcingaCommand' which handles command encoding. All other "features" of the `Command' object have been removed because theses "features" should be handled by upcoming concrete command classes. refs #6593
45 lines
906 B
PHP
45 lines
906 B
PHP
<?php
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
namespace Icinga\Module\Monitoring\Command;
|
|
|
|
/**
|
|
* Base class for commands sent to an Icinga instance
|
|
*/
|
|
abstract class IcingaCommand
|
|
{
|
|
/**
|
|
* Get the command string
|
|
*
|
|
* @return string
|
|
*/
|
|
abstract public function getCommandString();
|
|
|
|
/**
|
|
* Escape a command string
|
|
*
|
|
* @param string $commandString
|
|
*
|
|
* @return string
|
|
*/
|
|
public function escape($commandString)
|
|
{
|
|
return str_replace(array("\r", "\n"), array('\r', '\n'), $commandString);
|
|
}
|
|
|
|
/**
|
|
* Get the command as string with the current timestamp as the command submission time
|
|
*
|
|
* @return string
|
|
*/
|
|
public function __toString()
|
|
{
|
|
return sprintf(
|
|
'[%u] %s',
|
|
time(),
|
|
$this->escape($this->getCommandString())
|
|
);
|
|
}
|
|
}
|