From 0ff6b6dd6f297dc3257f8a4687ca514a2c60cd28 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 20 Jul 2011 00:32:03 +0000 Subject: [PATCH] More concrete exceptions added, BaseController rewritten: - Exceptions added, please use these instead of InvalidSocketExceptio - All filters in BaseController are now named in class constants --- .gitattributes | 3 ++ .../class_SocketConnectionException.php | 49 +++++++++++++++++++ .../socket/class_SocketCreationException.php | 49 +++++++++++++++++++ .../socket/class_SocketOptionException.php | 49 +++++++++++++++++++ .../socket/class_SocketShutdownException.php | 6 +-- .../resolver/state/class_StateResolver.php | 6 +-- .../main/controller/class_BaseController.php | 16 +++--- 7 files changed, 166 insertions(+), 12 deletions(-) create mode 100644 inc/classes/exceptions/socket/class_SocketConnectionException.php create mode 100644 inc/classes/exceptions/socket/class_SocketCreationException.php create mode 100644 inc/classes/exceptions/socket/class_SocketOptionException.php diff --git a/.gitattributes b/.gitattributes index cbc08e5a..679412da 100644 --- a/.gitattributes +++ b/.gitattributes @@ -95,6 +95,9 @@ inc/classes/exceptions/socket/.htaccess svneol=native#text/plain inc/classes/exceptions/socket/class_InvalidServerSocketException.php svneol=native#text/plain inc/classes/exceptions/socket/class_InvalidSocketException.php svneol=native#text/plain inc/classes/exceptions/socket/class_NoSocketRegisteredException.php svneol=native#text/plain +inc/classes/exceptions/socket/class_SocketConnectionException.php svneol=native#text/plain +inc/classes/exceptions/socket/class_SocketCreationException.php svneol=native#text/plain +inc/classes/exceptions/socket/class_SocketOptionException.php svneol=native#text/plain inc/classes/exceptions/socket/class_SocketShutdownException.php svneol=native#text/plain inc/classes/exceptions/stacker/.htaccess svneol=native#text/plain inc/classes/exceptions/stacker/class_AlreadyInitializedStackerException.php svneol=native#text/plain diff --git a/inc/classes/exceptions/socket/class_SocketConnectionException.php b/inc/classes/exceptions/socket/class_SocketConnectionException.php new file mode 100644 index 00000000..2e53617d --- /dev/null +++ b/inc/classes/exceptions/socket/class_SocketConnectionException.php @@ -0,0 +1,49 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 SocketConnectionException extends FrameworkException { + /** + * A Constructor for this exception + * + * @param $messageArray Error message array + * @param $code Error code + * @return void + */ + public function __construct (array $messageData, $code) { + // Construct the message + $message = sprintf("[%s:] Could not make a connection! (type %s != resource). errno=%s, errstr=%s", + $messageData[0]->__toString(), + $messageData[1], + $messageData[2], + $messageData[3] + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/socket/class_SocketCreationException.php b/inc/classes/exceptions/socket/class_SocketCreationException.php new file mode 100644 index 00000000..12155de4 --- /dev/null +++ b/inc/classes/exceptions/socket/class_SocketCreationException.php @@ -0,0 +1,49 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 SocketCreationException extends FrameworkException { + /** + * A Constructor for this exception + * + * @param $messageArray Error message array + * @param $code Error code + * @return void + */ + public function __construct (array $messageData, $code) { + // Construct the message + $message = sprintf("[%s:] Cannot create socket (type %s != resource). errno=%s, errstr=%s", + $messageData[0]->__toString(), + $messageData[1], + $messageData[2], + $messageData[3] + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/socket/class_SocketOptionException.php b/inc/classes/exceptions/socket/class_SocketOptionException.php new file mode 100644 index 00000000..c63a0ada --- /dev/null +++ b/inc/classes/exceptions/socket/class_SocketOptionException.php @@ -0,0 +1,49 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 SocketOptionException extends FrameworkException { + /** + * A Constructor for this exception + * + * @param $messageArray Error message array + * @param $code Error code + * @return void + */ + public function __construct (array $messageData, $code) { + // Construct the message + $message = sprintf("[%s:] Changing option on socket failed! (type %s != resource). errno=%s, errstr=%s", + $messageData[0]->__toString(), + $messageData[1], + $messageData[2], + $messageData[3] + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/socket/class_SocketShutdownException.php b/inc/classes/exceptions/socket/class_SocketShutdownException.php index 0305f445..9311677a 100644 --- a/inc/classes/exceptions/socket/class_SocketShutdownException.php +++ b/inc/classes/exceptions/socket/class_SocketShutdownException.php @@ -26,11 +26,11 @@ class SocketShutdownException extends FrameworkException { /** * A Constructor for this exception * - * @param $helperInstance A BaseConnectionHelper instance - * @param $code Error code + * @param $helperInstance A ConnectionHelper instance + * @param $code Error code * @return void */ - public function __construct (BaseConnectionHelper $helperInstance, $code) { + public function __construct (ConnectionHelper $helperInstance, $code) { // Get socket resource $socketResource = $helperInstance->getSocketResource(); diff --git a/inc/classes/interfaces/resolver/state/class_StateResolver.php b/inc/classes/interfaces/resolver/state/class_StateResolver.php index 6df3a6b2..d94d34a6 100644 --- a/inc/classes/interfaces/resolver/state/class_StateResolver.php +++ b/inc/classes/interfaces/resolver/state/class_StateResolver.php @@ -23,14 +23,14 @@ */ interface StateResolver extends Resolver { /** - * Returns an state instance for a given package class and raw data + * Returns an state instance for a given package raw data and socket resource * - * @param $packageInstance An instance of a package class + * @param $helperInstance An instance of a ConnectionHelper class * @param $packageData Raw package data * @param $socketResource A valid socket resource * @return $stateInstance An instance of the resolved state */ - function resolveStateByPackage (Networkable $packageInstance, array $packageData, $socketResource); + static function resolveStateByPackage (ConnectionHelper $helperInstance, array $packageData, $socketResource); /** * Checks wether the given state is valid diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index ba28c276..44be9968 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -32,6 +32,10 @@ class BaseController extends BaseFrameworkSystem implements Registerable { // Exception constants const EXCEPTION_FILTER_CHAIN_INVALID = 0xf10; + // Names of controller's own filter chains + const FILTER_CHAIN_PRE_COMMAND = 'controller_pre_command'; + const FILTER_CHAIN_POST_COMMAND = 'controller_post_command'; + /** * Protected constructor * @@ -43,8 +47,8 @@ class BaseController extends BaseFrameworkSystem implements Registerable { parent::__construct($className); // Initialize both filter chains - $this->initFilterChain('pre'); - $this->initFilterChain('post'); + $this->initFilterChain(self::FILTER_CHAIN_PRE_COMMAND); + $this->initFilterChain(self::FILTER_CHAIN_POST_COMMAND); // Add this controller to the registry Registry::getRegistry()->addInstance('controller', $this); @@ -92,7 +96,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ public function addPreFilter (Filterable $filterInstance) { // Add the pre filter - $this->addFilter('pre', $filterInstance); + $this->addFilter(self::FILTER_CHAIN_PRE_COMMAND, $filterInstance); } /** @@ -103,7 +107,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ public function addPostFilter (Filterable $filterInstance) { // Add the post filter - $this->addFilter('post', $filterInstance); + $this->addFilter(self::FILTER_CHAIN_POST_COMMAND, $filterInstance); } /** @@ -135,7 +139,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) { // Execute all pre filters - $this->executeFilters('pre', $requestInstance, $responseInstance); + $this->executeFilters(self::FILTER_CHAIN_PRE_COMMAND, $requestInstance, $responseInstance); } /** @@ -147,7 +151,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable { */ protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) { // Execute all post filters - $this->executeFilters('post', $requestInstance, $responseInstance); + $this->executeFilters(self::FILTER_CHAIN_POST_COMMAND, $requestInstance, $responseInstance); } } -- 2.30.2