(REF) CRM_Utils_Hook - Remove deprecated formulations of `invoke(int,...)`
authorTim Otten <totten@civicrm.org>
Tue, 21 Apr 2020 00:12:08 +0000 (17:12 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 21 Apr 2020 04:28:58 +0000 (21:28 -0700)
Overview
--------

The signature of `CRM_Utils_Hook::invoke()` originally took an argument `int
$count` (number of hook args), but circa 4.7 it changed to prefer `string[]
$names` (symbolic names for each hook arg).  The `int` notation doesn't
provide enough information to fire via Symfony EventDispatcher and was
mostly replaced/deprecated, but `int` notation is still supported for
backward compatibility.

This cleans a couple oddballs using the `int` notation.

Before
------

Some stub functions in `CRM_Utils_Hook` still use the `invoke(int,...)` formulation:

* `hook_themes` fell through a crack because it had a long PR (years?) that
   overlapped with the change in `invoke()`.
* `hook_install` (etc) looks like `int`, but it's not actually used.

After
-----

None of the stub functions in `CRM_Utils_Hook::invoke(string[], ...)` use
`int` formulation.

CRM/Utils/Hook.php

index d634c0c7a139b4ff5e6e3a78325cdb64f3704655..2b0fd9a3799bd44fffc3802525463a6fb472c636 100644 (file)
@@ -662,7 +662,7 @@ abstract class CRM_Utils_Hook {
    *   the return value is ignored
    */
   public static function themes(&$themes) {
-    return self::singleton()->invoke(1, $themes,
+    return self::singleton()->invoke(['themes'], $themes,
       self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
       'civicrm_themes'
     );
@@ -1745,11 +1745,8 @@ abstract class CRM_Utils_Hook {
    * installation of unrelated modules).
    */
   public static function install() {
-    return self::singleton()->invoke(0, self::$_nullObject,
-      self::$_nullObject, self::$_nullObject,
-      self::$_nullObject, self::$_nullObject, self::$_nullObject,
-      'civicrm_install'
-    );
+    // Actually invoke via CRM_Extension_Manager_Module::callHook
+    throw new \RuntimeException(sprintf("The method %s::%s is just a documentation stub and should not be invoked directly.", __CLASS__, __FUNCTION__));
   }
 
   /**
@@ -1758,11 +1755,8 @@ abstract class CRM_Utils_Hook {
    * uninstallation of unrelated modules).
    */
   public static function uninstall() {
-    return self::singleton()->invoke(0, self::$_nullObject,
-      self::$_nullObject, self::$_nullObject,
-      self::$_nullObject, self::$_nullObject, self::$_nullObject,
-      'civicrm_uninstall'
-    );
+    // Actually invoke via CRM_Extension_Manager_Module::callHook
+    throw new \RuntimeException(sprintf("The method %s::%s is just a documentation stub and should not be invoked directly.", __CLASS__, __FUNCTION__));
   }
 
   /**
@@ -1771,11 +1765,8 @@ abstract class CRM_Utils_Hook {
    * re-enablement of unrelated modules).
    */
   public static function enable() {
-    return self::singleton()->invoke(0, self::$_nullObject,
-      self::$_nullObject, self::$_nullObject,
-      self::$_nullObject, self::$_nullObject, self::$_nullObject,
-      'civicrm_enable'
-    );
+    // Actually invoke via CRM_Extension_Manager_Module::callHook
+    throw new \RuntimeException(sprintf("The method %s::%s is just a documentation stub and should not be invoked directly.", __CLASS__, __FUNCTION__));
   }
 
   /**
@@ -1784,11 +1775,8 @@ abstract class CRM_Utils_Hook {
    * disablement of unrelated modules).
    */
   public static function disable() {
-    return self::singleton()->invoke(0, self::$_nullObject,
-      self::$_nullObject, self::$_nullObject,
-      self::$_nullObject, self::$_nullObject, self::$_nullObject,
-      'civicrm_disable'
-    );
+    // Actually invoke via CRM_Extension_Manager_Module::callHook
+    throw new \RuntimeException(sprintf("The method %s::%s is just a documentation stub and should not be invoked directly.", __CLASS__, __FUNCTION__));
   }
 
   /**