2021-02-04 09:02:19 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Icingadb\Command\Object;
|
|
|
|
|
|
|
|
|
|
use Icinga\Module\Icingadb\Command\IcingaCommand;
|
|
|
|
|
use ipl\Orm\Model;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base class for commands that involve a monitored object, i.e. a host or service
|
|
|
|
|
*/
|
|
|
|
|
abstract class ObjectCommand extends IcingaCommand
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Involved object
|
|
|
|
|
*
|
|
|
|
|
* @var Model
|
|
|
|
|
*/
|
|
|
|
|
protected $object;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the involved object
|
|
|
|
|
*
|
|
|
|
|
* @param Model $object
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
2021-09-22 04:21:15 -04:00
|
|
|
public function setObject(Model $object): self
|
2021-02-04 09:02:19 -05:00
|
|
|
{
|
|
|
|
|
$this->object = $object;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the involved object
|
|
|
|
|
*
|
|
|
|
|
* @return Model
|
|
|
|
|
*/
|
2021-09-22 04:21:15 -04:00
|
|
|
public function getObject(): Model
|
2021-02-04 09:02:19 -05:00
|
|
|
{
|
2021-09-22 04:21:15 -04:00
|
|
|
if ($this->object === null) {
|
|
|
|
|
throw new \LogicException(
|
|
|
|
|
'You are accessing an unset property. Please make sure to set it beforehand.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 09:02:19 -05:00
|
|
|
return $this->object;
|
|
|
|
|
}
|
|
|
|
|
}
|