1. Go to this page and download the library: Download qoliber/djson library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// These are BLOCKED - throws InvalidArgumentException
$djson->registerFunction('exec', fn($cmd) => shell_exec($cmd));
$djson->registerFunction('eval', fn($code) => eval($code));
$djson->registerFunction('file_get_contents', fn($path) => file_get_contents($path));
// Error: "dangerous pattern 'exec'... use registerUnsafeFunction()"
// Trying the "unsafe" method? ALSO blocked! (troll mode activated)
$djson->registerUnsafeFunction('exec', fn($cmd) => shell_exec($cmd));
// Error: "Sorry matey, no unsafe functions allowed! Security is mandatory!"
// These are SAFE and work perfectly
$djson->registerFunction('currency', fn($v, $s = '$') => $s . number_format($v, 2));
$djson->registerFunction('md5hash', fn($v) => md5($v));
$djson->registerFunction('base64', fn($v) => base64_encode($v));
$djson->registerFunction('truncate', fn($v, $len = 50) => substr($v, 0, $len) . '...');
// BLOCKED - Even though function name is safe, the code inside is dangerous!
$djson->registerFunction('process_data', function ($input) {
return eval($input); // Detected via reflection!
});
// Error: "callable's source code contains a call to prohibited function pattern 'eval'"
// BLOCKED - Database access detected in callable
$djson->registerFunction('get_user', function ($id) {
return mysqli_query($conn, "SELECT * FROM users WHERE id = $id");
});
// Error: "callable's source code contains a call to prohibited function pattern 'mysqli'"
$template = [
'items' => [
'@djson for products as product',
'position' => '{{_index}}', // Current index
'isFirst' => '{{_first}}', // true if first item
'isLast' => '{{_last}}', // true if last item
'name' => '{{product.name}}'
]
];
$template = [
'@djson match status',
'@djson case active',
'message' => 'User is active',
'@djson case pending',
'message' => 'Awaiting approval',
'@djson default',
'message' => 'Status unknown'
];
$template = [
'@djson set total = price * quantity',
'@djson set discount = total * 0.1',
'@djson set final = total - discount',
'finalPrice' => '{{final | number_format(2)}}'
];