use Civi\API\Exception\UnauthorizedException;
use Civi\API\Request;
use Civi\Api4\Generic\AbstractAction;
+use Civi\Api4\Service\Schema\SchemaMap;
use CRM_Core_DAO_AllCoreTables as AllCoreTables;
class CoreUtil {
* The BAO name for use in static calls. Return doc block is hacked to allow
* auto-completion of static methods
*/
- public static function getBAOFromApiName($entityName) {
+ public static function getBAOFromApiName($entityName): ?string {
// TODO: It would be nice to just call self::getInfoItem($entityName, 'dao')
// but that currently causes test failures, probably due to early-bootstrap issues.
if ($entityName === 'CustomValue' || strpos($entityName, 'Custom_') === 0) {
* @param $baoClassName
* @return string|null
*/
- public static function getApiNameFromBAO($baoClassName) {
+ public static function getApiNameFromBAO($baoClassName): ?string {
$briefName = AllCoreTables::getBriefName($baoClassName);
return $briefName && self::getApiClass($briefName) ? $briefName : NULL;
}
/**
* @param string $entityName
- * @return string|\Civi\Api4\Generic\AbstractEntity
+ * @return string|\Civi\Api4\Generic\AbstractEntity|null
*/
- public static function getApiClass($entityName) {
+ public static function getApiClass(string $entityName): ?string {
$className = 'Civi\Api4\\' . $entityName;
if (class_exists($className)) {
return $className;
*
* @param string $entityName
*
- * @return string
+ * @return string|null
*/
- public static function getTableName(string $entityName) {
+ public static function getTableName(string $entityName): ?string {
return self::getInfoItem($entityName, 'table_name');
}
/**
* Given a sql table name, return the name of the api entity.
*
- * @param $tableName
+ * @param string $tableName
* @return string|NULL
*/
- public static function getApiNameFromTableName($tableName) {
+ public static function getApiNameFromTableName($tableName): ?string {
$provider = \Civi::service('action_object_provider');
foreach ($provider->getEntities() as $entityName => $info) {
if (($info['table_name'] ?? NULL) === $tableName) {
/**
* @return string[]
*/
- public static function getOperators() {
+ public static function getOperators(): array {
$operators = \CRM_Core_DAO::acceptedSQLOperators();
$operators[] = 'CONTAINS';
$operators[] = 'NOT CONTAINS';
* @param string $entityName
* @return array{extends: array, column: string, grouping: mixed}|null
*/
- public static function getCustomGroupExtends(string $entityName) {
+ public static function getCustomGroupExtends(string $entityName): ?array {
$contactTypes = \CRM_Contact_BAO_ContactType::basicTypes();
// Custom_group.extends pretty much maps 1-1 with entity names, except for Contact.
if (in_array($entityName, $contactTypes, TRUE)) {
* @return bool
* @throws \CRM_Core_Exception
*/
- public static function isCustomEntity($customGroupName) {
+ public static function isCustomEntity($customGroupName): bool {
return $customGroupName && \CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupName, 'is_multiple', 'name');
}
* @param array $record
* @param int|null $userID
* Contact ID of the user we are testing, 0 for the anonymous user.
- * @return bool
+ * @return bool|null
* @throws \CRM_Core_Exception
*/
- public static function checkAccessRecord(AbstractAction $apiRequest, array $record, int $userID = NULL) {
+ public static function checkAccessRecord(AbstractAction $apiRequest, array $record, int $userID = NULL): ?bool {
$userID = $userID ?? \CRM_Core_Session::getLoggedInContactID() ?? 0;
// Super-admins always have access to everything
/**
* @return \Civi\Api4\Service\Schema\SchemaMap
*/
- public static function getSchemaMap() {
+ public static function getSchemaMap(): SchemaMap {
$cache = \Civi::cache('metadata');
$schemaMap = $cache->get('api4.schema.map');
if (!$schemaMap) {
* @return array{name: string, type: string, count: int, table: string|null, key: string|null}[]
* @throws NotImplementedException
*/
- public static function getRefCount(string $entityName, $entityId) {
+ public static function getRefCount(string $entityName, $entityId): array {
$daoName = self::getInfoItem($entityName, 'dao');
if (!$daoName) {
throw new NotImplementedException("Cannot getRefCount for $entityName - dao not found.");