Skip to content

Commit b1daa82

Browse files
authored
Basic::setJsonBodyAsPOST()
1 parent 18f2294 commit b1daa82

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Basic.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static function baseUrl()
189189
/**
190190
* Prevent Cross-Site Request Forgery (CSRF)
191191
* Create a per request token to handle CSRF using sessions
192-
* Basic::firewall() should be executed. $verify_csrf_token = TRUE (default)
192+
* Basic::setFirewall() should be executed. $verify_csrf_token = TRUE (default)
193193
*/
194194

195195
public static function csrfToken()
@@ -211,7 +211,7 @@ public static function encrypt($plaintext)
211211
{
212212
// Require encryption middleware
213213
if (! defined('PASS_PHRASE') || ! defined('CIPHER_METHOD')) {
214-
self::apiResponse(501, 'Please activate Basic::encryption() middleware and set the pass phrase.');
214+
self::apiResponse(501, 'Please activate Basic::setEncryption() middleware and set the pass phrase.');
215215
}
216216

217217
// Encryption - Version 1
@@ -261,7 +261,7 @@ public static function decrypt($encrypted)
261261
{
262262
// Require encryption middleware
263263
if (! defined('PASS_PHRASE') || ! defined('CIPHER_METHOD')) {
264-
self::apiResponse(501, 'Please activate Basic::encryption() middleware and set the pass phrase.');
264+
self::apiResponse(501, 'Please activate Basic::setEncryption() middleware and set the pass phrase.');
265265
}
266266

267267
// Decryption - Version 1
@@ -362,6 +362,15 @@ public static function setErrorReporting($boolean=TRUE)
362362
}
363363
}
364364

365+
/**
366+
* JSON Request Body as $_POST
367+
*/
368+
369+
public static function setJsonBodyAsPOST() {
370+
$body = file_get_contents('php://input');
371+
if ( ! empty($body) && is_array(json_decode($body, TRUE)) ) $_POST = json_decode($body, TRUE);
372+
}
373+
365374
/**
366375
* Web Application Firewall
367376
*

sample-site/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
Basic::setErrorReporting(); // Error reporting
18+
Basic::setJsonBodyAsPOST(); // JSON as $_POST
1819
Basic::setFirewall(); // Enable firewall
1920
// Basic::setHttps(); // Require TLS/HTTPS
2021
Basic::setEncryption('SecretPassPhrase123'); // Encryption cipher method and pass phrase

0 commit comments

Comments
 (0)