-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPaymentFactory.php
73 lines (56 loc) · 1.47 KB
/
PaymentFactory.php
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
<?php
namespace OS\PaymentBundle;
use Exception;
/**
* @author ouardisoft
*/
class PaymentFactory
{
private $plugin;
private $container;
public function __construct($container)
{
$this->container = $container;
}
public function __call($name, $arguments)
{
$plugin = $this->getPlugin();
return call_user_func_array(array($plugin, $name), $arguments);
}
public function getPlugin($plugin = null)
{
if ($plugin) {
$this->setPlugin($plugin);
}
if (method_exists($this->plugin, 'setContainer')) {
$this->plugin->setContainer($this->container);
}
return $this->plugin;
}
public function setPlugin($plugin)
{
$exists = true;
if (!class_exists($plugin)) {
$exists = false;
}
if (!class_exists(sprintf('OS\\PaymentBundle\\Plugins\\%s', $plugin)) && !$exists) {
$exists = false;
} else {
$plugin = sprintf('OS\\PaymentBundle\\Plugins\\%s', $plugin);
$exists = true;
}
if ($exists == false) {
throw new Exception(sprintf('Plugin %s not found.', $plugin));
}
$this->plugin = new $plugin;
return $this;
}
public function execute($args = array())
{
$this->setPlugin($args['plugin']);
$this
->getPlugin()
->execute($args['options']);
return $this;
}
}