2013-06-07 05:44:37 -04:00
|
|
|
<?php
|
2026-03-26 12:46:27 -04:00
|
|
|
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2013-06-07 05:44:37 -04:00
|
|
|
|
|
|
|
|
namespace Icinga\Application;
|
|
|
|
|
|
|
|
|
|
use Icinga\Exception\ProgrammingError;
|
|
|
|
|
|
2013-07-26 09:58:16 -04:00
|
|
|
/**
|
|
|
|
|
* Icinga application container
|
|
|
|
|
*/
|
2013-06-07 05:44:37 -04:00
|
|
|
class Icinga
|
|
|
|
|
{
|
2013-07-26 09:58:16 -04:00
|
|
|
/**
|
|
|
|
|
* @var ApplicationBootstrap
|
|
|
|
|
*/
|
|
|
|
|
private static $app;
|
2013-06-07 05:44:37 -04:00
|
|
|
|
2013-07-26 09:58:16 -04:00
|
|
|
/**
|
|
|
|
|
* Getter for an application environment
|
|
|
|
|
*
|
|
|
|
|
* @return ApplicationBootstrap|Web
|
|
|
|
|
* @throws ProgrammingError
|
|
|
|
|
*/
|
2013-06-07 05:44:37 -04:00
|
|
|
public static function app()
|
|
|
|
|
{
|
2013-07-26 09:58:16 -04:00
|
|
|
if (self::$app == null) {
|
2013-06-07 05:44:37 -04:00
|
|
|
throw new ProgrammingError('Icinga has never been started');
|
|
|
|
|
}
|
2013-07-26 09:58:16 -04:00
|
|
|
|
2013-06-07 05:44:37 -04:00
|
|
|
return self::$app;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 09:58:16 -04:00
|
|
|
/**
|
|
|
|
|
* Setter for an application environment
|
|
|
|
|
*
|
2014-04-14 02:31:46 -04:00
|
|
|
* @param ApplicationBootstrap $app
|
|
|
|
|
* @param bool $overwrite
|
|
|
|
|
*
|
2013-07-26 09:58:16 -04:00
|
|
|
* @throws ProgrammingError
|
|
|
|
|
*/
|
2014-04-14 02:31:46 -04:00
|
|
|
public static function setApp(ApplicationBootstrap $app, $overwrite = false)
|
2013-06-07 05:44:37 -04:00
|
|
|
{
|
2014-04-14 02:31:46 -04:00
|
|
|
if (self::$app !== null && !$overwrite) {
|
2013-06-07 05:44:37 -04:00
|
|
|
throw new ProgrammingError('Cannot start Icinga twice');
|
|
|
|
|
}
|
2013-07-26 09:58:16 -04:00
|
|
|
|
2013-06-07 05:44:37 -04:00
|
|
|
self::$app = $app;
|
|
|
|
|
}
|
|
|
|
|
}
|