Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 322d5dd

Browse files
Basic structure of the application
1 parent 273cf02 commit 322d5dd

File tree

5 files changed

+97
-11
lines changed

5 files changed

+97
-11
lines changed

‎README.md‎

Whitespace-only changes.

‎core/Helper/HelperClass.php‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace CodeArchitect\Framework\Helper;
4+
5+
use stdClass;
6+
7+
class HelperClass
8+
{
9+
10+
11+
// public function makeJsonResponse(array $fieldNames, array $data, bool $isJson = true)
12+
// {
13+
// $combinedArray = array_combine($fieldNames, $data);
14+
// }
15+
16+
public function makeJsonSuccessResponse(array $dataArray)
17+
{
18+
$stdClassData = $this->arrayToStdClass($dataArray);
19+
return json_encode($stdClassData, JSON_PRETTY_PRINT);
20+
}
21+
22+
public function makeJsonErrorResponse(array $dataArray)
23+
{
24+
$stdClassData = $this->arrayToStdClass($dataArray);
25+
return json_encode($stdClassData, JSON_PRETTY_PRINT);
26+
}
27+
28+
private function arrayToStdClass($array): stdClass
29+
{
30+
$stdclass = new stdClass();
31+
32+
foreach ($array as $key => $value) {
33+
if (is_array($value)) {
34+
$stdclass->$key = $this->arrayToStdClass($value); // Recursively convert arrays
35+
} else {
36+
$stdclass->$key = $value;
37+
}
38+
}
39+
return $stdclass;
40+
}
41+
42+
}

‎core/Operations/BaseClass.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace CodeArchitect\Framework\Operations;
4+
5+
use CodeArchitect\Framework\Helper\HelperClass;
6+
7+
class BaseClass
8+
{
9+
protected HelperClass $helper;
10+
11+
public function __construct(
12+
public $mc
13+
)
14+
{
15+
$this->helper = new HelperClass() ;
16+
}
17+
18+
}

‎core/Operations/MultichainBasic.php‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace CodeArchitect\Framework\Operations;
4+
5+
use CodeArchitect\Framework\Helper\HelperClass;
6+
7+
class MultichainBasic extends BaseClass
8+
{
9+
10+
public function getinfo()
11+
{
12+
return $this->mc->getinfo();
13+
}
14+
15+
/**
16+
* Check if the connection is active or not
17+
* @return false|string
18+
*/
19+
public function isActive()
20+
{
21+
$value = $this->getinfo();
22+
23+
if (!empty($value["chainname"]))
24+
{
25+
$data = ["status" => "success", "code" => 200, "data" => ["chainName" => $value["chainname"]]];
26+
return $this->helper->makeJsonSuccessResponse($data);
27+
}else{
28+
$data = ["status" => "error", "code" => 404, "data" => ["error" => "Cannot find active chain name"]];
29+
return $this->helper->makeJsonErrorResponse($data);
30+
}
31+
}
32+
33+
}

‎index.php‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,13 @@
2020
$config = new Config();
2121
$mc = $config->instance();
2222

23-
print_r($mc->getinfo());
2423

24+
// Multichain Basic commands
25+
$multiBasic = new \CodeArchitect\Framework\Operations\MultichainBasic(mc: $mc);
2526
header('Content-Type: application/json');
2627

27-
// Your data to be sent in the response
28-
$data = [
29-
'message' => 'Hello, this is a simple REST API response!',
30-
'timestamp' => time(),
31-
];
28+
// check if the connection is active or not
29+
print_r($multiBasic->isActive());
3230

33-
// Encode the data as JSON
34-
$response = json_encode($data);
35-
36-
// Output the JSON response
37-
echo $response;
3831

3932

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /