From a4733c77282e1b60a909be1f1a39eb912d8d9ac6 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 27 Jul 2016 22:19:45 +0200 Subject: [PATCH] Localization fix --- Localization/Localization.php | 2 ++ Log/FileLogger.php | 4 ++-- System/File/Directory.php | 3 +-- Views/View.php | 32 ++++++++++++++++++++++++-------- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Localization/Localization.php b/Localization/Localization.php index f6edf12cd..c4a289a13 100644 --- a/Localization/Localization.php +++ b/Localization/Localization.php @@ -16,6 +16,8 @@ namespace phpOMS\Localization; use phpOMS\Datatypes\Exception\InvalidEnumValue; +use phpOMS\Utils\Converter\AngleType; +use phpOMS\Utils\Converter\TemperatureType; /** * Localization class. diff --git a/Log/FileLogger.php b/Log/FileLogger.php index ba38e2bf2..65bde6914 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -19,7 +19,7 @@ use phpOMS\Datatypes\Exception\InvalidEnumValue; use phpOMS\System\File\Directory; use phpOMS\System\File\File; use phpOMS\System\File\PathException; -use phpOMS\Validation\Validator; +use phpOMS\Utils\StringUtils; /** * Logging class. @@ -99,7 +99,7 @@ class FileLogger implements LoggerInterface $path = realpath($lpath); $this->verbose = $verbose; - if ($path !== false && Validator::startsWith($path, ROOT_PATH) === false) { + if ($path !== false && StringUtils::startsWith($path, ROOT_PATH) === false) { throw new PathException($lpath); } diff --git a/System/File/Directory.php b/System/File/Directory.php index b08c3809f..a0e5f8e8b 100644 --- a/System/File/Directory.php +++ b/System/File/Directory.php @@ -16,7 +16,6 @@ namespace phpOMS\System\File; use phpOMS\Utils\StringUtils; -use phpOMS\Validation\Validator; /** * Filesystem class. @@ -193,7 +192,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess public static function deletePath($path) : bool { $path = realpath($oldPath = $path); - if ($path === false || !is_dir($path) || Validator::startsWith($path, ROOT_PATH)) { + if ($path === false || !is_dir($path) || StringUtils::startsWith($path, ROOT_PATH)) { throw new PathException($oldPath); } diff --git a/Views/View.php b/Views/View.php index 6c735a61f..9890673ac 100644 --- a/Views/View.php +++ b/Views/View.php @@ -20,7 +20,7 @@ use phpOMS\Localization\Localization; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\System\File\PathException; -use phpOMS\Validation\Validator; +use phpOMS\Utils\StringUtils; /** * List view. @@ -319,19 +319,35 @@ class View implements \Serializable * * @return array * + * @throws + * * @since 1.0.0 * @author Dennis Eichhorn */ public function getText(string $translation, string $module = null, string $theme = null) { - if(!isset($module)) { - $match = '/Theme/'; - $module = ($start = strripos($this->template, $match)) !== false ? substr($this->template, ($offset = $start+strlen($match)), strpos($this->template, '/', $offset)) : throw new \Exception('Unknown Theme'); + if (!isset($module)) { + $match = '/Modules/'; + + if (($start = strripos($this->template, $match)) === false) { + throw new \Exception('Unknown Module'); + } + + $start = $start + strlen($match); + $end = strpos($this->template, '/', $start); + $module = substr($this->template, $start, $end - $start); } - if(!isset($theme)) { - $match = '/Modules/'; - $module = ($start = strripos($this->template, $match)) !== false ? substr($this->template, ($offset = $start+strlen($match)), strpos($this->template, '/', $offset)) : throw new \Exception('Unknown Module'); + if (!isset($theme)) { + $match = '/Theme/'; + + if (($start = strripos($this->template, $match)) === false) { + throw new \Exception('Unknown Theme'); + } + + $start = $start + strlen($match); + $end = strpos($this->template, '/', $start); + $theme = substr($this->template, $start, $end - $start); } return $this->app->l11nManager->getText($this->l11n->getLanguage(), $module, $theme, $translation); @@ -368,7 +384,7 @@ class View implements \Serializable { $path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php'); - if ($path === false || Validator::startsWith($path, ROOT_PATH) === false) { + if ($path === false || StringUtils::startsWith($path, ROOT_PATH) === false) { throw new PathException($oldPath); }