Commit | Line | Data |
---|---|---|
72ad6c1b TO |
1 | <?php |
2 | ||
3 | /** | |
4 | * This is a quick-and-dirty way to define a vaguely-class-ish structure. It's non-performant, abnormal, | |
5 | * and not a complete OOP system. Only use for testing/mocking. | |
6 | * | |
7 | * @code | |
8 | * $object = new CRM_Utils_FakeObject(array( | |
9 | * 'doIt' => function() { print "It!\n"; } | |
10 | * )); | |
11 | * $object->doIt(); | |
12 | * @endcode | |
13 | */ | |
14 | class CRM_Utils_FakeObject { | |
5bc392e6 EM |
15 | /** |
16 | * @param $array | |
17 | */ | |
72ad6c1b TO |
18 | function __construct($array) { |
19 | $this->array = $array; | |
20 | } | |
21 | ||
5bc392e6 EM |
22 | /** |
23 | * @param $name | |
24 | * @param $arguments | |
25 | * | |
26 | * @throws Exception | |
27 | */ | |
72ad6c1b TO |
28 | function __call($name, $arguments) { |
29 | if (isset($this->array[$name]) && is_callable($this->array[$name])) { | |
30 | return call_user_func_array($this->array[$name], $arguments); | |
31 | } else { | |
32 | throw new Exception("Call to unimplemented method: $name"); | |
33 | } | |
34 | } | |
5bc392e6 | 35 | } |