<?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. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
namespace Civi\API\Provider;
+
use Civi\API\Events;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
public static function getSubscribedEvents() {
return array(
Events::RESOLVE => array(
- array('onApiResolve', Events::W_EARLY), // TODO decide if we really want to override others
+ // TODO decide if we really want to override others
+ array('onApiResolve', Events::W_EARLY),
),
Events::AUTHORIZE => array(
- array('onApiAuthorize', Events::W_EARLY), // TODO decide if we really want to override others
+ // TODO decide if we really want to override others
+ array('onApiAuthorize', Events::W_EARLY),
),
);
}
/**
* @param \Civi\API\Kernel $apiKernel
+ * The API kernel.
*/
public function __construct($apiKernel) {
$this->apiKernel = $apiKernel;
/**
* @param \Civi\API\Event\ResolveEvent $event
+ * API resolution 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);
$event->setApiProvider($this);
- $event->stopPropagation(); // TODO decide if we really want to override others
+ $event->stopPropagation();
+ // TODO decide if we really want to override others
}
}
/**
* @param \Civi\API\Event\AuthorizeEvent $event
+ * API authorization event.
*/
public function onApiAuthorize(\Civi\API\Event\AuthorizeEvent $event) {
$apiRequest = $event->getApiRequest();
if (isset($apiRequest['is_metadata'])) {
- // if (\CRM_Core_Permission::check('access AJAX API') || \CRM_Core_Permission::check('access CiviCRM')) {
+ // if (\CRM_Core_Permission::check('access AJAX API')
+ // || \CRM_Core_Permission::check('access CiviCRM')) {
$event->authorize();
$event->stopPropagation();
// }
/**
* {inheritdoc}
+ * @param array $apiRequest
+ * @return array
+ * @throws \API_Exception
*/
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']));
-// case 'getfields':
-// return $this->doGetFields($apiRequest);
+ 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:
}
// We shouldn't get here because onApiResolve() checks $this->actions
- throw new \API_Exception("Unsupported action (" . $apiRequest['entity'] . '.' . $apiRequest['action'] . ']');
+ throw new \API_Exception("Unsupported action (" . $apiRequest['entity'] . '.' . $apiRequest['action'] . ']');
}
/**
* {inheritdoc}
+ * @param int $version
+ * @return array
*/
- function getEntityNames($version) {
+ public function getEntityNames($version) {
return array('Entity');
}
/**
* {inheritdoc}
+ * @param int $version
+ * @param string $entity
+ * @return array
*/
- function getActionNames($version, $entity) {
+ public function getActionNames($version, $entity) {
+ $entity = _civicrm_api_get_camel_name($entity, $version);
return isset($this->actions[$entity]) ? $this->actions[$entity] : $this->actions['*'];
}
+
}