--- /dev/null
+<?php
+/**
+ * A concrete 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, this is free software
+ * @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();
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set part description
+ $this->setObjectDescription("HTTP-Anfrage");
+
+ // Create unique ID number
+ $this->createUniqueID();
+
+ // 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 the $_REQUEST array
+ $this->requestData = $_REQUEST;
+ }
+
+ /**
+ * 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
+ * @throws MissingArrayElementsException Thrown if a request element is not set
+ */
+ public function isRequestElementSet ($element) {
+ // Is this element found?
+ if (!isset($this->requestData[$element])) {
+ // Then throw an exception
+ throw new MissingArrayElementsException(array($this, 'requestData', $element), self::EXCEPTION_MISSING_ELEMENT);
+ }
+
+ // All clear
+ return true;
+ }
+
+ /**
+ * Getter for request element or 'null' if the 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;
+
+ try {
+ if ($this->isRequestElementSet($element)) {
+ $value = $this->requestData[$element];
+ }
+ } catch (MissingArrayElementsException $e) {
+ // Do nothing here
+ }
+
+ // Return the element's value
+ return $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 the 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(str_replace('-', '_', $headerName));
+
+ // Does this header exist?
+ if (isset($_SERVER[$name])) {
+ $headerValue = $_SERVER[$name];
+ }
+
+ // Return the value
+ return $headerValue;
+ }
+}
+
+// [EOF]
+?>