This repository was archived by the owner on Mar 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathdriver.php
More file actions
83 lines (71 loc) · 1.95 KB
/
driver.php
File metadata and controls
83 lines (71 loc) · 1.95 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Gateway driver class.
*/
abstract class Gateway_Driver
{
/**
* The gateway model for the driver.
*
* @var Model_Gateway
*/
public $gateway;
/**
* The customer model for the driver.
*
* @var Model_Customer
*/
public $customer;
/**
* Class constructor.
*
* @param Model_Gateway $gateway The gateway model to use for the driver.
* @param Model_Customer $customer The customer model to use for the driver.
*
* @return void
*/
public function __construct(Model_Gateway $gateway, Model_Customer $customer = null)
{
$this->gateway = $gateway;
$this->customer = $customer;
}
/**
* Forges an instance of the class called on the driver.
*
* @param string $method The method called.
* @param array $args The arguments passed.
*
* @return Gateway_Model
*/
public function __call($method, $args)
{
$instance = self::forge($this->gateway, $this->customer, $method);
if (!empty($args)) {
$data = $instance->find_one($args[0]);
if (!empty($data)) {
$instance->set($data);
}
}
return $instance;
}
/**
* Gets a new instance of gateway $class_name.
*
* @param Model_Gateway $gateway The gateway model to use for the driver.
* @param Model_Customer $customer The customer model to use for the driver.
* @param string $class_name The class name to call on the driver.
*
* @return Gateway_Model
*/
public static function forge(Model_Gateway $gateway, Model_Customer $customer = null, $class_name)
{
$driver_name = str_replace('Gateway_', '', get_called_class());
$driver_name = str_replace('_Driver', '', $driver_name);
$class = 'Gateway_' . Str::ucwords(Inflector::denamespace($driver_name)) . '_' . Str::ucwords(Inflector::denamespace($class_name));
if (!class_exists($class)) {
throw new GatewayException('Call to undefined class ' . $class);
}
$driver = Gateway::instance($gateway, $customer);
return new $class($driver);
}
}