[REF] Update fetchAll function signature to match parent function
[civicrm-core.git] / CRM / Api4 / Services.php
index a615f1a0e27c7f0863dcc006bbbd54a64a0185cd..95fd4a2202cc006863768cf3a1a25c25799d0e79 100644 (file)
@@ -1,5 +1,24 @@
 <?php
 
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ * $Id$
+ *
+ */
+
+
 use Symfony\Component\DependencyInjection\Reference;
 use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
 use Symfony\Component\Config\FileLocator;
@@ -62,16 +81,23 @@ class CRM_Api4_Services {
     );
     foreach ($locations as $location) {
       $path = \CRM_Utils_File::addTrailingSlash(dirname($location)) . str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
-      foreach (glob("$path*.php") as $file) {
-        $matches = [];
-        preg_match('/(\w*).php/', $file, $matches);
-        $serviceName = $namespace . array_pop($matches);
-        $serviceClass = new \ReflectionClass($serviceName);
-        if ($serviceClass->isInstantiable()) {
-          $definition = $container->register(str_replace('\\', '_', $serviceName), $serviceName);
-          $definition->addTag($tag);
+      try {
+        $resource = new \Symfony\Component\Config\Resource\DirectoryResource($path, ';\.php$;');
+        $container->addResource($resource);
+        foreach (glob("$path*.php") as $file) {
+          $matches = [];
+          preg_match('/(\w*).php/', $file, $matches);
+          $serviceName = $namespace . array_pop($matches);
+          $serviceClass = new \ReflectionClass($serviceName);
+          if ($serviceClass->isInstantiable()) {
+            $definition = $container->register(str_replace('\\', '_', $serviceName), $serviceName);
+            $definition->addTag($tag);
+          }
         }
       }
+      catch (\InvalidArgumentException $e) {
+        //Directory is not found so lets not do anything i suppose.
+      }
     }
   }