Request class rewritten to extend BaseRequest class, ConsoleRequest added
authorRoland Häder <roland@mxchange.org>
Tue, 24 Mar 2009 06:39:34 +0000 (06:39 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 24 Mar 2009 06:39:34 +0000 (06:39 +0000)
.gitattributes
inc/classes/interfaces/request/class_Requestable.php
inc/classes/main/debug/class_DebugConsoleOutput.php
inc/classes/main/request/class_ [new file with mode: 0644]
inc/classes/main/request/class_BaseRequest.php [new file with mode: 0644]
inc/classes/main/request/class_HttpRequest.php [deleted file]
inc/classes/main/request/console/.htaccess [new file with mode: 0644]
inc/classes/main/request/console/class_ConsoleRequest.php [new file with mode: 0644]
inc/classes/main/request/web/.htaccess [new file with mode: 0644]
inc/classes/main/request/web/class_HttpRequest.php [new file with mode: 0644]

index 34429048609f38247725691200a12623812fa91d..c8d5329730aebcc7e99ddd2310cf6e2401e851d0 100644 (file)
@@ -400,7 +400,12 @@ inc/classes/main/registration/class_BaseRegistration.php -text
 inc/classes/main/registry/.htaccess -text
 inc/classes/main/registry/class_Registry.php -text
 inc/classes/main/request/.htaccess -text
-inc/classes/main/request/class_HttpRequest.php -text
+inc/classes/main/request/class_ -text
+inc/classes/main/request/class_BaseRequest.php -text
+inc/classes/main/request/console/.htaccess -text
+inc/classes/main/request/console/class_ConsoleRequest.php -text
+inc/classes/main/request/web/.htaccess -text
+inc/classes/main/request/web/class_HttpRequest.php -text
 inc/classes/main/resolver/.htaccess -text
 inc/classes/main/resolver/action/.htaccess -text
 inc/classes/main/resolver/action/class_BaseActionResolver.php -text
index c349798673d66edeb1187907e4fbfbe20f52220f..fef4e3497846a775b5ebdffcbfc50c49624ec706 100644 (file)
@@ -23,9 +23,7 @@
  */
 interface Requestable extends FrameworkInterface {
        /**
-        * Prepares the HTTP request data for usage by currently copying
-        * $_REQUEST into a private attribute. Later on we can add more
-        * things for initialization here.
+        * Prepares the request data for usage
         *
         * @return      void
         */
index 4dd9c82666ee717a6a4735ecd9e605f122063937..c397022d62c7718fa153284ea292ae724255bb51 100644 (file)
@@ -35,7 +35,7 @@ class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, Output
        /**
         * Creates an instance of this class
         *
-        * @return      $debugInstance          The prepared debug instance
+        * @return      $debugInstance  The prepared debug instance
         */
        public final static function createDebugConsoleOutput () {
                // Get a new instance
@@ -48,7 +48,7 @@ class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, Output
        /**
         * Outputs the given data without HTML tags
         *
-        * @param               $output The HTML'ed output
+        * @param       $output         The HTML'ed output
         * @return      void
         */
        public final function outputStream ($output) {
@@ -58,8 +58,8 @@ class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, Output
        /**
         * Assigns a variable for output
         *
-        * @param               $var            The variable we shall assign
-        * @param               $value  The value to store in the variable
+        * @param       $var    The variable we shall assign
+        * @param       $value  The value to store in the variable
         * @return      void
         */
        public final function assignVariable ($var, $value) {
@@ -76,7 +76,7 @@ class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, Output
                // Empty output will be silently ignored
                if ($outStream !== false) {
                        $this->outputStream($outStream);
-               }
+               } // END - if
        }
 }
 
diff --git a/inc/classes/main/request/class_ b/inc/classes/main/request/class_
new file mode 100644 (file)
index 0000000..fcfeb47
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**
+ * A concrete request class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 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 ???Request extends BaseRequest implements Requestable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class and prepares it a little
+        *
+        * @return      $httpInstance   An instance of this class
+        */
+       public final static function create???Request () {
+               // Create an instance
+               $httpInstance = new ???Request();
+
+               // Prepare the HTTP request data for usage
+               $httpInstance->prepareRequestData();
+
+               // Return the prepared instance
+               return $httpInstance;
+       }
+
+       /**
+        * Prepares the request data for usage
+        *
+        * @return      void
+        * @todo        Needs to be implemented
+        */
+       public function prepareRequestData () {
+               $this->partialStub("Please implement this method.");
+       }
+
+       /**
+        * Getter for a header element or 'null' if header was not found
+        *
+        * @param       $headerName             Name of the header
+        * @return      $headerValue    Value of the header or 'null' if not found
+        */
+       public function getHeader ($headerName) {
+               $this->partialStub("Please implement this method.");
+       }
+
+       /**
+        * Getter for request method. This getter might be useful for security filters
+        *
+        * @return      $requestMethod  Used request method
+        */
+       public final function getRequestMethod () {
+               $this->partialStub("Please implement this method.");
+               return $_SERVER['REQUEST_METHOD'];
+       }
+
+       /**
+        * Reads a cookie and returns it's value or null if not found
+        *
+        * @param       $cookieName             Name of cookie we shall read
+        * @return      $cookieValue    Value of cookie or null if not found
+        */
+       public final function readCookie ($cookieName) {
+               $this->partialStub("Please implement this method.");
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/request/class_BaseRequest.php b/inc/classes/main/request/class_BaseRequest.php
new file mode 100644 (file)
index 0000000..9364112
--- /dev/null
@@ -0,0 +1,140 @@
+<?php
+/**
+ * A general request class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 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 BaseRequest extends BaseFrameworkSystem {
+       /**
+        * Array for the request data
+        */
+       private $requestData = array();
+
+       /**
+        * Wether this request is valid and can be further processed. The default is
+        * valid so make sure your intercepting filters sets this attribute to false
+        * when they need to intercept the data flow.
+        */
+       private $requestIsValid = true;
+
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of the class
+        * @return      void
+        */
+       protected function __construct ($className) {
+               // Call parent constructor
+               parent::__construct($className);
+
+               // Clean up a little
+               $this->removeNumberFormaters();
+               $this->removeSystemArray();
+       }
+
+       /**
+        * Checks wether a request element is set
+        * @param       $element        Name of the request element we want to check
+        * @return      $isSet          Wether the request element is set
+        */
+       public function isRequestElementSet ($element) {
+               // Is this element found?
+               $isSet = isset($this->requestData[$element]);
+
+               // Return result
+               return $isSet;
+       }
+
+       /**
+        * Getter for request element or 'null' if element was not found
+        *
+        * @param       $element        Name of the request element we want to check
+        * @return      $value          Value of the found request element or 'null' if the
+        *                                              element was not found
+        */
+       public function getRequestElement ($element) {
+               // Initialize value
+               $value = null;
+
+               // Is the element set?
+               if ($this->isRequestElementSet($element)) {
+                       // Get the bare value
+                       $value = $this->requestData[$element];
+
+                       // Secure it against attacks
+                       $value = htmlentities(strip_tags($value), ENT_QUOTES);
+               } // END - if
+
+               // Return the element's value
+               return $value;
+       }
+
+       /**
+        * Setter for request elements
+        *
+        * @param       $element        Request element to se
+        * @param       $value          Value to set
+        * @return      void
+        */
+       public function setRequestElement ($element, $value) {
+               $this->requestData[$element] = $value;
+       }
+
+       /**
+        * Setter for request data array
+        *
+        * @param       $requestData    Request element to se
+        * @return      void
+        */
+       public function setRequestData (array $requestData) {
+               $this->requestData = $requestData;
+       }
+
+       /**
+        * Wrapper method for array_key() function for the request data array
+        *
+        * @return      $array  An array containing all array keys to return
+        */
+       public function getParameterNames () {
+               return array_keys($this->requestData);
+       }
+
+       /**
+        * Sets wether the request was valid (default: true)
+        *
+        * @param       $isValid        Wether the request is valid
+        * @return      void
+        */
+       public final function requestIsValid ($isValid = true) {
+               $this->requestIsValid = (bool) $isValid;
+       }
+
+       /**
+        * Returns wether this request is valid
+        *
+        * @return      $requestIsValid         Wether this request is valid
+        */
+       public final function isRequestValid () {
+               return $this->requestIsValid;
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php
deleted file mode 100644 (file)
index b7fda8c..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-<?php
-/**
- * A concrete and secured HTTP request class to make HTTP requests more abstract
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 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 HttpRequest extends BaseFrameworkSystem implements Requestable {
-       /**
-        * Array for the request data
-        */
-       private $requestData = array();
-
-       /**
-        * Wether this request is valid and can be further processed. The default is
-        * valid so make sure your intercepting filters sets this attribute to false
-        * when they need to intercept the data flow.
-        */
-       private $requestIsValid = true;
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
-       }
-
-       /**
-        * Creates an instance of this class and prepares it a little
-        *
-        * @return      $httpInstance   An instance of this class
-        */
-       public final static function createHttpRequest () {
-               // Create an instance
-               $httpInstance = new HttpRequest();
-
-               // Prepare the HTTP request data for usage
-               $httpInstance->prepareRequestData();
-
-               // Return the prepared instance
-               return $httpInstance;
-       }
-
-       /**
-        * Prepares the HTTP request data for usage by currently copying
-        * $_REQUEST into a private attribute. Later on we can add more
-        * things for initialization here.
-        *
-        * @return      void
-        */
-       public function prepareRequestData () {
-               // Copy GET then POST data
-               $this->requestData = array_merge($_GET, $_POST);
-       }
-
-       /**
-        * Checks wether a request element is set
-        * @param       $element        Name of the request element we want to check
-        * @return      $isSet          Wether the request element is set
-        */
-       public function isRequestElementSet ($element) {
-               // Is this element found?
-               $isSet = isset($this->requestData[$element]);
-
-               // Return result
-               return $isSet;
-       }
-
-       /**
-        * Getter for request element or 'null' if element was not found
-        *
-        * @param       $element        Name of the request element we want to check
-        * @return      $value          Value of the found request element or 'null' if the
-        *                                              element was not found
-        */
-       public function getRequestElement ($element) {
-               // Initialize value
-               $value = null;
-
-               // Is the element set?
-               if ($this->isRequestElementSet($element)) {
-                       // Get the bare value
-                       $value = $this->requestData[$element];
-
-                       // Secure it against attacks
-                       $value = htmlentities(strip_tags($value), ENT_QUOTES);
-               } // END - if
-
-               // Return the element's value
-               return $value;
-       }
-
-       /**
-        * Setter for request elements
-        *
-        * @param       $element        Request element to se
-        * @param       $value          Value to set
-        * @return      void
-        */
-       public function setRequestElement ($element, $value) {
-               $this->requestData[$element] = $value;
-       }
-
-       /**
-        * Wrapper method for array_key() function for the request data array
-        *
-        * @return      $array  An array containing all array keys to return
-        */
-       public function getParameterNames () {
-               return array_keys($this->requestData);
-       }
-
-       /**
-        * Getter for a header element or 'null' if header was not found
-        *
-        * @param       $headerName             Name of the header
-        * @return      $headerValue    Value of the header or 'null' if not found
-        */
-       public function getHeader ($headerName) {
-               // Default return value on error
-               $headerValue = null;
-
-               // Construct the name
-               $name = 'HTTP_' . strtolower($this->convertDashesToUnderscores($headerName));
-
-               // Does this header exist?
-               if (isset($_SERVER[$name])) {
-                       $headerValue = $_SERVER[$name];
-               } // END - if
-
-               // Return the value
-               return $headerValue;
-       }
-
-       /**
-        * Getter for request method. This getter might be useful for security filters
-        *
-        * @return      $requestMethod  Used request method
-        */
-       public final function getRequestMethod () {
-               return $_SERVER['REQUEST_METHOD'];
-       }
-
-       /**
-        * Sets wether the request was valid (default: true)
-        *
-        * @param       $isValid        Wether the request is valid
-        * @return      void
-        */
-       public final function requestIsValid ($isValid = true) {
-               $this->requestIsValid = (bool) $isValid;
-       }
-
-       /**
-        * Returns wether this request is valid
-        *
-        * @return      $requestIsValid         Wether this request is valid
-        */
-       public final function isRequestValid () {
-               return $this->requestIsValid;
-       }
-
-       /**
-        * Reads a cookie and returns it's value or null if not found
-        *
-        * @param       $cookieName             Name of cookie we shall read
-        * @return      $cookieValue    Value of cookie or null if not found
-        */
-       public final function readCookie ($cookieName) {
-               // Default is no cookie with that name found
-               $cookieValue = null;
-
-               // Is the cookie set?
-               if (isset($_COOKIE[$cookieName])) {
-                       // Then get it
-                       $cookieValue = $_COOKIE[$cookieName];
-               } // END - if
-
-               // Return the value
-               return $cookieValue;
-       }
-}
-
-// [EOF]
-?>
diff --git a/inc/classes/main/request/console/.htaccess b/inc/classes/main/request/console/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/request/console/class_ConsoleRequest.php b/inc/classes/main/request/console/class_ConsoleRequest.php
new file mode 100644 (file)
index 0000000..3ac92eb
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**
+ * A concrete request class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 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 ConsoleRequest extends BaseRequest implements Requestable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class and prepares it a little
+        *
+        * @return      $httpInstance   An instance of this class
+        */
+       public final static function createConsoleRequest () {
+               // Create an instance
+               $httpInstance = new ConsoleRequest();
+
+               // Prepare the console request data for usage
+               $httpInstance->prepareRequestData();
+
+               // Return the prepared instance
+               return $httpInstance;
+       }
+
+       /**
+        * Prepares the request data for usage
+        *
+        * @return      void
+        * @todo        Needs to be implemented
+        */
+       public function prepareRequestData () {
+               $this->partialStub("Please implement this method.");
+       }
+
+       /**
+        * Getter for a header element or 'null' if header was not found
+        *
+        * @param       $headerName             Name of the header
+        * @return      $headerValue    Value of the header or 'null' if not found
+        */
+       public function getHeader ($headerName) {
+               $this->partialStub("Please implement this method.");
+       }
+
+       /**
+        * Getter for request method. This getter might be useful for security filters
+        *
+        * @return      $requestMethod  Used request method
+        */
+       public final function getRequestMethod () {
+               $this->partialStub("Please implement this method.");
+               return $_SERVER['REQUEST_METHOD'];
+       }
+
+       /**
+        * Reads a cookie and returns it's value or null if not found
+        *
+        * @param       $cookieName             Name of cookie we shall read
+        * @return      $cookieValue    Value of cookie or null if not found
+        */
+       public final function readCookie ($cookieName) {
+               $this->partialStub("Please implement this method.");
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/request/web/.htaccess b/inc/classes/main/request/web/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/request/web/class_HttpRequest.php b/inc/classes/main/request/web/class_HttpRequest.php
new file mode 100644 (file)
index 0000000..3979115
--- /dev/null
@@ -0,0 +1,116 @@
+<?php
+/**
+ * A concrete and secured HTTP request class to make HTTP requests more abstract
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 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 HttpRequest extends BaseRequest implements Requestable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class and prepares it a little
+        *
+        * @return      $httpInstance   An instance of this class
+        */
+       public final static function createHttpRequest () {
+               // Create an instance
+               $httpInstance = new HttpRequest();
+
+               // Prepare the HTTP request data for usage
+               $httpInstance->prepareRequestData();
+
+               // Return the prepared instance
+               return $httpInstance;
+       }
+
+       /**
+        * Prepares the HTTP request data for usage by currently copying
+        * $_REQUEST into a private attribute. Later on we can add more
+        * things for initialization here.
+        *
+        * @return      void
+        */
+       public function prepareRequestData () {
+               // Copy GET then POST data
+               $this->setRequestData(array_merge($_GET, $_POST));
+       }
+
+       /**
+        * Getter for a header element or 'null' if header was not found
+        *
+        * @param       $headerName             Name of the header
+        * @return      $headerValue    Value of the header or 'null' if not found
+        */
+       public function getHeader ($headerName) {
+               // Default return value on error
+               $headerValue = null;
+
+               // Construct the name
+               $name = 'HTTP_' . strtolower($this->convertDashesToUnderscores($headerName));
+
+               // Does this header exist?
+               if (isset($_SERVER[$name])) {
+                       $headerValue = $_SERVER[$name];
+               } // END - if
+
+               // Return the value
+               return $headerValue;
+       }
+
+       /**
+        * Getter for request method. This getter might be useful for security filters
+        *
+        * @return      $requestMethod  Used request method
+        */
+       public final function getRequestMethod () {
+               return $_SERVER['REQUEST_METHOD'];
+       }
+
+       /**
+        * Reads a cookie and returns it's value or null if not found
+        *
+        * @param       $cookieName             Name of cookie we shall read
+        * @return      $cookieValue    Value of cookie or null if not found
+        */
+       public final function readCookie ($cookieName) {
+               // Default is no cookie with that name found
+               $cookieValue = null;
+
+               // Is the cookie set?
+               if (isset($_COOKIE[$cookieName])) {
+                       // Then get it
+                       $cookieValue = $_COOKIE[$cookieName];
+               } // END - if
+
+               // Return the value
+               return $cookieValue;
+       }
+}
+
+// [EOF]
+?>