]> git.mxchange.org Git - core.git/commitdiff
More concrete exceptions added, BaseController rewritten:
authorRoland Häder <roland@mxchange.org>
Wed, 20 Jul 2011 00:32:03 +0000 (00:32 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 20 Jul 2011 00:32:03 +0000 (00:32 +0000)
- Exceptions added, please use these instead of InvalidSocketExceptio
- All filters in BaseController are now named in class constants

.gitattributes
inc/classes/exceptions/socket/class_SocketConnectionException.php [new file with mode: 0644]
inc/classes/exceptions/socket/class_SocketCreationException.php [new file with mode: 0644]
inc/classes/exceptions/socket/class_SocketOptionException.php [new file with mode: 0644]
inc/classes/exceptions/socket/class_SocketShutdownException.php
inc/classes/interfaces/resolver/state/class_StateResolver.php
inc/classes/main/controller/class_BaseController.php

index cbc08e5aea6626cc20933c2a844bb5501e2ea838..679412da2dce4a4610d85947424a6ce25389e05b 100644 (file)
@@ -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 (file)
index 0000000..2e53617
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/**
+ * This exception is thrown when socket_connection() could not succeed. This
+ * means a lot: the connection was refused by other peer (no open port; mostly
+ * with TCP connections), broken pipes and so on ...
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..12155de
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/**
+ * This exception is thrown when socket_create() returns a variable with
+ * non-resource type. This could mean you don't have propper permission to
+ * create a socket or else. (Sorry I don't know it exactly)
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..c63a0ad
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/**
+ * This exception is thrown when an option could not be set on given socket
+ * resource. This means that the socket could be (somehow) created but cannot
+ * be altered (as usual with non-blocking connections).
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 0305f4455a6311b98bafd74f44f09502955d268f..9311677a53399542d6e9b31a704d4344b57fc50f 100644 (file)
@@ -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();
 
index 6df3a6b2f45b18f389e90aaa4b55b6d93b351aa8..d94d34a67f9348fd88e9423df46a954cf99c3e95 100644 (file)
  */
 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
index ba28c2768da76e5da26aa0751991feef8bbb4544..44be9968aad22c8a488dc39f9480e299745e6504 100644 (file)
@@ -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);
        }
 }