+++ /dev/null
-<?php
-/**
- * A concrete request class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @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
- * 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 static final 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
- */
- public function prepareRequestData () {
- // 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
- }
-
- /**
- * 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
- * @throws UnsupportedOperationException This method should never be called
- */
- public function getHeaderElement ($headerName) {
- // Console doesn't have any headers
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Getter for request method. This getter might be useful for security filters
- *
- * @return $requestMethod Used request method
- */
- public final function getRequestMethod () {
- // @TODO Can't this be 'CONSOLE' ?
- return 'LOCAL';
- }
-
- /**
- * 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
- * @throws UnsupportedOperationException This method should never be called
- */
- public final function readCookie ($cookieName) {
- // There are no cookies on console
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Checks if the request method is GET.
- *
- * @return $isGet Whether the request method is GET
- * @throws UnsupportedOperationException This method should never be called
- */
- public function isGetRequestMethod () {
- // Not support method
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Checks if the request method is HEAD.
- *
- * @return $isHead Whether the request method is HEAD
- * @throws UnsupportedOperationException This method should never be called
- */
- public function isHeadRequestMethod () {
- // Not support method
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Checks if the request method is POST.
- *
- * @return $isPost Whether the request method is POST
- * @throws UnsupportedOperationException This method should never be called
- */
- public function isPostRequestMethod () {
- // Not support method
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>