CRM-14370 - API Kernel - Implement getEntityNames, getActionNames
[civicrm-core.git] / api / v3 / Generic / Getactions.php
index e7743ae6bce6796a8698ce5388066c96a290576a..9cfbbd67a95d7235558ccb9459f49d4e3ca550dd 100644 (file)
@@ -1,26 +1,34 @@
 <?php
-// $Id$
 
-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);
+/*
+ +--------------------------------------------------------------------+
+| CiviCRM version 4.5                                                |
++--------------------------------------------------------------------+
+| Copyright CiviCRM LLC (c) 2004-2014                                |
++--------------------------------------------------------------------+
+| This file is a part of CiviCRM.                                    |
+|                                                                    |
+| CiviCRM is free software; you can copy, modify, and distribute it  |
+| under the terms of the GNU Affero General Public License           |
+| Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+|                                                                    |
+| CiviCRM is distributed in the hope that it will be useful, but     |
+| WITHOUT ANY WARRANTY; without even the implied warranty of         |
+| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+| See the GNU Affero General Public License for more details.        |
+|                                                                    |
+| You should have received a copy of the GNU Affero General Public   |
+| License and the CiviCRM Licensing Exception along                  |
+| with this program; if not, contact CiviCRM LLC                     |
+| at info[AT]civicrm[DOT]org. If you have questions about the        |
+| GNU Affero General Public License or the licensing of CiviCRM,     |
+| see the CiviCRM license FAQ at http://civicrm.org/licensing        |
++--------------------------------------------------------------------+
+*/
 
-  $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['version'], $apiRequest['entity']);
   return civicrm_api3_create_success($actions);
 }