X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FAPI%2FProvider%2FMagicFunctionProvider.php;h=74a38dbcac5d3d90474674ecf538cbcdd792169e;hb=07007b7a01bf68bbe96a980862c0fcdd20eeba52;hp=ce14050bada34d5a7a1417b1c2d207ffde846cae;hpb=ffb9b8a34ae98d1461ae60dc0410a092534cd274;p=civicrm-core.git diff --git a/Civi/API/Provider/MagicFunctionProvider.php b/Civi/API/Provider/MagicFunctionProvider.php index ce14050bad..74a38dbcac 100644 --- a/Civi/API/Provider/MagicFunctionProvider.php +++ b/Civi/API/Provider/MagicFunctionProvider.php @@ -34,6 +34,9 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; * conventions. */ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterface { + /** + * @return array + */ public static function getSubscribedEvents() { return array( Events::RESOLVE => array( @@ -47,10 +50,16 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa */ 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); @@ -130,7 +139,7 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa $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) { @@ -215,6 +224,8 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa /** * @param string $entity * @param string $action + * @param $version + * * @return string */ protected function getFunctionName($entity, $action, $version) { @@ -246,25 +257,27 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa $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; + } } } } } -} \ No newline at end of file +}