/
PaymentFactory.php
57 lines (42 loc) · 1.07 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
<?php
namespace OS\PaymentBundle;
use Exception;
/**
* @author ouardisoft
*/
class PaymentFactory
{
private $plugin;
public function __call($name, $arguments)
{
return $this->getPlugin()->$name($arguments);
}
public function getPlugin()
{
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;
}
}