Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit bd5742a

Browse files
committed
✨ add isAjax() getContent() and getContentType() methods
Signed-off-by: otengkwame <[email protected]>
1 parent af82187 commit bd5742a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

framework/core/Input.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,38 @@ public function inputStream($index = null, $xss_clean = false)
663663
return $this->input_stream($index, $xss_clean);
664664
}
665665

666+
/**
667+
* Alias To Method Above
668+
*
669+
* @param string $index Index for item to be fetched
670+
* @param bool $xss_clean Whether to apply XSS filtering
671+
* @return mixed
672+
*/
673+
public function getContent($index = null, $xss_clean = false)
674+
{
675+
676+
$contentType = $this->getContentType() ?? '';
677+
678+
if (strcasecmp($contentType, 'application/json') == 0) {
679+
return $this->input_stream($index, $xss_clean);
680+
} elseif ($this->method() === 'POST') {
681+
return $_POST;
682+
// pass a "GET" to $index to make this a get content
683+
} elseif (strtoupper($this->method()) === $index) {
684+
return $_GET;
685+
}
686+
687+
return $this->input_stream($index, $xss_clean);
688+
}
689+
690+
/**
691+
* Get Content Type
692+
*/
693+
public function getContentType()
694+
{
695+
return isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : null;
696+
}
697+
666698
// ------------------------------------------------------------------------
667699

668700
/**
@@ -1210,6 +1242,16 @@ public function isAjaxRequest()
12101242
return $this->is_ajax_request();
12111243
}
12121244

1245+
/**
1246+
* Alias To Method Above
1247+
*
1248+
* @return bool
1249+
*/
1250+
public function isAjax()
1251+
{
1252+
return $this->isAjaxRequest();
1253+
}
1254+
12131255
// --------------------------------------------------------------------
12141256

12151257
/**

0 commit comments

Comments
 (0)