forked from pudney/Payvment-Developer-PHP-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasePayvment.php
More file actions
72 lines (65 loc) · 1.97 KB
/
BasePayvment.php
File metadata and controls
72 lines (65 loc) · 1.97 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
<?php
/**
* Description of Base
*
* @author cdraycott
* Defines a base set of methods for a data model, along with abstract definitions for each model
*/
abstract class BasePayvment {
/**
* This magic function will be called if the given method
* does not exist.
* @param string $methodName
* @param mixed $argument
*/
public function __call($methodName, $argument)
{
preg_match("/(get|set)(.*)$/", $methodName, $pieces);
if (count($pieces) != 3)
{
throw new \Exception("Method $methodName not found on class ".get_class($this));
}
$pieces[2] = lcfirst($pieces[2]);
switch ($pieces[1]) {
case 'get':
return $this->get('_'.$pieces[2]);
break;
case 'set':
$this->set('_'.$pieces[2], $argument[0]);
break;
default:
throw new \Exception("Method $methodName not found on class ".get_class($this));
}
}
/*
* Default set function. Will set the internal property to the passed
* argument value
* @param string $methodName
* @param unknown_type $argument
*/
private function set($variableName, $argument)
{
if (property_exists(get_class($this), $variableName))
{
$this->$variableName = $argument;
}
else {
throw new \Exception("Member $variableName does not exist on class ".get_class($this) . ' so could not be set');
}
}
/*
* Retrieve the internal property based on the method name
* @param string $methodName
* @return mixed attributes of the object
*/
private function get($variableName)
{
if (property_exists(get_class($this), $variableName))
{
return $this->$variableName;
}
else {
throw new \Exception("Member $variableName does not exist on class ".get_class($this));
}
}
}