1 | <?php |
||
14 | class Protean |
||
15 | { |
||
16 | /** |
||
17 | * Internal factory storage |
||
18 | * |
||
19 | * @var GatewayFactory |
||
20 | */ |
||
21 | private static $factory; |
||
22 | |||
23 | /** |
||
24 | * Get the gateway factory |
||
25 | * |
||
26 | * Creates a new empty GatewayFactory if none has been set previously. |
||
27 | * |
||
28 | * @return GatewayFactory A GatewayFactory instance |
||
29 | */ |
||
30 | 42 | public static function factory() |
|
31 | { |
||
32 | 42 | if (is_null(self::$factory)) { |
|
33 | 3 | $namespace = substr(static::class, 0, -(strlen(class_basename(static::class)) + 1)); |
|
34 | 3 | self::$factory = new GatewayFactory($namespace); |
|
35 | } |
||
36 | |||
37 | 42 | return self::$factory; |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * Static function call router. |
||
42 | * |
||
43 | * All other function calls to the Protean class are routed to the factory. |
||
44 | * |
||
45 | * Example: |
||
46 | * |
||
47 | * <code> |
||
48 | * // Create a gateway |
||
49 | * $gateway = Protean::create('Something'); |
||
50 | * </code> |
||
51 | * |
||
52 | * @param string $method The factory method to invoke. |
||
53 | * @param array $parameters Parameters passed to the factory method. |
||
54 | * |
||
55 | * @return mixed |
||
56 | */ |
||
57 | 42 | public static function __callStatic($method, $parameters) |
|
61 | } |
||
62 |