X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Frequest%2Fconsole%2Fclass_ConsoleRequest.php;h=12b10db1e202b7df70be38eadb5e87920e0b1c9a;hp=3ac92eb87a269cbcb54bf7df8b361c5f88351c48;hb=66e68715d3d5a5e7fd5a3046471914ef3f9dd4b4;hpb=bbebbec0a156ebc2e6255fb80adadb50d79c1b6f diff --git a/inc/classes/main/request/console/class_ConsoleRequest.php b/inc/classes/main/request/console/class_ConsoleRequest.php index 3ac92eb8..12b10db1 100644 --- a/inc/classes/main/request/console/class_ConsoleRequest.php +++ b/inc/classes/main/request/console/class_ConsoleRequest.php @@ -2,11 +2,11 @@ /** * A concrete request class * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @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 @@ -37,7 +37,7 @@ class ConsoleRequest extends BaseRequest implements Requestable { * * @return $httpInstance An instance of this class */ - public final static function createConsoleRequest () { + public static final function createConsoleRequest () { // Create an instance $httpInstance = new ConsoleRequest(); @@ -52,10 +52,37 @@ class ConsoleRequest extends BaseRequest implements Requestable { * Prepares the request data for usage * * @return void - * @todo Needs to be implemented */ public function prepareRequestData () { - $this->partialStub("Please implement this method."); + // Get the "request data" from the command-line argument list + $args = $_SERVER['argv']; + + // Are there less than two parameters? + if ($_SERVER['argc'] < 2) { + // Skip this + return; + } // END - if + + // Is the first element "index.php" ? + if ($args[0] == 'index.php') { + // Then remove it + array_shift($args); + } // END - if + + // Try to determine next parameters + foreach ($args as $arg) { + // Seperate arguemnt name from value + $argArray = explode('=', $arg); + + // Is the second one set? + if (!isset($argArray[1])) { + // Add it likewise, but empty value + $this->setRequestElement($argArray[0], ''); + } else { + // Set a name=value pair escaped and secured + $this->setRequestElement($argArray[0], escapeshellcmd($argArray[1])); + } + } // END - foreach } /** @@ -63,9 +90,11 @@ class ConsoleRequest extends BaseRequest implements Requestable { * * @param $headerName Name of the header * @return $headerValue Value of the header or 'null' if not found + * @throws UnsupportedOperationException This method should never be called */ public function getHeader ($headerName) { - $this->partialStub("Please implement this method."); + // Console doesn't have any headers + throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION); } /** @@ -74,8 +103,8 @@ class ConsoleRequest extends BaseRequest implements Requestable { * @return $requestMethod Used request method */ public final function getRequestMethod () { - $this->partialStub("Please implement this method."); - return $_SERVER['REQUEST_METHOD']; + // @TODO Can't this be 'CONSOLE' ? + return 'LOCAL'; } /** @@ -83,9 +112,11 @@ class ConsoleRequest extends BaseRequest implements Requestable { * * @param $cookieName Name of cookie we shall read * @return $cookieValue Value of cookie or null if not found + * @throws UnsupportedOperationException This method should never be called */ public final function readCookie ($cookieName) { - $this->partialStub("Please implement this method."); + // There are no cookies on console + throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION); } }