From 56d63f3f055bba5be6b6b02fb3ed72318b8f0b95 Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Sat, 28 Mar 2020 21:16:04 +0100 Subject: [PATCH] dev-1674: fix rebuilding of container on every request --- CRM/Api4/Services.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CRM/Api4/Services.php b/CRM/Api4/Services.php index ec8190348c..736866af6a 100644 --- a/CRM/Api4/Services.php +++ b/CRM/Api4/Services.php @@ -83,7 +83,7 @@ class CRM_Api4_Services { $path = \CRM_Utils_File::addTrailingSlash(dirname($location)) . str_replace('\\', DIRECTORY_SEPARATOR, $namespace); try { $resource = new \Symfony\Component\Config\Resource\DirectoryResource($path, ';\.php$;'); - $container->addResource($resource); + $addResource = false; foreach (glob("$path*.php") as $file) { $matches = []; preg_match('/(\w*)\.php$/', $file, $matches); @@ -92,8 +92,12 @@ class CRM_Api4_Services { if ($serviceClass->isInstantiable()) { $definition = $container->register(str_replace('\\', '_', $serviceName), $serviceName); $definition->addTag($tag); + $addResource = true; } } + if ($addResource) { + $container->addResource($resource); + } } catch (\InvalidArgumentException $e) { //Directory is not found so lets not do anything i suppose. -- 2.25.1