phpstorm - Move listener to the end of the hook
authorTim Otten <totten@civicrm.org>
Fri, 25 Aug 2023 12:03:02 +0000 (05:03 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 25 Aug 2023 12:03:02 +0000 (05:03 -0700)
tools/extensions/phpstorm/info.xml
tools/extensions/phpstorm/mixin/phpstorm@1.0.0.mixin.php [new file with mode: 0644]
tools/extensions/phpstorm/phpstorm.php

index 38449206f2deb6d846f8d48f5b09476e9ec2648f..8f4f17f9684e6f639048e3998e51ca0030884351 100644 (file)
     <format>23.02.1</format>
     <angularModule>crmPhpstorm</angularModule>
   </civix>
-  <!-- <mixins>
+  <mixins>
+    <mixin>phpstorm@1.0.0</mixin>
+    <!--
     <mixin>mgd-php@1.0.0</mixin>
     <mixin>setting-php@1.0.0</mixin>
     <mixin>smarty-v2@1.0.1</mixin>
-  </mixins> -->
+    -->
+  </mixins>
 </extension>
diff --git a/tools/extensions/phpstorm/mixin/phpstorm@1.0.0.mixin.php b/tools/extensions/phpstorm/mixin/phpstorm@1.0.0.mixin.php
new file mode 100644 (file)
index 0000000..c70b85b
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * @mixinName phpstorm
+ * @mixinVersion 1.0.0
+ *
+ * @param CRM_Extension_MixInfo $mixInfo
+ *   On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
+ * @param \CRM_Extension_BootCache $bootCache
+ *   On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
+ */
+return function ($mixInfo, $bootCache) {
+
+  // We want to register a late-stage listener for hook_civicrm_container, but... it's a special hook.
+  // Therefore, we apply the Shenanigan technique.
+  Civi::dispatcher()->addListener('&hook_civicrm_container', function($container) use ($mixInfo) {
+    if ($mixInfo->isActive()) {
+      \Civi\PhpStorm\Generator::generate($container);
+    }
+  }, -2000);
+
+};
index 450c7b3ea25ff502befbbc8084af64c3b3ab36ce..b7d7483201a10ca2d8a953d2a3c30003a9b385b1 100644 (file)
 // function phpstorm_civicrm_config(&$config): void {
 //  _phpstorm_civix_civicrm_config($config);
 // }
-
-/**
- * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
- * @return void
- * @see \CRM_Utils_Hook::container()
- */
-function phpstorm_civicrm_container($container): void {
-  // Delegate pattern. There aren't many other ways to listen to this ehook.
-  \Civi\PhpStorm\Generator::generate($container);
-}