CRM-14370 - Move helper functions into classes
[civicrm-core.git] / api / v3 / Generic / Getactions.php
index 71b722c43cae2ff003ee5c9464f9cd84908dbe36..a10990dc8daacfa0c4864967f25c1350387e86d7 100644 (file)
 +--------------------------------------------------------------------+
 */
 
-function civicrm_api3_generic_getActions($params) {
-  civicrm_api3_verify_mandatory($params, NULL, array('entity'));
-  $r = civicrm_api('Entity', 'Get', array('version' => 3));
-  $entity = CRM_Utils_String::munge($params['entity']);
-  if (!in_array($entity, $r['values'])) {
-    return civicrm_api3_create_error("Entity " . $entity . " invalid. Use api.entity.get to have the list", array('entity' => $r['values']));
-  }
-  _civicrm_api_loadEntity($entity);
-
-  $functions     = get_defined_functions();
-  $actions       = array();
-  $prefix        = 'civicrm_api3_' . strtolower($entity) . '_';
-  $prefixGeneric = 'civicrm_api3_generic_';
-  foreach ($functions['user'] as $fct) {
-    if (strpos($fct, $prefix) === 0) {
-      $actions[] = substr($fct, strlen($prefix));
-    }
-    elseif (strpos($fct, $prefixGeneric) === 0) {
-      $actions[] = substr($fct, strlen($prefixGeneric));
-    }
-  }
+function civicrm_api3_generic_getActions($apiRequest) {
+  civicrm_api3_verify_mandatory($apiRequest, NULL, array('entity'));
+  $mfp = \Civi\Core\Container::singleton()->get('magic_function_provider');
+  $actions = $mfp->getActionNames($apiRequest['entity'], $apiRequest['version']);
   return civicrm_api3_create_success($actions);
 }