mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-09 23:14:29 -06:00
71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
|
|
*/
|
|
|
|
/**
|
|
* Description of BaseController
|
|
*
|
|
* @author SCTN4
|
|
*/
|
|
class BaseController {
|
|
|
|
static function create() { return new self(); }
|
|
/**
|
|
* __call magic method.
|
|
*/
|
|
public function __call($name, $arguments)
|
|
{
|
|
$this->sendOutput('', array('HTTP/1.1 404 Not Found'));
|
|
}
|
|
/**
|
|
* Get URI elements.
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getUriSegments()
|
|
{
|
|
$requestUri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING); /*htmlspecialchars()*/
|
|
$parsedUri = parse_url($requestUri, PHP_URL_PATH);
|
|
$uri = explode( '/', $parsedUri );
|
|
return $uri;
|
|
}
|
|
/**
|
|
* Get querystring params.
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getQueryStringParams()
|
|
{
|
|
$query = array();
|
|
$queryString = filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_STRING); /*htmlspecialchars()*/
|
|
parse_str($queryString, $query);
|
|
return $query;
|
|
}
|
|
|
|
protected function getServerRequestMethod()
|
|
{
|
|
$requestMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING); /*htmlspecialchars()*/
|
|
return $requestMethod;
|
|
}
|
|
/**
|
|
* Send API output.
|
|
*
|
|
* @param mixed $data
|
|
* @param string $httpHeader
|
|
*/
|
|
protected function sendOutput($data, $httpHeaders=array())
|
|
{
|
|
header_remove('Set-Cookie');
|
|
if (is_array($httpHeaders) && count($httpHeaders)) {
|
|
foreach ($httpHeaders as $httpHeader) {
|
|
header($httpHeader);
|
|
}
|
|
}
|
|
echo $data;
|
|
exit;
|
|
}
|
|
}
|