Merge pull request #4772 from jitendrapurohit/CRM-15750
[civicrm-core.git] / Civi / API / Provider / ReflectionProvider.php
index addaa3145dddb793301ee3846b3fed2d289be2ab..4e646faad16029d356f8f397460c4b5c109a4350 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -33,6 +33,9 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  * This class defines operations for inspecting the API's metadata.
  */
 class ReflectionProvider implements EventSubscriberInterface, ProviderInterface {
+  /**
+   * @return array
+   */
   public static function getSubscribedEvents() {
     return array(
       Events::RESOLVE => array(
@@ -60,14 +63,19 @@ class ReflectionProvider implements EventSubscriberInterface, ProviderInterface
   public function __construct($apiKernel) {
     $this->apiKernel = $apiKernel;
     $this->actions = array(
+      // FIXME: We really need to deal with the api's lack of uniformity wrt case (Entity or entity)
       'Entity' => array('get', 'getactions'),
+      'entity' => array('get', 'getactions'),
       '*' => array('getactions'), // 'getfields'
     );
   }
 
+  /**
+   * @param \Civi\API\Event\ResolveEvent $event
+   */
   public function onApiResolve(\Civi\API\Event\ResolveEvent $event) {
     $apiRequest = $event->getApiRequest();
-    $actions = isset($this->actions[$apiRequest['entity']]) ? $this->actions[$apiRequest['entity']] : $this->actions['*'];
+    $actions = $this->getActionNames($apiRequest['version'], $apiRequest['entity']);
     if (in_array($apiRequest['action'], $actions)) {
       $apiRequest['is_metadata'] = TRUE;
       $event->setApiRequest($apiRequest);
@@ -76,6 +84,9 @@ class ReflectionProvider implements EventSubscriberInterface, ProviderInterface
     }
   }
 
+  /**
+   * @param \Civi\API\Event\AuthorizeEvent $event
+   */
   public function onApiAuthorize(\Civi\API\Event\AuthorizeEvent $event) {
     $apiRequest = $event->getApiRequest();
     if (isset($apiRequest['is_metadata'])) {
@@ -90,12 +101,12 @@ class ReflectionProvider implements EventSubscriberInterface, ProviderInterface
    * {inheritdoc}
    */
   public function invoke($apiRequest) {
-    if ($apiRequest['entity'] == 'Entity' && $apiRequest['action'] == 'get') {
-      return civicrm_api3_create_success($this->apiKernel->getEntityNames($apiRequest['version']));
+    if (strtolower($apiRequest['entity']) == 'entity' && $apiRequest['action'] == 'get') {
+      return civicrm_api3_create_success($this->apiKernel->getEntityNames($apiRequest['version']), $apiRequest['params'], 'entity', 'get');
     }
     switch ($apiRequest['action']) {
       case 'getactions':
-        return civicrm_api3_create_success($this->apiKernel->getActionNames($apiRequest['version'], $apiRequest['entity']));
+        return civicrm_api3_create_success($this->apiKernel->getActionNames($apiRequest['version'], $apiRequest['entity']), $apiRequest['params'], $apiRequest['entity'], $apiRequest['action']);
 //      case 'getfields':
 //        return $this->doGetFields($apiRequest);
       default:
@@ -116,6 +127,7 @@ class ReflectionProvider implements EventSubscriberInterface, ProviderInterface
    * {inheritdoc}
    */
   function getActionNames($version, $entity) {
+    $entity = _civicrm_api_get_camel_name($entity, $version);
     return isset($this->actions[$entity]) ? $this->actions[$entity] : $this->actions['*'];
   }
-}
\ No newline at end of file
+}