Passed
Branch master (49f250)
by Brayan
01:45
created

___loadApi()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Ocrend Framewok 3 package.
5
 *
6
 * (c) Ocrend Software <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
*/
11
12
# Definir el path
13
define('___ROOT___', '../');
14
15
# Cargadores principales
16
require ___ROOT___ . 'Ocrend/Kernel/Config/Config.php';
17
18
/**
19
 * Lanza un error público
20
 * 
21
 * @return void
22
 */
23
function ___catchApi() {
24
    header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
25
    header('Content-Type: application/json');
26
    echo json_encode(array(
27
        'success' => 0,
28
        'message' => 'Ha ocurrido un problema interno'
29
    ));
30
}
31
32
/**
33
 * Carga la api
34
 * 
35
 * @return void
36
 */
37
function ___loadApi() {
38
    # Preparar la API
39
    $app = new Silex\Application();
40
    unset($app['exception_handler']);
41
42
    # Verbos HTTP
43
    require 'controllers/ini.app.php';
44
    require 'controllers/get.controllers.php';
45
    require 'controllers/post.controllers.php';
46
47
    $app->run();
48
}
49
50
# Arrancar
51
if($config['build']['production']) {
52
    try { 
53
        ___loadApi();  
54
    } catch(\Throwable $e) {
55
        ___catchApi();
56
    } catch(\Exception $e) {
57
        ___catchApi();
58
    }
59
} else {
60
    ___loadApi();
61
}