@@ -279,7 +279,7 @@ public function post($index = null, $xss_clean = false)
279279 * @param bool $asArray if true, the data will be returned as an array
280280 * @return array|object
281281 */
282- public function all ($ asArray = false )
282+ public function all ($ asArray = false )
283283 {
284284 $ this ->post (null , true );
285285
@@ -288,7 +288,6 @@ public function all($asArray = false)
288288 }
289289
290290 return $ this ->data = (object )$ this ->data ;
291-
292291 }
293292
294293 // --------------------------------------------------------------------
@@ -540,7 +539,7 @@ public function upload($file = [], $path = '', $name = null): CI_Input|string
540539 }
541540
542541 $ this ->tempfile = $ file ['tmp_name ' ];
543- $ this ->filepath = ($ path ) ? realpath ($ path ) : realpath (WRITABLEPATH . 'uploads ' );
542+ $ this ->filepath = ($ path ) ? realpath ($ path ) : realpath (WRITABLEPATH . 'uploads ' );
544543 $ this ->extension = pathinfo ($ file ['name ' ], PATHINFO_EXTENSION );
545544 $ this ->originalName = $ file ['name ' ];
546545 $ this ->originalMimeType = $ file ['type ' ];
@@ -734,14 +733,14 @@ public function getContent($index = null, $xss_clean = false)
734733
735734 $ contentType = $ this ->getContentType () ?? '' ;
736735
737- if (strcasecmp ($ contentType , 'application/json ' ) == 0 ) {
738- return $ this ->input_stream ($ index , $ xss_clean );
739- } elseif ($ this ->method () === 'POST ' ) {
740- return $ _POST ;
736+ if (strcasecmp ($ contentType , 'application/json ' ) == 0 ) {
737+ return $ this ->input_stream ($ index , $ xss_clean );
738+ } elseif ($ this ->method () === 'POST ' ) {
739+ return $ _POST ;
741740 // pass a "GET" to $index to make this a get content
742- } elseif (strtoupper ($ this ->method ()) === $ index ) {
743- return $ _GET ;
744- }
741+ } elseif (strtoupper ($ this ->method ()) === $ index ) {
742+ return $ _GET ;
743+ }
745744
746745 return $ this ->input_stream ($ index , $ xss_clean );
747746 }
@@ -750,9 +749,9 @@ public function getContent($index = null, $xss_clean = false)
750749 * Get Content Type
751750 */
752751 public function getContentType ()
753- {
754- return isset ($ _SERVER ['CONTENT_TYPE ' ]) ? $ _SERVER ['CONTENT_TYPE ' ] : null ;
755- }
752+ {
753+ return isset ($ _SERVER ['CONTENT_TYPE ' ]) ? $ _SERVER ['CONTENT_TYPE ' ] : null ;
754+ }
756755
757756 // ------------------------------------------------------------------------
758757
@@ -1311,14 +1310,14 @@ public function isAjax()
13111310 }
13121311
13131312 /**
1314- * Checks request type.
1315- *
1316- * @param string $type HTTP verb
1317- */
1318- public function is (string $ type ): bool
1319- {
1320- return is ($ type ); // is() function from Common.php
1321- }
1313+ * Checks request type.
1314+ *
1315+ * @param string $type HTTP verb
1316+ */
1317+ public function is (string $ type ): bool
1318+ {
1319+ return is ($ type ); // is() function from Common.php
1320+ }
13221321
13231322 // --------------------------------------------------------------------
13241323
@@ -1354,107 +1353,107 @@ public function method($upper = false)
13541353 }
13551354
13561355 // ---------------------------HTMX Methods-----------------------------
1357-
1356+
1357+ /**
1358+ * Indicates that the request is triggered by Htmx.
1359+ */
1360+ public function isHtmx (): bool
1361+ {
1362+ return $ this ->hxHeaderToBool ('HX-Request ' );
1363+ }
1364+
1365+ /**
1366+ * Indicates that the request is via an element using hx-boost.
1367+ */
1368+ public function isBoosted (): bool
1369+ {
1370+ return $ this ->hxHeaderToBool ('HX-Boosted ' );
1371+ }
1372+
1373+ /**
1374+ * True if the request is for history restoration
1375+ * after a miss in the local history cache.
1376+ */
1377+ public function isHistoryRestoreRequest (): bool
1378+ {
1379+ return $ this ->hxHeaderToBool ('HX-History-Restore-Request ' );
1380+ }
1381+
1382+ /**
1383+ * The current (htmx) URL of the browser.
1384+ */
1385+ public function currentHxUrl (): ?string
1386+ {
1387+ return $ this ->hxHeader ('HX-Current-Url ' );
1388+ }
1389+
1390+ /**
1391+ * The user response to an hx-prompt.
1392+ */
1393+ public function hxPrompt (): ?string
1394+ {
1395+ return $ this ->hxHeader ('HX-Prompt ' );
1396+ }
1397+
1398+ /**
1399+ * The id of the target element if it exists.
1400+ */
1401+ public function hxTarget (): ?string
1402+ {
1403+ return $ this ->hxHeader ('HX-Target ' );
1404+ }
1405+
1406+ /**
1407+ * The id of the triggered element if it exists.
1408+ */
1409+ public function hxTrigger (): ?string
1410+ {
1411+ return $ this ->hxHeader ('HX-Trigger ' );
1412+ }
1413+
13581414 /**
1359- * Indicates that the request is triggered by Htmx.
1360- */
1361- public function isHtmx (): bool
1362- {
1363- return $ this ->hxHeaderToBool ('HX-Request ' );
1364- }
1365-
1366- /**
1367- * Indicates that the request is via an element using hx-boost.
1368- */
1369- public function isBoosted (): bool
1370- {
1371- return $ this ->hxHeaderToBool ('HX-Boosted ' );
1372- }
1373-
1374- /**
1375- * True if the request is for history restoration
1376- * after a miss in the local history cache.
1377- */
1378- public function isHistoryRestoreRequest (): bool
1379- {
1380- return $ this ->hxHeaderToBool ('HX-History-Restore-Request ' );
1381- }
1382-
1383- /**
1384- * The current (htmx) URL of the browser.
1385- */
1386- public function currentHxUrl (): ?string
1387- {
1388- return $ this ->hxHeader ('HX-Current-Url ' );
1389- }
1390-
1391- /**
1392- * The user response to an hx-prompt.
1393- */
1394- public function hxPrompt (): ?string
1395- {
1396- return $ this ->hxHeader ('HX-Prompt ' );
1397- }
1398-
1399- /**
1400- * The id of the target element if it exists.
1401- */
1402- public function hxTarget (): ?string
1403- {
1404- return $ this ->hxHeader ('HX-Target ' );
1405- }
1406-
1407- /**
1408- * The id of the triggered element if it exists.
1409- */
1410- public function hxTrigger (): ?string
1411- {
1412- return $ this ->hxHeader ('HX-Trigger ' );
1413- }
1414-
1415- /**
1416- * The name of the triggered element if it exists.
1417- */
1418- public function hxTriggerName (): ?string
1419- {
1420- return $ this ->hxHeader ('HX-Trigger-Name ' );
1421- }
1422-
1423- /**
1424- * The value of the header is a JSON serialized
1425- * version of the event that triggered the request.
1426- *
1427- * @see https://htmx.org/extensions/event-header/
1428- */
1429- public function getTriggeringEvent (bool $ toArray = true ): array |object |null
1430- {
1431- if (! $ this ->getRequestHeader ('Triggering-Event ' )) {
1432- return null ;
1433- }
1434-
1435- return json_decode ($ this ->getRequestHeader ('Triggering-Event ' ), $ toArray );
1436- }
1437-
1438- /**
1439- * Get an Htmx header value
1440- */
1441- private function hxHeader (string $ header ): ?string
1442- {
1443- if (!$ this ->getRequestHeader ($ header )) {
1444- return null ;
1445- }
1446-
1447- return $ this ->getRequestHeader ($ header );
1448- }
1449-
1450- /**
1451- * Cast Htmx header to bool
1452- */
1453- private function hxHeaderToBool (string $ header ): bool
1454- {
1455- return $ this ->getRequestHeader ($ header )
1456- && $ this ->getRequestHeader ($ header ) === 'true ' ;
1457- }
1415+ * The name of the triggered element if it exists.
1416+ */
1417+ public function hxTriggerName (): ?string
1418+ {
1419+ return $ this ->hxHeader ('HX-Trigger-Name ' );
1420+ }
1421+
1422+ /**
1423+ * The value of the header is a JSON serialized
1424+ * version of the event that triggered the request.
1425+ *
1426+ * @see https://htmx.org/extensions/event-header/
1427+ */
1428+ public function getTriggeringEvent (bool $ toArray = true ): array |object |null
1429+ {
1430+ if (! $ this ->getRequestHeader ('Triggering-Event ' )) {
1431+ return null ;
1432+ }
1433+
1434+ return json_decode ($ this ->getRequestHeader ('Triggering-Event ' ), $ toArray );
1435+ }
1436+
1437+ /**
1438+ * Get an Htmx header value
1439+ */
1440+ private function hxHeader (string $ header ): ?string
1441+ {
1442+ if (!$ this ->getRequestHeader ($ header )) {
1443+ return null ;
1444+ }
1445+
1446+ return $ this ->getRequestHeader ($ header );
1447+ }
1448+
1449+ /**
1450+ * Cast Htmx header to bool
1451+ */
1452+ private function hxHeaderToBool (string $ header ): bool
1453+ {
1454+ return $ this ->getRequestHeader ($ header )
1455+ && $ this ->getRequestHeader ($ header ) === 'true ' ;
1456+ }
14581457
14591458 // ------------------------------------------------------------------------
14601459
@@ -1470,9 +1469,9 @@ public function __get($name)
14701469 {
14711470
14721471 if ($ this ->has ($ name )) {
1473- return $ this ->index ($ name , true );
1474- } elseif (
1475- $ name === 'raw_input_stream '
1472+ return $ this ->index ($ name , true );
1473+ } elseif (
1474+ $ name === 'raw_input_stream '
14761475 || $ name === 'rawInputStream '
14771476 || $ name === 'getContent '
14781477 ) {
@@ -1481,8 +1480,7 @@ public function __get($name)
14811480 } elseif ($ name === 'ip_address ' || $ name === 'ipAddress ' ) {
14821481 return $ this ->ipAddress ();
14831482 } else {
1484- return null ;
1485- }
1483+ return null ;
1484+ }
14861485 }
1487-
14881486}
0 commit comments