* conventions.
*/
class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterface {
+
/**
* @return array
*/
public static function getSubscribedEvents() {
- return array(
- Events::RESOLVE => array(
- array('onApiResolve', Events::W_MIDDLE),
- ),
- );
+ return [
+ Events::RESOLVE => [
+ ['onApiResolve', Events::W_MIDDLE],
+ ],
+ ];
}
/**
/**
*/
public function __construct() {
- $this->cache = array();
+ $this->cache = [];
}
/**
// Unlike normal API implementations, generic implementations require explicit
// knowledge of the entity and action (as well as $params). Bundle up these bits
// into a convenient data structure.
+ if ($apiRequest['action'] === 'getsingle') {
+ // strip any api nested parts here as otherwise chaining may happen twice
+ // see https://lab.civicrm.org/dev/core/issues/643
+ // testCreateBAODefaults fails without this.
+ foreach ($apiRequest['params'] as $key => $param) {
+ if ($key !== 'api.has_parent' && substr($key, 0, 4) === 'api.' || substr($key, 0, 4) === 'api_') {
+ unset($apiRequest['params'][$key]);
+ }
+ }
+ }
$result = $function($apiRequest);
+
}
elseif ($apiRequest['function'] && !$apiRequest['is_generic']) {
$result = $function($apiRequest['params']);
* @return array
*/
public function getEntityNames($version) {
- $entities = array();
+ $entities = [];
$include_dirs = array_unique(explode(PATH_SEPARATOR, get_include_path()));
#$include_dirs = array(dirname(__FILE__). '/../../');
foreach ($include_dirs as $include_dir) {
$api_dir = implode(DIRECTORY_SEPARATOR,
- array($include_dir, 'api', 'v' . $version));
+ [$include_dir, 'api', 'v' . $version]);
if (!is_dir($api_dir)) {
continue;
}
}
}
}
- $entities = array_diff($entities, array('Generic'));
+ $entities = array_diff($entities, ['Generic']);
$entities = array_unique($entities);
sort($entities);
$entity = _civicrm_api_get_camel_name($entity);
$entities = $this->getEntityNames($version);
if (!in_array($entity, $entities)) {
- return array();
+ return [];
}
$this->loadEntity($entity, $version);
$functions = get_defined_functions();
- $actions = array();
+ $actions = [];
$prefix = 'civicrm_api' . $version . '_' . _civicrm_api_get_entity_name_from_camel($entity) . '_';
$prefixGeneric = 'civicrm_api' . $version . '_generic_';
foreach ($functions['user'] as $fct) {
// someone already loaded the appropriate file
// FIXME: This has the affect of masking bugs in load order; this is
// included to provide bug-compatibility.
- $this->cache[$cachekey] = array('function' => $stdFunction, 'is_generic' => FALSE);
+ $this->cache[$cachekey] = ['function' => $stdFunction, 'is_generic' => FALSE];
return $this->cache[$cachekey];
}
- $stdFiles = array(
+ $stdFiles = [
// By convention, the $camelName.php is more likely to contain the
// function, so test it first
'api/v' . $apiRequest['version'] . '/' . $camelName . '.php',
'api/v' . $apiRequest['version'] . '/' . $camelName . '/' . $actionCamelName . '.php',
- );
+ ];
foreach ($stdFiles as $stdFile) {
if (\CRM_Utils_File::isIncludable($stdFile)) {
require_once $stdFile;
if (function_exists($stdFunction)) {
- $this->cache[$cachekey] = array('function' => $stdFunction, 'is_generic' => FALSE);
+ $this->cache[$cachekey] = ['function' => $stdFunction, 'is_generic' => FALSE];
return $this->cache[$cachekey];
}
}
require_once 'api/v3/Generic.php';
# $genericFunction = 'civicrm_api3_generic_' . $apiRequest['action'];
$genericFunction = $this->getFunctionName('generic', $apiRequest['action'], $apiRequest['version']);
- $genericFiles = array(
+ $genericFiles = [
// By convention, the Generic.php is more likely to contain the
// function, so test it first
'api/v' . $apiRequest['version'] . '/Generic.php',
'api/v' . $apiRequest['version'] . '/Generic/' . $actionCamelName . '.php',
- );
+ ];
foreach ($genericFiles as $genericFile) {
if (\CRM_Utils_File::isIncludable($genericFile)) {
require_once $genericFile;
if (function_exists($genericFunction)) {
- $this->cache[$cachekey] = array('function' => $genericFunction, 'is_generic' => TRUE);
+ $this->cache[$cachekey] = ['function' => $genericFunction, 'is_generic' => TRUE];
return $this->cache[$cachekey];
}
}
}
- $this->cache[$cachekey] = array('function' => FALSE, 'is_generic' => FALSE);
+ $this->cache[$cachekey] = ['function' => FALSE, 'is_generic' => FALSE];
return $this->cache[$cachekey];
}
}
// Check for standalone action files; to match _civicrm_api_resolve(), only load the first one
- $loaded_files = array(); // array($relativeFilePath => TRUE)
+ // array($relativeFilePath => TRUE)
+ $loaded_files = [];
$include_dirs = array_unique(explode(PATH_SEPARATOR, get_include_path()));
foreach ($include_dirs as $include_dir) {
- foreach (array($camelName, 'Generic') as $name) {
+ foreach ([$camelName, 'Generic'] as $name) {
$action_dir = implode(DIRECTORY_SEPARATOR,
- array($include_dir, 'api', "v${version}", $name));
+ [$include_dir, 'api', "v${version}", $name]);
if (!is_dir($action_dir)) {
continue;
}
foreach ($iterator as $fileinfo) {
$file = $fileinfo->getFilename();
if (array_key_exists($file, $loaded_files)) {
- continue; // action provided by an earlier item on include_path
+ // action provided by an earlier item on include_path
+ continue;
}
$parts = explode(".", $file);