CustomerRewardsRESTAPI/Controller/API/BaseController.php

72 lines
1.8 KiB
PHP
Raw Normal View History

2024-04-15 11:38:59 -05:00
<?php
/**
* Description of BaseController
*
2024-05-06 13:19:09 -05:00
* @author Mike Howard
2024-04-15 11:38:59 -05:00
*/
class BaseController {
2024-05-06 13:19:09 -05:00
public $name;
public function __construct() {
$this->name = 'BaseController';
}
public static function create() { return new self(); }
2024-04-15 11:38:59 -05:00
/**
2024-05-06 13:19:09 -05:00
* The __call() method is invoked automatically when a non-existing method or inaccessible method is called.
2024-04-15 11:38:59 -05:00
*/
public function __call($name, $arguments)
{
2024-05-06 13:19:09 -05:00
$this->sendOutput('', array('HTTP/1.1 404 Non-Existant method or inaccessible method called'));
2024-04-15 11:38:59 -05:00
}
/**
* 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 );
2024-04-15 11:38:59 -05:00
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);
2024-04-15 11:38:59 -05:00
return $query;
}
protected function getServerRequestMethod()
{
$requestMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING); /*htmlspecialchars()*/
return $requestMethod;
}
2024-04-15 11:38:59 -05:00
/**
* 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;
}
}