This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
64 lines (53 loc) · 1.67 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
* File: index.php
*
* MMF (Monty Micro Framework). A PHP Micro Framework for Rest apps.
* Created by Ivan Montilla <personal@ivanmontilla.es>
*
* Official website: mmf-php.com
* Documentation: docs.mmf-php.com
*
* You have permission to use, adapt and redistribute this
* code or adaption.
* You can use this framework or adaption for make apps
* with profit, but never sell this framework or adaption.
*
* Get started in docs.mmf-php.com/quickstart
*/
use MMF\Controller\Exception\TypeOfResponseNotValidException;
use MMF\Environment;
define("IN_INDEX_FILE", true);
spl_autoload_register("mmfAutoload", true, true);
function mmfAutoload($class) {
require_once str_ireplace("\\", "/", $class) . ".php";
}
if (Environment::isProductionEnvironment()) {
error_reporting(0);
ini_set("display_errors", false);
header('Content-Type: application/json; charset=utf-8');
}
$path = [];
if (!isset($_SERVER["PATH_INFO"]) or $_SERVER["PATH_INFO"] == "/") {
$path[0] = "App\\Controller\\" . Environment::getConfigObject()->Environment->controller;
$path[1] = "index";
} else {
$path = explode("/", $_SERVER["PATH_INFO"]);
array_shift($path);
$path[0] = "App\\Controller\\" . $path[0];
if (!isset($path[1])) $path[1] = "index";
}
$params = [];
for ($i = 2; $i < count($path); $i++) {
array_push($params, $path[$i]);
}
$controller = new $path[0];
$response = call_user_func_array([$controller, $path[1]], $params);
if (is_object($response)) {
$response = get_object_vars($response);
} else {
if (!is_array($response)) {
throw new TypeOfResponseNotValidException();
}
}
echo json_encode($response, JSON_UNESCAPED_UNICODE);