Skip to content

Commit 4772f7e

Browse files
committed
V 11.4; Updated DataValidator version
1 parent d159b97 commit 4772f7e

File tree

8 files changed

+106
-287
lines changed

8 files changed

+106
-287
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"minimum-stability": "stable",
1414
"require": {
1515
"php": ">=8.1",
16-
"anshu-krishna/data-validator": "^2.6.3",
16+
"anshu-krishna/data-validator": "^2.8",
1717
"anshu-krishna/php-utilities": "^2.0.1"
1818
},
1919
"autoload": {

example/client/api-caller.js

Lines changed: 0 additions & 232 deletions
This file was deleted.

example/client/component/api-fetch.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ class APIFetch extends HTMLElement {
4848
}
4949
param = {...param, ...d};
5050
}
51-
let resp = await this.#api.fetchRaw(fname, param);
52-
this.#rcntr.innerHTML = JSON.stringify(resp, null, 4);
51+
const resp = await this.#api.fetchRaw(fname, param);
52+
if(resp.status === 5) {
53+
this.#rcntr.innerText = resp.value;
54+
} else {
55+
this.#rcntr.innerHTML = JSON.stringify(resp, null, 4);
56+
}
5357

5458
this.#root.querySelector('#resp_cntr').style.background = (resp.status === 0) ? '#4caf50' : '#f44336';
5559

example/server/function/Test/@index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'?string' => 'string',
1919
'?string64' => 'string64',
2020
'?timestamp' => 'timestamp',
21+
'?timestamp_utc' => 'timestamp_utc',
2122
'?unsigned' => 'unsigned',
2223
'?url' => 'url',
2324
'?url64' => 'url64',
@@ -38,6 +39,7 @@
3839
'?_string' => 'string|null',
3940
'?_string64' => 'string64|null',
4041
'?_timestamp' => 'timestamp|null',
42+
'?_timestamp_utc' => 'timestamp_utc|null',
4143
'?_unsigned' => 'unsigned|null',
4244
'?_url' => 'url|null',
4345
'?_url64' => 'url64|null',

example/server/function/TestCustom/@index.php

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,64 @@
11
<?php
22
use Krishna\API\Func;
33
use Krishna\API\Server;
4+
use Krishna\Utilities\JSON;
5+
6+
Server::set_custom_final_writer(function($data) {
7+
[
8+
'status' => $status,
9+
'value' => $value,
10+
'headers' => $headers,
11+
'meta' => $meta
12+
] = $data;
13+
?><!DOCTYPE html>
14+
<html lang="en">
15+
<head>
16+
<meta charset="UTF-8">
17+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
18+
<title>Custom Final Writer</title>
19+
<style>
20+
body {
21+
padding: 0.5rem;
22+
margin: 0;
23+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
24+
}
25+
dl {
26+
padding: 0.8rem;
27+
box-shadow: 0 0 3px black;
28+
border-radius: 0.5rem;
29+
display: grid;
30+
gap: 0.8rem;
31+
grid-template-columns: max-content 1fr;
32+
}
33+
dt {
34+
font-weight: bold;
35+
font-size: 1.1rem;
36+
}
37+
dd {
38+
margin: 0;
39+
}
40+
pre {
41+
font-size: 1.1rem;
42+
margin: 0;
43+
white-space: pre-wrap;
44+
word-break: break-all;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<dl>
50+
<dt>Status:</dt>
51+
<dd><?= $status->description() ?></dd>
52+
<dt>Value:</dt>
53+
<dd><pre><?= JSON::encode($value, true, true) ?></pre></dd>
54+
<dt>Headers:</dt>
55+
<dd><pre><?= JSON::encode($headers, true, true) ?></pre></dd>
56+
<dt>Meta:</dt>
57+
<dd><pre><?= JSON::encode($meta, true, true) ?></pre></dd>
58+
</dl>
59+
</body>
60+
</html><?php
61+
});
462

563
Func::set_signature([
664
'?bool' => 'bool',
@@ -46,31 +104,4 @@
46104

47105
Func::set_definition(function(array $params, string $function_name) {
48106
return $params;
49-
});
50-
51-
52-
function array2xml(array $array, \SimpleXMLElement &$xml) {
53-
// Loop through array
54-
foreach($array as $key => $value ) {
55-
// Another array? Iterate
56-
if (is_array($value)) {
57-
array2xml($value, $xml->addChild($key));
58-
} else {
59-
$xml->addChild($key, $value);
60-
}
61-
}
62-
63-
// Return XML
64-
return $xml->asXML();
65-
}
66-
Server::set_custom_final_writer(function($data) {
67-
// [
68-
// 'status' => $status,
69-
// 'value' => $value,
70-
// 'headers' => $headers,
71-
// 'meta' => $meta
72-
// ] = $data;
73-
74-
// Dump the final data
75-
var_dump($data);
76107
});

example/server/public/index.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<?php
2-
namespace ExampleApp;
3-
require_once '../../../vendor/autoload.php';
4-
5-
use Krishna\API\Config;
6-
use Krishna\API\Debugger;
7-
use Krishna\API\Server;
8-
9-
Config::$dev_mode = true;
10-
11-
Server::init();
1+
<?php
2+
namespace ExampleApp;
3+
require_once '../../../vendor/autoload.php';
4+
5+
use Krishna\API\Config;
6+
use Krishna\API\Server;
7+
8+
Config::$dev_mode = true;
9+
Config::$zlib = false;
10+
11+
Server::init();
1212
Server::execute();

0 commit comments

Comments
 (0)