Merge pull request #3775 from colemanw/file
[civicrm-core.git] / CRM / Utils / FakeObject.php
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 {
15 function __construct($array) {
16 $this->array = $array;
17 }
18
19 function __call($name, $arguments) {
20 if (isset($this->array[$name]) && is_callable($this->array[$name])) {
21 return call_user_func_array($this->array[$name], $arguments);
22 } else {
23 throw new Exception("Call to unimplemented method: $name");
24 }
25 }
26 }