Load::partial()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Pin\Libs;
4
5
/**
6
 * Load
7
 * Clase con métodos estáticos para cargar archivos, helpers, vistas y manejar
8
 * el enrutamiento dinámico antiguo si es necesario.
9
 */
10
class Load
11
{
12
    public static function file($file, $extension, $base_dir, $classification, $parameters = null)
13
    {
14
        if (isset($parameters) && is_array($parameters)) {
15
            extract($parameters);
16
        }
17
        $path = $base_dir . $file . $extension;
18
        if (file_exists($path)) {
19
            require $path;
20
        } else {
21
            throw (new \Exception("$classification <b>$file</b> no existe!"));
22
        }
23
    }
24
25
    public static function lib($lib)
26
    {
27
        self::file($lib, ".php", PIN_PATH . 'libs' . DS, "Librería");
28
    }
29
30
    public static function config($config)
31
    {
32
        self::file($config, ".php", PIN_PATH . 'config' . DS, "Configuración");
33
    }
34
35
    public static function helper($helper)
36
    {
37
        self::file($helper, ".php", PIN_PATH . 'helpers' . DS, "Helper");
38
    }
39
40
    public static function view($view, $parameters = null)
41
    {
42
        self::file($view, ".phtml", APP_PATH . 'views' . DS, "Vista", $parameters);
43
    }
44
45
    public static function partial($partial, $parameters = null)
46
    {
47
        self::file($partial, ".phtml", APP_PATH . 'views' . DS . '_shared' . DS . 'partials' . DS, "Parcial", $parameters);
48
    }
49
50
    public static function redirect($url)
51
    {
52
        $url = PUBLIC_PATH . $url;
53
        header("Location: $url", true, 301);
54
        exit;
55
    }
56
}
57
58