(dev/core#1740) Cumulative contributions not being calculated with the correct criteria
[civicrm-core.git] / CRM / Api4 / Services.php
index 95fd4a2202cc006863768cf3a1a25c25799d0e79..35c24449e04a5a6bd17ed1ed7f27cb796d4deefc 100644 (file)
@@ -81,12 +81,15 @@ class CRM_Api4_Services {
     );
     foreach ($locations as $location) {
       $path = \CRM_Utils_File::addTrailingSlash(dirname($location)) . str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
-      try {
-        $resource = new \Symfony\Component\Config\Resource\DirectoryResource($path, ';\.php$;');
+      if (!file_exists($path) || !is_dir($path)) {
+        $resource = new \Symfony\Component\Config\Resource\FileExistenceResource($path);
         $container->addResource($resource);
+      }
+      else {
+        $resource = new \Symfony\Component\Config\Resource\DirectoryResource($path, ';\.php$;');
         foreach (glob("$path*.php") as $file) {
           $matches = [];
-          preg_match('/(\w*).php/', $file, $matches);
+          preg_match('/(\w*)\.php$/', $file, $matches);
           $serviceName = $namespace . array_pop($matches);
           $serviceClass = new \ReflectionClass($serviceName);
           if ($serviceClass->isInstantiable()) {
@@ -94,9 +97,7 @@ class CRM_Api4_Services {
             $definition->addTag($tag);
           }
         }
-      }
-      catch (\InvalidArgumentException $e) {
-        //Directory is not found so lets not do anything i suppose.
+        $container->addResource($resource);
       }
     }
   }