Merge pull request #15986 from civicrm/5.20
[civicrm-core.git] / CRM / Utils / FakeObject.php
CommitLineData
72ad6c1b 1<?php
50bfb460 2/*
bc77d7c0
TO
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 +--------------------------------------------------------------------+
50bfb460
SB
10 */
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
50bfb460 16 */
72ad6c1b
TO
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 * @code
23 * $object = new CRM_Utils_FakeObject(array(
24 * 'doIt' => function() { print "It!\n"; }
25 * ));
26 * $object->doIt();
27 * @endcode
28 */
29class CRM_Utils_FakeObject {
6714d8d2 30
5bc392e6
EM
31 /**
32 * @param $array
33 */
00be9182 34 public function __construct($array) {
72ad6c1b
TO
35 $this->array = $array;
36 }
37
5bc392e6 38 /**
100fef9d 39 * @param string $name
5bc392e6
EM
40 * @param $arguments
41 *
42 * @throws Exception
43 */
00be9182 44 public function __call($name, $arguments) {
72ad6c1b
TO
45 if (isset($this->array[$name]) && is_callable($this->array[$name])) {
46 return call_user_func_array($this->array[$name], $arguments);
0db6c3e1
TO
47 }
48 else {
72ad6c1b
TO
49 throw new Exception("Call to unimplemented method: $name");
50 }
51 }
96025800 52
5bc392e6 53}