Skip to content

Commit 9b9998d

Browse files
authored
1.6.0
1 parent 16e6908 commit 9b9998d

File tree

8 files changed

+261
-59
lines changed

8 files changed

+261
-59
lines changed

App/Controllers/AppController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
namespace Monster\App\Controllers;
44

5+
use Monster\App\Models\Json;
6+
57
class AppController
68
{
79
public function index()
810
{
9-
echo "Welcome to API-Monster";
11+
$json = new Json();
12+
13+
$data = [
14+
"status" => true,
15+
"message" => "API Page"
16+
];
17+
18+
$json->clean($data, 200);
1019
}
11-
}
20+
}

App/Controllers/HomeController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Monster\App\Controllers;
4+
5+
class HomeController
6+
{
7+
public function index()
8+
{
9+
echo "Welcome to API-Monster";
10+
}
11+
}

App/Core.php

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,6 @@
22

33
namespace Monster\App;
44

5-
/*
6-
|--------------------------------------------------------------------------
7-
| API-Monster Framework
8-
|--------------------------------------------------------------------------
9-
|
10-
| API-Monster is a fast, safe, and easy-to-use PHP framework designed for
11-
| building API applications. It provides a wide range of features and
12-
| components to streamline the development process and enhance
13-
| productivity.
14-
|
15-
| Features:
16-
| - Fast: API-Monster is optimized for performance, allowing you to build
17-
| high-performance API applications.
18-
| - Safe: The framework prioritizes security and provides built-in mechanisms
19-
| for handling common security concerns.
20-
| - Easy: API-Monster follows a user-friendly approach, making it easy for
21-
| developers to understand and work with the framework.
22-
|
23-
| Key Components:
24-
| - Routing: API-Monster supports routing similar to Laravel, allowing you to
25-
| define routes and map them to corresponding controller actions.
26-
| - MySQL Class: The framework includes a MySQL class for easy interaction
27-
| with MySQL databases.
28-
| - HTTP Class: API-Monster provides an HTTP class for handling HTTP requests
29-
| and responses, simplifying the communication with external APIs.
30-
| - Cipher Class: The Cipher class offers encoding and decoding functionality,
31-
| allowing you to securely handle sensitive data.
32-
| - Controllers: API-Monster supports controllers, enabling you to organize
33-
| your application's logic into modular and reusable components.
34-
| - Object-Oriented Syntax: The framework utilizes object-oriented programming
35-
| (OOP) syntax, promoting clean and maintainable code.
36-
|
37-
| Getting Started:
38-
| To create a new API-Monster project, you can use Composer by running the
39-
| following command:
40-
| composer create-project darkphp/apimonster myapp
41-
|
42-
| GitHub Repository:
43-
| For more information and to explore the framework's source code, you can
44-
| visit the API-Monster GitHub repository at:
45-
| https://github.com/ReactMVC/API-Monster
46-
|
47-
| Developer Information:
48-
| API-Monster is developed by Hossein Pira. If you have any questions,
49-
| suggestions, or feedback, you can reach out to Hossein via email at:
50-
| - h3dev.pira@gmail.com
51-
| - hosseinpiradev@gmail.com
52-
| Alternatively, you can contact Hossein on Telegram at @h3dev.
53-
|
54-
*/
55-
565
class Core
576
{
587
// The HTTP method associated with this route item
@@ -177,4 +126,4 @@ public function execute()
177126
}
178127
}
179128
}
180-
}
129+
}

App/Models/Json.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
class Json
66
{
77
// Clean and output the given data as JSON with indentation and Unicode and slashes escaping
8-
public function clean(array $data)
8+
public function clean(array $data, int $code = 200)
99
{
10+
http_response_code($code); // HTTP Code
1011
header('Content-type: application/json; charset=utf-8'); // Set the response header to indicate JSON content type
1112
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); // Encode the data as JSON with pretty print and Unicode and slashes escaping
1213
}
1314

1415
// Output the given data as JSON without any special formatting
15-
public function show(array $data)
16+
public function show(array $data, int $code = 200)
1617
{
18+
http_response_code($code); // HTTP Code
1719
header('Content-type: application/json; charset=utf-8'); // Set the response header to indicate JSON content type
1820
echo json_encode($data); // Encode the data as JSON
1921
}
20-
}
22+
}

App/Route.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static function run()
7878

7979
// If no route matches, return a 404 error
8080
http_response_code(404);
81-
echo "404 Not Found";
81+
include_once(__DIR__ . "/../routes/errors/404.html");
8282
}
8383

8484
// Getters and setters for the private properties
@@ -100,6 +100,11 @@ public static function prefixPath($path, $prefix = null)
100100
if (empty($prefix)) {
101101
$prefix = self::$prefix;
102102
}
103+
104+
if ($path === '/') {
105+
return $prefix;
106+
}
107+
103108
return $prefix . $path;
104109
}
105-
}
110+
}

