Merge pull request #19017 from eileenmcnaughton/remove_recur
[civicrm-core.git] / CRM / Utils / FakeObject.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This is a quick-and-dirty way to define a vaguely-class-ish structure. It's non-performant, abnormal,
20 * and not a complete OOP system. Only use for testing/mocking.
21 *
22 * ```
23 * $object = new CRM_Utils_FakeObject(array(
24 * 'doIt' => function() { print "It!\n"; }
25 * ));
26 * $object->doIt();
27 * ```
28 */
29 class CRM_Utils_FakeObject {
30
31 /**
32 * @param $array
33 */
34 public function __construct($array) {
35 $this->array = $array;
36 }
37
38 /**
39 * @param string $name
40 * @param $arguments
41 *
42 * @throws Exception
43 */
44 public function __call($name, $arguments) {
45 if (isset($this->array[$name]) && is_callable($this->array[$name])) {
46 return call_user_func_array($this->array[$name], $arguments);
47 }
48 else {
49 throw new Exception("Call to unimplemented method: $name");
50 }
51 }
52
53 }