X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=framework%2Fmain%2Fclasses%2Frequest%2Fclass_BaseRequest.php;fp=framework%2Fmain%2Fclasses%2Frequest%2Fclass_BaseRequest.php;h=49130652be6920de855df4fd326870ad81fc034d;hb=78a010fef84895720e796842208f01dfb619c332;hp=0000000000000000000000000000000000000000;hpb=7629f2314d517561d4301ddfb068a797b6ed8700;p=core.git diff --git a/framework/main/classes/request/class_BaseRequest.php b/framework/main/classes/request/class_BaseRequest.php new file mode 100644 index 00000000..49130652 --- /dev/null +++ b/framework/main/classes/request/class_BaseRequest.php @@ -0,0 +1,140 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 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 . + */ +class BaseRequest extends BaseFrameworkSystem { + /** + * Array for the request data + */ + private $requestData = array(); + + /** + * Whether 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); + } + + /** + * Checks whether a request element is set + * @param $element Name of the request element we want to check + * @return $isSet Whether 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 whether the request was valid (default: TRUE) + * + * @param $isValid Whether the request is valid + * @return void + */ + public final function requestIsValid ($isValid = TRUE) { + $this->requestIsValid = (bool) $isValid; + } + + /** + * Returns whether this request is valid + * + * @return $requestIsValid Whether this request is valid + */ + public final function isRequestValid () { + return $this->requestIsValid; + } + +}