PhpStormCompilePass - Generate hints for `Civi::cache()`
authorTim Otten <totten@civicrm.org>
Fri, 25 Aug 2023 23:16:28 +0000 (16:16 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 25 Aug 2023 23:35:58 +0000 (16:35 -0700)
The `cache()` method just returns objects from the container, so it can come from the same metadata.

tools/extensions/phpstorm/Civi/PhpStorm/PhpStormCompilePass.php

index debe9f8d5e593704f8e0cd2778c6892902ff4fa4..fe6ecf3b17064fc0e78228843c98c8052bb56edd 100644 (file)
@@ -19,8 +19,17 @@ class PhpStormCompilePass implements CompilerPassInterface {
       return;
     }
 
+    $services = $this->findServices($container);
+    $caches = [];
+    foreach ($services as $serviceId => $type) {
+      if (preg_match('/^cache\./', $serviceId)) {
+        $caches[substr($serviceId, 6)] = $type;
+      }
+    }
+
     $builder = new PhpStormMetadata('services', __CLASS__);
-    $builder->addOverrideMap('\Civi::service()', $this->findServices($container));
+    $builder->addOverrideMap('\Civi::service()', $services);
+    $builder->addOverrideMap('\Civi::cache()', $caches);
     $builder->write();
   }