* conventions.
*/
class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterface {
+ /**
+ * @return array
+ */
public static function getSubscribedEvents() {
return array(
Events::RESOLVE => array(
*/
private $cache;
+ /**
+ *
+ */
function __construct() {
$this->cache = array();
}
+ /**
+ * @param \Civi\API\Event\ResolveEvent $event
+ */
public function onApiResolve(\Civi\API\Event\ResolveEvent $event) {
$apiRequest = $event->getApiRequest();
$resolved = $this->resolve($apiRequest);
$functions = get_defined_functions();
$actions = array();
- $prefix = 'civicrm_api' . $version . '_' . strtolower($entity) . '_';
+ $prefix = 'civicrm_api' . $version . '_' . _civicrm_api_get_entity_name_from_camel($entity) . '_';
$prefixGeneric = 'civicrm_api' . $version . '_generic_';
foreach ($functions['user'] as $fct) {
if (strpos($fct, $prefix) === 0) {
$loaded_files = array(); // array($relativeFilePath => TRUE)
$include_dirs = array_unique(explode(PATH_SEPARATOR, get_include_path()));
foreach ($include_dirs as $include_dir) {
- $action_dir = implode(DIRECTORY_SEPARATOR, array($include_dir, 'api', "v${version}", $camelName));
- if (!is_dir($action_dir)) {
- continue;
- }
-
- $iterator = new \DirectoryIterator($action_dir);
- foreach ($iterator as $fileinfo) {
- $file = $fileinfo->getFilename();
- if (array_key_exists($file, $loaded_files)) {
- continue; // action provided by an earlier item on include_path
+ foreach (array($camelName, 'Generic') as $name) {
+ $action_dir = implode(DIRECTORY_SEPARATOR, array($include_dir, 'api', "v${version}", $name));
+ if (!is_dir($action_dir)) {
+ continue;
}
- $parts = explode(".", $file);
- if (end($parts) == "php" && !preg_match('/Tests?\.php$/', $file)) {
- require_once $action_dir . DIRECTORY_SEPARATOR . $file;
- $loaded_files[$file] = TRUE;
+ $iterator = new \DirectoryIterator($action_dir);
+ foreach ($iterator as $fileinfo) {
+ $file = $fileinfo->getFilename();
+ if (array_key_exists($file, $loaded_files)) {
+ continue; // action provided by an earlier item on include_path
+ }
+
+ $parts = explode(".", $file);
+ if (end($parts) == "php" && !preg_match('/Tests?\.php$/', $file)) {
+ require_once $action_dir . DIRECTORY_SEPARATOR . $file;
+ $loaded_files[$file] = TRUE;
+ }
}
}
}