2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
namespace Icinga\Application;
|
|
|
|
|
|
|
|
use Icinga\Exception\ProgrammingError;
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Icinga application container
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
class Icinga
|
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* @var ApplicationBootstrap
|
|
|
|
*/
|
|
|
|
private static $app;
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Getter for an application environment
|
|
|
|
*
|
|
|
|
* @return ApplicationBootstrap|Web
|
|
|
|
* @throws ProgrammingError
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
public static function app()
|
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
if (self::$app == null) {
|
2013-06-07 11:44:37 +02:00
|
|
|
throw new ProgrammingError('Icinga has never been started');
|
|
|
|
}
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
return self::$app;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Setter for an application environment
|
|
|
|
*
|
2014-04-14 08:31:46 +02:00
|
|
|
* @param ApplicationBootstrap $app
|
|
|
|
* @param bool $overwrite
|
|
|
|
*
|
2013-07-26 15:58:16 +02:00
|
|
|
* @throws ProgrammingError
|
|
|
|
*/
|
2014-04-14 08:31:46 +02:00
|
|
|
public static function setApp(ApplicationBootstrap $app, $overwrite = false)
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-04-14 08:31:46 +02:00
|
|
|
if (self::$app !== null && !$overwrite) {
|
2013-06-07 11:44:37 +02:00
|
|
|
throw new ProgrammingError('Cannot start Icinga twice');
|
|
|
|
}
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
self::$app = $app;
|
|
|
|
}
|
|
|
|
}
|