self::getNextId(), 'version' => 3, 'params' => $params, 'fields' => NULL, 'entity' => self::normalizeEntityName($entity), 'action' => self::normalizeActionName($action), ]; case 4: // Load the API kernel service for registering API providers, as // otherwise subscribers to the civi.api4.createRequest event registered // through the EventSubscriberInterface will not be registered. \Civi::service('civi_api_kernel'); $e = new CreateApi4RequestEvent($entity); \Civi::dispatcher()->dispatch('civi.api4.createRequest', $e); $callable = [$e->className, $action]; if (!$e->className || !is_callable($callable)) { throw new \Civi\API\Exception\NotImplementedException("API ($entity, $action) does not exist (join the API team and implement it!)"); } // Check enabled components $daoName = \CRM_Core_DAO_AllCoreTables::getFullName($entity); if ($daoName && defined("{$daoName}::COMPONENT") && !\CRM_Core_Component::isEnabled($daoName::COMPONENT)) { throw new \Civi\API\Exception\NotImplementedException("$entity API is not available because " . $daoName::COMPONENT . " component is disabled"); } $apiRequest = call_user_func_array($callable, $e->args); foreach ($params as $name => $param) { $setter = 'set' . ucfirst($name); $apiRequest->$setter($param); } return $apiRequest; default: throw new \Civi\API\Exception\NotImplementedException("Unknown api version"); } } /** * Normalize entity to be CamelCase. * * APIv1-v3 munges entity/action names, and accepts any mixture of case and underscores. * * @param string $entity * @return string */ public static function normalizeEntityName($entity) { return \CRM_Core_DAO_AllCoreTables::convertEntityNameToCamel(\CRM_Utils_String::munge($entity), TRUE); } /** * Normalize api action name to be lowercase. * * APIv1-v3 munges entity/action names, and accepts any mixture of case and underscores. * * @param $action * @param $version * @return string */ public static function normalizeActionName($action) { return strtolower(\CRM_Utils_String::munge($action)); } public static function getNextId() { return self::$nextId++; } }