82 lines
2.5 KiB
PHP
82 lines
2.5 KiB
PHP
<?php
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
/**
|
|
* This file is part of Icinga Web 2.
|
|
*
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
* Copyright (C) 2014 Icinga Development Team
|
|
*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*
|
|
* @copyright 2014 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>
|
|
*
|
|
*/
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
namespace Icinga\Module\Translation\Cli;
|
|
|
|
use \Exception;
|
|
use Icinga\Cli\Command;
|
|
|
|
/**
|
|
* Base class for translation commands
|
|
*/
|
|
class TranslationCommand extends Command
|
|
{
|
|
/**
|
|
* Check whether the given locale code is valid
|
|
*
|
|
* @param string $code The locale code to validate
|
|
*
|
|
* @return string The validated locale code
|
|
*
|
|
* @throws Exception In case the locale code is invalid
|
|
*/
|
|
public function validateLocaleCode($code)
|
|
{
|
|
$current = setlocale(LC_ALL, '0');
|
|
$result = setlocale(LC_ALL, $code);
|
|
setlocale(LC_ALL, $current);
|
|
|
|
if ($result === false) {
|
|
throw new Exception("Locale code '$code' is not valid");
|
|
}
|
|
|
|
return $code;
|
|
}
|
|
|
|
/**
|
|
* Check whether the given module is available and enabled
|
|
*
|
|
* @param string $name The module name to validate
|
|
*
|
|
* @return string The validated module name
|
|
*
|
|
* @throws Exception In case the given module is not available or not enabled
|
|
*/
|
|
public function validateModuleName($name)
|
|
{
|
|
$enabledModules = $this->app->getModuleManager()->listEnabledModules();
|
|
|
|
if (!in_array($name, $enabledModules)) {
|
|
throw new Exception("Module with name '$name' not found or is not enabled");
|
|
}
|
|
|
|
return $name;
|
|
}
|
|
}
|