From 092ce40f75f8c493f6a1eac28cbbaa50a4362df7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 4 Mar 2017 22:49:53 +0100 Subject: [PATCH] rewrote to SPL exceptions as these exceptions are really overdue ... MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../console/class_ConsoleTemplateEngine.php | 10 ++-- .../html/class_HtmlTemplateEngine.php | 10 ++-- .../image/class_ImageTemplateEngine.php | 10 ++-- .../mail/class_MailTemplateEngine.php | 10 ++-- .../menu/class_MenuTemplateEngine.php | 10 ++-- .../class_BasePathIsEmptyException.php | 50 +----------------- .../class_BasePathIsNoDirectoryException.php | 2 +- .../class_InvalidBasePathStringException.php | 51 +------------------ 8 files changed, 33 insertions(+), 120 deletions(-) diff --git a/framework/main/classes/template/console/class_ConsoleTemplateEngine.php b/framework/main/classes/template/console/class_ConsoleTemplateEngine.php index 09aadd22..e4ca45eb 100644 --- a/framework/main/classes/template/console/class_ConsoleTemplateEngine.php +++ b/framework/main/classes/template/console/class_ConsoleTemplateEngine.php @@ -6,6 +6,9 @@ namespace CoreFramework\Template\Engine; use CoreFramework\Registry\Registry; use CoreFramework\Template\CompileableTemplate; +// Import SPL stuff +use \UnexpectedValueException; + /** * A Console template engine class * @@ -44,8 +47,7 @@ class ConsoleTemplateEngine extends BaseTemplateEngine implements CompileableTem * Creates an instance of the class TemplateEngine and prepares it for usage * * @return $templateInstance An instance of TemplateEngine - * @throws BasePathIsEmptyException If the provided $templateBasePath is empty - * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws UnexpectedValueException If the provided $templateBasePath is empty or no string * @throws BasePathIsNoDirectoryException If $templateBasePath is no * directory or not found * @throws BasePathReadProtectedException If $templateBasePath is @@ -64,10 +66,10 @@ class ConsoleTemplateEngine extends BaseTemplateEngine implements CompileableTem // Is the base path valid? if (empty($templateBasePath)) { // Base path is empty - throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } elseif (!is_string($templateBasePath)) { // Is not a string - throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/html/class_HtmlTemplateEngine.php b/framework/main/classes/template/html/class_HtmlTemplateEngine.php index 32b16fad..9fd2f285 100644 --- a/framework/main/classes/template/html/class_HtmlTemplateEngine.php +++ b/framework/main/classes/template/html/class_HtmlTemplateEngine.php @@ -6,6 +6,9 @@ namespace CoreFramework\Template\Engine; use CoreFramework\Registry\Registry; use CoreFramework\Template\CompileableTemplate; +// Import SPL stuff +use \UnexpectedValueException; + /** * The own template engine for loading caching and sending out the web pages * and emails. @@ -44,8 +47,7 @@ class HtmlTemplateEngine extends BaseTemplateEngine implements CompileableTempla * Creates an instance of the class TemplateEngine and prepares it for usage * * @return $templateInstance An instance of TemplateEngine - * @throws BasePathIsEmptyException If the provided $templateBasePath is empty - * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws UnexpectedValueException If the provided $templateBasePath is empty or no string * @throws BasePathIsNoDirectoryException If $templateBasePath is no * directory or not found * @throws BasePathReadProtectedException If $templateBasePath is @@ -64,10 +66,10 @@ class HtmlTemplateEngine extends BaseTemplateEngine implements CompileableTempla // Is the base path valid? if (empty($templateBasePath)) { // Base path is empty - throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } elseif (!is_string($templateBasePath)) { // Is not a string - throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/image/class_ImageTemplateEngine.php b/framework/main/classes/template/image/class_ImageTemplateEngine.php index 950b8867..3dbdb96d 100644 --- a/framework/main/classes/template/image/class_ImageTemplateEngine.php +++ b/framework/main/classes/template/image/class_ImageTemplateEngine.php @@ -9,6 +9,9 @@ use CoreFramework\Registry\Registry; use CoreFramework\Response\Responseable; use CoreFramework\Template\CompileableTemplate; +// Import SPL stuff +use \UnexpectedValueException; + /** * The own template engine for loading caching and sending out images * @@ -80,8 +83,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl * Creates an instance of the class TemplateEngine and prepares it for usage * * @return $templateInstance An instance of TemplateEngine - * @throws BasePathIsEmptyException If the provided $templateBasePath is empty - * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws UnexpectedValueException If the provided $templateBasePath is empty or no string * @throws BasePathIsNoDirectoryException If $templateBasePath is no * directory or not found * @throws BasePathReadProtectedException If $templateBasePath is @@ -100,10 +102,10 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl // Is the base path valid? if (empty($templateBasePath)) { // Base path is empty - throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } elseif (!is_string($templateBasePath)) { // Is not a string - throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/mail/class_MailTemplateEngine.php b/framework/main/classes/template/mail/class_MailTemplateEngine.php index 78b6dcc6..04e59829 100644 --- a/framework/main/classes/template/mail/class_MailTemplateEngine.php +++ b/framework/main/classes/template/mail/class_MailTemplateEngine.php @@ -9,6 +9,9 @@ use CoreFramework\Registry\Registry; use CoreFramework\Response\Responseable; use CoreFramework\Template\CompileableTemplate; +// Import SPL stuff +use \UnexpectedValueException; + /** * The own template engine for loading caching and sending out images * @@ -74,8 +77,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla * Creates an instance of the class TemplateEngine and prepares it for usage * * @return $templateInstance An instance of TemplateEngine - * @throws BasePathIsEmptyException If the provided $templateBasePath is empty - * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws UnexpectedValueException If the provided $templateBasePath is empty or no string * @throws BasePathIsNoDirectoryException If $templateBasePath is no * directory or not found * @throws BasePathReadProtectedException If $templateBasePath is @@ -94,10 +96,10 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla // Is the base path valid? if (empty($templateBasePath)) { // Base path is empty - throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } elseif (!is_string($templateBasePath)) { // Is not a string - throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/menu/class_MenuTemplateEngine.php b/framework/main/classes/template/menu/class_MenuTemplateEngine.php index 6663f8ad..e21e97df 100644 --- a/framework/main/classes/template/menu/class_MenuTemplateEngine.php +++ b/framework/main/classes/template/menu/class_MenuTemplateEngine.php @@ -8,6 +8,9 @@ use CoreFramework\Parser\Xml\XmlParser; use CoreFramework\Registry\Registry; use CoreFramework\Template\CompileableTemplate; +// Import SPL stuff +use \UnexpectedValueException; + /** * A Menu template engine class * @@ -134,8 +137,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla * * @param $menuInstance A RenderableMenu instance * @return $templateInstance An instance of TemplateEngine - * @throws BasePathIsEmptyException If the provided $templateBasePath is empty - * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws UnexpectedValueException If the found $templateBasePath is empty or not a string * @throws BasePathIsNoDirectoryException If $templateBasePath is no * directory or not found * @throws BasePathReadProtectedException If $templateBasePath is @@ -154,10 +156,10 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla // Is the base path valid? if (empty($templateBasePath)) { // Base path is empty - throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } elseif (!is_string($templateBasePath)) { // Is not a string - throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/exceptions/template/class_BasePathIsEmptyException.php b/framework/main/exceptions/template/class_BasePathIsEmptyException.php index 1e553acb..7d6dceec 100644 --- a/framework/main/exceptions/template/class_BasePathIsEmptyException.php +++ b/framework/main/exceptions/template/class_BasePathIsEmptyException.php @@ -1,50 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * 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 3 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, see . - */ -class BasePathIsEmptyException extends FrameworkException { - /** - * The constructor - * - * @param $class Class throwing this exception - * @param $code Code number for the exception - * @return void - */ - public function __construct (FrameworkInterface $class, $code) { - // Add a message around the missing class - $message = sprintf('[%s:%d] Template path is empty.', - $class->__toString(), - $this->getLine() - ); - - // Call parent constructor - parent::__construct($message, $code); - } - -} +// @DEPRECATED diff --git a/framework/main/exceptions/template/class_BasePathIsNoDirectoryException.php b/framework/main/exceptions/template/class_BasePathIsNoDirectoryException.php index 6773481b..eeb095f3 100644 --- a/framework/main/exceptions/template/class_BasePathIsNoDirectoryException.php +++ b/framework/main/exceptions/template/class_BasePathIsNoDirectoryException.php @@ -38,7 +38,7 @@ class BasePathIsNoDirectoryException extends FrameworkException { */ public function __construct (array $classArray, $code) { // Add a message around the missing class - $message = sprintf('[%s:%d] Template base path %s does not exist.', + $message = sprintf('[%s:%d] Template base path "%s" does not exist.', $classArray[0]->__toString(), $this->getLine(), $classArray[1] diff --git a/framework/main/exceptions/template/class_InvalidBasePathStringException.php b/framework/main/exceptions/template/class_InvalidBasePathStringException.php index 2b07d3da..7d6dceec 100644 --- a/framework/main/exceptions/template/class_InvalidBasePathStringException.php +++ b/framework/main/exceptions/template/class_InvalidBasePathStringException.php @@ -1,51 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * @deprecated Don't use this anymore - * - * 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 3 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, see . - */ -class InvalidBasePathStringException extends FrameworkException { - /** - * The constructor - * - * @param $classArray Array holding exception data - * @param $code Code number for the exception - * @return void - */ - public function __construct (array $classArray, $code) { - // Add a message around the missing class - $message = sprintf('[%s:%d] %s is not a string with a base path.', - $classArray[0]->__toString(), - $this->getLine(), - $classArray[1] - ); - - // Call parent constructor - parent::__construct($message, $code); - } - -} +// @DEPRECATED -- 2.39.2