2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2013-07-12 15:00:59 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-07 11:44:37 +02:00
|
|
|
/**
|
2013-10-23 15:10:33 +02:00
|
|
|
* This file is part of Icinga Web 2.
|
2013-08-06 17:35:33 +02:00
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
2013-07-12 15:00:59 +02:00
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
2013-08-06 17:35:33 +02:00
|
|
|
*
|
2013-07-12 15:00:59 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2013-08-06 17:35:33 +02:00
|
|
|
*
|
2013-07-12 15:00:59 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2013-08-06 17:35:33 +02:00
|
|
|
*
|
2013-07-12 15:00:59 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2013-08-06 17:35:33 +02:00
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*
|
2013-06-07 11:44:37 +02:00
|
|
|
*/
|
2013-07-12 15:00:59 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
namespace Icinga\Application;
|
|
|
|
|
2014-02-18 14:46:15 +01:00
|
|
|
use DateTimeZone;
|
|
|
|
use Exception;
|
2014-02-20 13:53:28 +01:00
|
|
|
use Zend_Config;
|
2014-02-26 11:19:52 +01:00
|
|
|
use Icinga\Application\Modules\Manager as ModuleManager;
|
|
|
|
use Icinga\Application\Config;
|
2013-09-24 15:26:10 +02:00
|
|
|
use Icinga\Data\ResourceFactory;
|
2014-02-26 11:19:52 +01:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
2014-02-20 13:53:28 +01:00
|
|
|
use Icinga\Exception\NotReadableError;
|
2014-03-03 19:03:39 +01:00
|
|
|
use Icinga\Logger\Logger;
|
2014-02-26 11:19:52 +01:00
|
|
|
use Icinga\Util\DateTimeFactory;
|
|
|
|
use Icinga\Util\Translator;
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class bootstraps a thin Icinga application layer
|
|
|
|
*
|
|
|
|
* Usage example for CLI:
|
|
|
|
* <code>
|
|
|
|
* use Icinga\Application\Cli;
|
2013-06-20 14:06:02 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
* Cli::start();
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* Usage example for Icinga Web application:
|
|
|
|
* <code>
|
|
|
|
* use Icinga\Application\Web;
|
|
|
|
* Web::start()->dispatch();
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* Usage example for Icinga-Web 1.x compatibility mode:
|
|
|
|
* <code>
|
|
|
|
* use Icinga\Application\LegacyWeb;
|
|
|
|
* LegacyWeb::start()->setIcingaWebBasedir(ICINGAWEB_BASEDIR)->dispatch();
|
|
|
|
* </code>
|
|
|
|
*/
|
|
|
|
abstract class ApplicationBootstrap
|
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Icinga auto loader
|
|
|
|
*
|
|
|
|
* @var Loader
|
|
|
|
*/
|
|
|
|
private $loader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Library directory
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $libDir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Config object
|
|
|
|
*
|
2014-02-20 13:53:28 +01:00
|
|
|
* @var Zend_Config
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2014-02-14 10:48:17 +01:00
|
|
|
protected $config;
|
2013-07-26 15:58:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration directory
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $configDir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Application directory
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $appDir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module manager
|
|
|
|
*
|
|
|
|
* @var ModuleManager
|
|
|
|
*/
|
|
|
|
private $moduleManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag indicates we're on cli environment
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
protected $isCli = false;
|
2013-07-26 15:58:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag indicates we're on web environment
|
2013-08-06 17:35:33 +02:00
|
|
|
*
|
2013-07-26 15:58:16 +02:00
|
|
|
* @var bool
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
protected $isWeb = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2013-07-12 15:37:36 +02:00
|
|
|
protected function __construct($configDir)
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-02-12 14:51:04 +01:00
|
|
|
$this->libDir = realpath(__DIR__ . '/../..');
|
2013-06-14 13:51:44 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
if (!defined('ICINGA_LIBDIR')) {
|
|
|
|
define('ICINGA_LIBDIR', $this->libDir);
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
2013-07-12 15:00:59 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
// TODO: Make appdir configurable for packagers
|
2013-07-26 15:58:16 +02:00
|
|
|
$this->appDir = realpath($this->libDir. '/../application');
|
2013-07-12 15:00:59 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
if (!defined('ICINGA_APPDIR')) {
|
|
|
|
define('ICINGA_APPDIR', $this->appDir);
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
$this->setupAutoloader();
|
|
|
|
$this->setupZendAutoloader();
|
2013-06-14 13:51:44 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
Benchmark::measure('Bootstrap, autoloader registered');
|
|
|
|
|
|
|
|
Icinga::setApp($this);
|
2013-07-30 16:02:05 +02:00
|
|
|
$this->configDir = realpath($configDir);
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
require_once dirname(__FILE__) . '/functions.php';
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Bootstrap interface method for concrete bootstrap objects
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
abstract protected function bootstrap();
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Getter for module manager
|
|
|
|
*
|
|
|
|
* @return ModuleManager
|
|
|
|
*/
|
|
|
|
public function getModuleManager()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
return $this->moduleManager;
|
|
|
|
}
|
|
|
|
|
2013-07-12 15:00:59 +02:00
|
|
|
/**
|
|
|
|
* Getter for class loader
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
2013-07-12 15:00:59 +02:00
|
|
|
* @return Loader
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
public function getLoader()
|
|
|
|
{
|
|
|
|
return $this->loader;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Getter for configuration object
|
|
|
|
*
|
|
|
|
* @return Config
|
|
|
|
*/
|
|
|
|
public function getConfig()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
return $this->config;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Flag indicates we're on cli environment
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
public function isCli()
|
|
|
|
{
|
|
|
|
return $this->isCli;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Flag indicates we're on web environment
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
public function isWeb()
|
|
|
|
{
|
|
|
|
return $this->isWeb;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Getter for application dir
|
|
|
|
*
|
|
|
|
* Optional append sub directory
|
|
|
|
*
|
2013-08-23 09:57:32 +02:00
|
|
|
* @param string $subdir optional subdir
|
|
|
|
*
|
|
|
|
* @return string
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
public function getApplicationDir($subdir = null)
|
|
|
|
{
|
2013-07-30 16:02:05 +02:00
|
|
|
return $this->getDirWithSubDir($this->appDir, $subdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for config dir
|
2013-08-23 09:57:32 +02:00
|
|
|
*
|
|
|
|
* @param string $subdir
|
|
|
|
*
|
|
|
|
* @return string
|
2013-07-30 16:02:05 +02:00
|
|
|
*/
|
|
|
|
public function getConfigDir($subdir = null)
|
|
|
|
{
|
|
|
|
return $this->getDirWithSubDir($this->configDir, $subdir);
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:13:13 +01:00
|
|
|
/**
|
|
|
|
* Get the path to the bootstrapping directory.
|
|
|
|
*
|
|
|
|
* This is usually /public for Web and EmbeddedWeb
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getBootstrapDirecory()
|
|
|
|
{
|
|
|
|
return dirname($_SERVER['SCRIPT_FILENAME']);
|
|
|
|
}
|
|
|
|
|
2013-07-30 16:02:05 +02:00
|
|
|
/**
|
|
|
|
* Helper to glue directories together
|
|
|
|
*
|
2013-08-23 09:57:32 +02:00
|
|
|
* @param string $dir
|
|
|
|
* @param string $subdir
|
|
|
|
*
|
|
|
|
* @return string
|
2013-07-30 16:02:05 +02:00
|
|
|
*/
|
2013-08-12 16:38:26 +02:00
|
|
|
private function getDirWithSubDir($dir, $subdir = null)
|
2013-07-30 16:02:05 +02:00
|
|
|
{
|
2013-06-07 11:44:37 +02:00
|
|
|
if ($subdir !== null) {
|
|
|
|
$dir .= '/' . ltrim($subdir, '/');
|
|
|
|
}
|
2013-07-30 16:02:05 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
return $dir;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Starting concrete bootstrap classes
|
|
|
|
*
|
2013-08-23 09:57:32 +02:00
|
|
|
* @param string $configDir
|
|
|
|
*
|
|
|
|
* @return ApplicationBootstrap
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-07-12 15:37:36 +02:00
|
|
|
public static function start($configDir)
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-02-12 14:51:04 +01:00
|
|
|
$application = new static($configDir);
|
2013-08-23 09:57:32 +02:00
|
|
|
$application->bootstrap();
|
|
|
|
return $application;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
2013-08-23 09:57:32 +02:00
|
|
|
* Setup Icinga auto loader
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setupAutoloader()
|
2013-07-12 15:00:59 +02:00
|
|
|
{
|
2014-02-12 14:51:04 +01:00
|
|
|
require $this->libDir . '/Icinga/Application/Loader.php';
|
2013-07-12 15:00:59 +02:00
|
|
|
|
|
|
|
$this->loader = new Loader();
|
2013-07-26 15:58:16 +02:00
|
|
|
$this->loader->registerNamespace('Icinga', $this->libDir. '/Icinga');
|
|
|
|
$this->loader->registerNamespace('Icinga\\Form', $this->appDir. '/forms');
|
2013-07-12 15:00:59 +02:00
|
|
|
$this->loader->register();
|
2013-07-26 15:58:16 +02:00
|
|
|
|
|
|
|
return $this;
|
2013-07-12 15:00:59 +02:00
|
|
|
}
|
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
/**
|
|
|
|
* Register the Zend Autoloader
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2013-07-26 15:58:16 +02:00
|
|
|
protected function setupZendAutoloader()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
require_once 'Zend/Loader/Autoloader.php';
|
2013-07-26 15:58:16 +02:00
|
|
|
|
|
|
|
\Zend_Loader_Autoloader::getInstance();
|
|
|
|
|
|
|
|
// Unfortunately this is needed to get the Zend Plugin loader working:
|
|
|
|
set_include_path(
|
|
|
|
implode(
|
|
|
|
PATH_SEPARATOR,
|
|
|
|
array($this->libDir, get_include_path())
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-22 18:11:26 +01:00
|
|
|
* Setup module manager
|
2013-06-07 11:44:37 +02:00
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2014-01-22 18:11:26 +01:00
|
|
|
protected function setupModuleManager()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-01-24 10:48:30 +01:00
|
|
|
$this->moduleManager = new ModuleManager(
|
|
|
|
$this,
|
|
|
|
$this->configDir . '/enabledModules',
|
2014-02-20 13:53:28 +01:00
|
|
|
explode(
|
|
|
|
':',
|
|
|
|
$this->config->global !== null
|
|
|
|
? $this->config->global->get('modulePath', ICINGA_APPDIR . '/../modules')
|
|
|
|
: ICINGA_APPDIR . '/../modules'
|
|
|
|
)
|
2014-01-24 10:48:30 +01:00
|
|
|
);
|
2014-01-22 18:11:26 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2014-01-22 18:11:26 +01:00
|
|
|
/**
|
|
|
|
* Load all enabled modules
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
protected function loadEnabledModules()
|
|
|
|
{
|
2013-09-02 12:47:57 +02:00
|
|
|
try {
|
|
|
|
$this->moduleManager->loadEnabledModules();
|
2014-02-20 13:53:28 +01:00
|
|
|
} catch (NotReadableError $e) {
|
2014-03-03 19:03:39 +01:00
|
|
|
Logger::error(new Exception('Cannot load enabled modules. An exception was thrown:', 0, $e));
|
2013-09-02 12:47:57 +02:00
|
|
|
}
|
2013-07-26 15:58:16 +02:00
|
|
|
return $this;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2014-02-26 11:19:52 +01:00
|
|
|
/**
|
|
|
|
* Setup default logging
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
protected function setupLogging()
|
|
|
|
{
|
|
|
|
Logger::create(
|
|
|
|
new Zend_Config(
|
|
|
|
array(
|
|
|
|
'enable' => true,
|
|
|
|
'level' => Logger::$ERROR,
|
|
|
|
'type' => 'syslog',
|
|
|
|
'facility' => 'LOG_USER',
|
|
|
|
'application' => 'Icinga Web'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
/**
|
|
|
|
* Load Configuration
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2014-02-12 14:51:04 +01:00
|
|
|
protected function loadConfig()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-07-12 15:37:36 +02:00
|
|
|
Config::$configDir = $this->configDir;
|
2014-02-20 13:53:28 +01:00
|
|
|
try {
|
|
|
|
$this->config = Config::app();
|
|
|
|
} catch (NotReadableError $e) {
|
2014-03-03 19:03:39 +01:00
|
|
|
Logger::error(new Exception('Cannot load application configuration. An exception was thrown:', 0, $e));
|
2014-02-20 13:53:28 +01:00
|
|
|
$this->config = new Zend_Config(array());
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Error handling configuration
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2013-07-26 15:58:16 +02:00
|
|
|
protected function setupErrorHandling()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-02-14 10:48:17 +01:00
|
|
|
error_reporting(E_ALL | E_NOTICE);
|
|
|
|
ini_set('display_startup_errors', 1);
|
|
|
|
ini_set('display_errors', 1);
|
|
|
|
return $this;
|
|
|
|
}
|
2014-02-26 11:19:52 +01:00
|
|
|
|
2014-02-14 10:48:17 +01:00
|
|
|
/**
|
|
|
|
* Set up logger
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
protected function setupLogger()
|
|
|
|
{
|
2014-02-20 13:53:28 +01:00
|
|
|
if ($this->config->logging !== null) {
|
2014-03-03 19:03:39 +01:00
|
|
|
try {
|
|
|
|
Logger::create($this->config->logging);
|
|
|
|
} catch (ConfigurationError $e) {
|
|
|
|
Logger::error($e);
|
|
|
|
}
|
2014-02-26 11:19:52 +01:00
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-02-20 13:53:28 +01:00
|
|
|
* Set up the resource factory
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2013-09-24 15:26:10 +02:00
|
|
|
protected function setupResourceFactory()
|
2013-08-13 18:08:21 +02:00
|
|
|
{
|
2014-02-20 13:53:28 +01:00
|
|
|
try {
|
|
|
|
$config = Config::app('resources');
|
|
|
|
ResourceFactory::setConfig($config);
|
|
|
|
} catch (NotReadableError $e) {
|
2014-03-03 19:03:39 +01:00
|
|
|
Logger::error(
|
2014-02-20 13:53:28 +01:00
|
|
|
new Exception('Cannot load resource configuration. An exception was thrown:', 0, $e)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-08-13 18:08:21 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup default timezone
|
2013-06-07 11:44:37 +02:00
|
|
|
*
|
2013-08-23 09:57:32 +02:00
|
|
|
* @return self
|
|
|
|
* @throws ConfigurationError if the timezone in config.ini isn't valid
|
2013-06-07 11:44:37 +02:00
|
|
|
*/
|
2013-07-26 15:58:16 +02:00
|
|
|
protected function setupTimezone()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-02-20 13:53:28 +01:00
|
|
|
$timeZoneString = $this->config->global !== null ? $this->config->global->get('timezone', 'UTC') : 'UTC';
|
2013-08-06 17:35:33 +02:00
|
|
|
try {
|
2013-08-12 11:21:30 +02:00
|
|
|
$tz = new DateTimeZone($timeZoneString);
|
2013-08-06 17:35:33 +02:00
|
|
|
} catch (Exception $e) {
|
2013-08-12 11:21:30 +02:00
|
|
|
throw new ConfigurationError(t('Invalid timezone') . ' "' . $timeZoneString . '"');
|
2013-08-06 17:35:33 +02:00
|
|
|
}
|
2013-08-12 11:21:30 +02:00
|
|
|
date_default_timezone_set($timeZoneString);
|
2013-08-12 10:54:16 +02:00
|
|
|
DateTimeFactory::setConfig(array('timezone' => $tz));
|
2013-06-07 11:44:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2014-01-29 16:25:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup internationalization using gettext
|
|
|
|
*
|
|
|
|
* Uses the language defined in the global config or the default one
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
protected function setupInternationalization()
|
|
|
|
{
|
2014-02-03 12:22:13 +01:00
|
|
|
try {
|
2014-02-20 13:53:28 +01:00
|
|
|
Translator::setupLocale(
|
|
|
|
$this->config->global !== null ? $this->config->global->get('language', Translator::DEFAULT_LOCALE)
|
|
|
|
: Translator::DEFAULT_LOCALE
|
|
|
|
);
|
2014-02-03 12:22:13 +01:00
|
|
|
} catch (Exception $error) {
|
2014-02-26 11:19:52 +01:00
|
|
|
Logger::error($error);
|
2014-02-03 12:22:13 +01:00
|
|
|
}
|
2014-01-29 16:25:08 +01:00
|
|
|
|
|
|
|
$localeDir = $this->getApplicationDir('locale');
|
|
|
|
if (file_exists($localeDir) && is_dir($localeDir)) {
|
|
|
|
Translator::registerDomain('icinga', $localeDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|