Merge in 5.20
[civicrm-core.git] / Civi / Api4 / Utils / ActionUtil.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
22 namespace Civi\Api4\Utils;
23
24 class ActionUtil {
25
26 /**
27 * @param $entityName
28 * @param $actionName
29 * @return \Civi\Api4\Generic\AbstractAction
30 * @throws \Civi\API\Exception\NotImplementedException
31 */
32 public static function getAction($entityName, $actionName) {
33 // For custom pseudo-entities
34 if (strpos($entityName, 'Custom_') === 0) {
35 return \Civi\Api4\CustomValue::$actionName(substr($entityName, 7));
36 }
37 else {
38 $callable = ["\\Civi\\Api4\\$entityName", $actionName];
39 if (!is_callable($callable)) {
40 throw new \Civi\API\Exception\NotImplementedException("API ($entityName, $actionName) does not exist (join the API team and implement it!)");
41 }
42 return call_user_func($callable);
43 }
44 }
45
46 }