routes/errors/404.html

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>404 - Not Found</title>
8+
<style>
9+
* {
10+
box-sizing: border-box;
11+
}
12+
13+
body {
14+
font-family: 'Roboto', sans-serif;
15+
background-color: #222;
16+
color: #fff;
17+
margin: 0;
18+
display: flex;
19+
justify-content: center;
20+
align-items: center;
21+
min-height: 100vh;
22+
}
23+
24+
.container {
25+
max-width: 400px;
26+
width: 90%;
27+
text-align: center;
28+
padding: 40px;
29+
background-color: #333;
30+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
31+
border-radius: 4px;
32+
opacity: 0;
33+
animation: fade-in 1s forwards;
34+
}
35+
36+
@keyframes fade-in {
37+
0% {
38+
opacity: 0;
39+
transform: translateY(-20px);
40+
}
41+
42+
100% {
43+
opacity: 1;
44+
transform: translateY(0);
45+
}
46+
}
47+
48+
h1 {
49+
font-size: 72px;
50+
font-weight: 700;
51+
color: transparent;
52+
background-image: linear-gradient(to right, #e91e63, #8c14fc);
53+
-webkit-background-clip: text;
54+
background-clip: text;
55+
-webkit-text-fill-color: transparent;
56+
margin: 0;
57+
}
58+
59+
h2 {
60+
font-size: 24px;
61+
font-weight: 400;
62+
color: #fff;
63+
margin-top: 10px;
64+
}
65+
66+
p {
67+
font-size: 16px;
68+
color: #ccc;
69+
margin-top: 20px;
70+
}
71+
72+
a {
73+
display: inline-block;
74+
font-size: 16px;
75+
color: #e91e63;
76+
text-decoration: none;
77+
margin-top: 20px;
78+
border-bottom: 1px solid #e91e63;
79+
padding-bottom: 2px;
80+
transition: border-bottom 0.2s;
81+
}
82+
83+
a:hover {
84+
border-bottom-color: #c2185b;
85+
}
86+
87+
@media (max-width: 480px) {
88+
h1 {
89+
font-size: 48px;
90+
}
91+
92+
h2 {
93+
font-size: 20px;
94+
}
95+
96+
p {
97+
font-size: 14px;
98+
}
99+
}
100+
</style>
101+
</head>
102+
103+
<body>
104+
<div class="container">
105+
<h1>404</h1>
106+
<h2>Page Not Found</h2>
107+
<p>The page you are looking for does not exist.</p>
108+
<a href="/">Go back to homepage</a>
109+
</div>
110+
</body>
111+
112+
</html>

routes/errors/500.html

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>404 - Not Found</title>
8+
<style>
9+
* {
10+
box-sizing: border-box;
11+
}
12+
13+
body {
14+
font-family: 'Roboto', sans-serif;
15+
background-color: #222;
16+
color: #fff;
17+
margin: 0;
18+
display: flex;
19+
justify-content: center;
20+
align-items: center;
21+
min-height: 100vh;
22+
}
23+
24+
.container {
25+
max-width: 400px;
26+
width: 90%;
27+
text-align: center;
28+
padding: 40px;
29+
background-color: #333;
30+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
31+
border-radius: 4px;
32+
opacity: 0;
33+
animation: fade-in 1s forwards;
34+
}
35+
36+
@keyframes fade-in {
37+
0% {
38+
opacity: 0;
39+
transform: translateY(-20px);
40+
}
41+
42+
100% {
43+
opacity: 1;
44+
transform: translateY(0);
45+
}
46+
}
47+
48+
h1 {
49+
font-size: 72px;
50+
font-weight: 700;
51+
color: transparent;
52+
background-image: linear-gradient(to right, #e91e63, #8c14fc);
53+
-webkit-background-clip: text;
54+
background-clip: text;
55+
-webkit-text-fill-color: transparent;
56+
margin: 0;
57+
}
58+
59+
h2 {
60+
font-size: 24px;
61+
font-weight: 400;
62+
color: #fff;
63+
margin-top: 10px;
64+
}
65+
66+
p {
67+
font-size: 16px;
68+
color: #ccc;
69+
margin-top: 20px;
70+
}
71+
72+
a {
73+
display: inline-block;
74+
font-size: 16px;
75+
color: #e91e63;
76+
text-decoration: none;
77+
margin-top: 20px;
78+
border-bottom: 1px solid #e91e63;
79+
padding-bottom: 2px;
80+
transition: border-bottom 0.2s;
81+
}
82+
83+
a:hover {
84+
border-bottom-color: #c2185b;
85+
}
86+
87+
@media (max-width: 480px) {
88+
h1 {
89+
font-size: 48px;
90+
}
91+
92+
h2 {
93+
font-size: 20px;
94+
}
95+
96+
p {
97+
font-size: 14px;
98+
}
99+
}
100+
</style>
101+
</head>
102+
103+
<body>
104+
<div class="container">
105+
<h1>404</h1>
106+
<h2>Page Not Found</h2>
107+
<p>The page you are looking for does not exist.</p>
108+
<a href="/">Go back to homepage</a>
109+
</div>
110+
</body>
111+
112+
</html>

routes/web.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
|
1414
*/
1515

16+
Route::get('/', 'HomeController@index');
17+
Route::post('/', 'HomeController@index');
1618
Route::get('/api', 'AppController@index');
1719

1820
/*

0 commit comments

Comments
 (0)