Eric Lippmann e7eae87f16 monitoring/commands: Replace Command' with IcingaCommand'
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
2014-08-29 14:38:52 +02:00

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())
);
}
}