3 namespace Org\Mxchange\CoreFramework\Request;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
7 use Org\Mxchange\CoreFramework\Request\Requestable;
10 * A concrete request class
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 <<<<<<< HEAD:framework/main/classes/request/console/class_ConsoleRequest.php
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
18 >>>>>>> Some updates::inc/main/classes/request/console/class_ConsoleRequest.php
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.shipsimu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class ConsoleRequest extends BaseRequest implements Requestable {
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
47 * Creates an instance of this class and prepares it a little
49 * @return $consoleInstance An instance of this class
51 public static final function createConsoleRequest () {
53 $consoleInstance = new ConsoleRequest();
55 // Prepare the console request data for usage
56 $consoleInstance->prepareRequestData();
58 // Return the prepared instance
59 return $consoleInstance;
63 * Prepares the request data for usage
67 protected function prepareRequestData () {
68 // 'argv' and 'argc' should be there
69 if ((!isset($_SERVER['argv'])) || (!isset($_SERVER['argc']))) {
70 // Maybe not right PHP mode? (needs CLI?)
71 trigger_error(sprintf('[%s:%d]: argv/argc not set: %s', __METHOD__, __LINE__, print_r($_SERVER, true)), E_USER_ERROR);
74 // Get the "request data" from the command-line argument list
75 $args = $_SERVER['argv'];
77 // Are there less than two parameters?
78 if ($_SERVER['argc'] < 2) {
83 // Is the first element "index.php" ?
84 if ($args[0] == 'index.php') {
89 // Try to determine next parameters
90 foreach ($args as $arg) {
91 // Seperate argument key from value
92 $argArray = explode('=', $arg);
94 // Is the second one set?
95 if (!isset($argArray[1])) {
96 // Add it likewise, but empty value
97 $this->setRequestElement($argArray[0], '');
99 // Set a name=value pair escaped and secured
100 $this->setRequestElement($argArray[0], escapeshellcmd($argArray[1]));
106 * Getter for a header element or 'null' if header was not found
108 * @param $headerName Name of the header
109 * @return $headerValue Value of the header or 'null' if not found
110 * @throws UnsupportedOperationException This method should never be called
112 public function getHeaderElement ($headerName) {
113 // Console doesn't have any headers
114 throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
118 * Getter for request method. This getter might be useful for security filters
120 * @return $requestMethod Used request method
122 public final function getRequestMethod () {
123 // @TODO Can't this be 'CONSOLE' ?
128 * Reads a cookie and returns it's value or null if not found
130 * @param $cookieName Name of cookie we shall read
131 * @return $cookieValue Value of cookie or null if not found
132 * @throws UnsupportedOperationException This method should never be called
134 public final function readCookie ($cookieName) {
135 // There are no cookies on console
136 throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
140 * Checks if the request method is GET.
142 * @return $isGet Whether the request method is GET
143 * @throws UnsupportedOperationException This method should never be called
145 public function isGetRequestMethod () {
146 // Not support method
147 throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
151 * Checks if the request method is HEAD.
153 * @return $isHead Whether the request method is HEAD
154 * @throws UnsupportedOperationException This method should never be called
156 public function isHeadRequestMethod () {
157 // Not support method
158 throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
162 * Checks if the request method is POST.
164 * @return $isPost Whether the request method is POST
165 * @throws UnsupportedOperationException This method should never be called
167 public function isPostRequestMethod () {
168 // Not support method
169 throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION);