Completed
Push — 1.0 ( 2b306a...ba3a86 )
by Alberto
01:57
created

KumbiaFacade::__callStatic()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 8.8571
cc 5
eloc 13
nc 5
nop 2
1
<?php
2
/**
3
 * KumbiaPHP web & app Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://wiki.kumbiaphp.com/Licencia
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Kumbia
16
 * @package    Core
17
 * @copyright  Copyright (c) 2005 - 2016 Kumbia Team (http://www.kumbiaphp.com)
18
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
19
 */
20
21
 /**
22
  * Clase principal para el manejo de excepciones
23
  *
24
  * @category   Kumbia
25
  * @package    Core
26
  */
27
 abstract class KumbiaFacade
28
 {
29
    protected static $providers = [];
30
31
32
    /**
33
     * Set the providers
34
     * @param  Array  $p key/value array with providers
35
     * @return void
36
     */
37
    public static function providers(Array $p){
38
        self::$providers = $p;
39
    }
40
41
    /**
42
     * Getter for the alias of the component
43
     */
44
    protected static function getAlias(){
45
        throw new RuntimeException('Not implement');
46
    }
47
48
49
    protected static function getInstance($name)
50
    {
51
        return  isset(self::$providers[$name])?self::$providers[$name]:null;
52
    }
53
54
    /**
55
     * Handle dynamic, static calls to the object.
56
     *
57
     * @param  string  $method
58
     * @param  array   $args
59
     * @return mixed
60
     *
61
     * @throws \RuntimeException
62
     */
63
    public static function __callStatic($method, $args)
64
    {
65
        $instance = self::getInstance(static::getAlias());
66
        if (! $instance) {
67
            throw new RuntimeException('A facade root has not been set.');
68
        }
69
70
        switch (count($args)) {
71
            case 0:
72
                return $instance->$method();
73
            case 1:
74
                return $instance->$method($args[0]);
75
            case 2:
76
                return $instance->$method($args[0], $args[1]);
77
            default:
78
                return call_user_func_array([$instance, $method], $args);
79
        }
80
    }
81
82
 }
83